本文整理汇总了PHP中RedBeanModel::getForeignKeyName方法的典型用法代码示例。如果您正苦于以下问题:PHP RedBeanModel::getForeignKeyName方法的具体用法?PHP RedBeanModel::getForeignKeyName怎么用?PHP RedBeanModel::getForeignKeyName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanModel
的用法示例。
在下文中一共展示了RedBeanModel::getForeignKeyName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isCurrencyInUseById
/**
* Given an id of a currency model, determine if any currency values are using this currency.
* @return true if at least one currency value model is using this currency.
* @param integer $currencyId
*/
public static function isCurrencyInUseById($currencyId)
{
assert('is_int($currencyId)');
$columnName = RedBeanModel::getForeignKeyName('CurrencyValue', 'currency');
$quote = DatabaseCompatibilityUtil::getQuote();
$where = "{$quote}{$columnName}{$quote} = '{$currencyId}'";
$count = CurrencyValue::getCount(null, $where);
if ($count > 0) {
return true;
}
return false;
}
示例2: updateValueByDataIdAndOldValueAndNewValue
public static function updateValueByDataIdAndOldValueAndNewValue($customFieldDataId, $oldValue, $newValue)
{
$quote = DatabaseCompatibilityUtil::getQuote();
$customFieldTableName = RedBeanModel::getTableName('CustomField');
$baseCustomFieldTableName = RedBeanModel::getTableName('BaseCustomField');
$baseCustomFieldJoinColumnName = $baseCustomFieldTableName . '_id';
$valueAttributeColumnName = 'value';
$dataAttributeColumnName = RedBeanModel::getForeignKeyName('BaseCustomField', 'data');
$sql = "update {$quote}{$customFieldTableName}{$quote}, {$quote}{$baseCustomFieldTableName}{$quote} ";
$sql .= "set {$quote}{$valueAttributeColumnName}{$quote} = '{$newValue}' ";
$sql .= "where {$quote}{$customFieldTableName}{$quote}.{$baseCustomFieldJoinColumnName} = ";
// Not Coding Standard
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id ";
$sql .= "AND {$quote}{$dataAttributeColumnName}{$quote} = {$customFieldDataId} ";
$sql .= "AND {$quote}{$valueAttributeColumnName}{$quote} = '{$oldValue}'";
R::exec($sql);
}
示例3: testUpdateValueOnCustomFieldRows
/**
* @depends testSetAttributesWithPostForCustomField
*/
public function testUpdateValueOnCustomFieldRows()
{
$values = array('A', 'B', 'C');
$customFieldData = CustomFieldData::getByName('updateItems');
$customFieldData->serializedData = serialize($values);
$this->assertTrue($customFieldData->save());
$id = $customFieldData->id;
$customField = new CustomField();
$customField->value = 'A';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$customField = new CustomField();
$customField->value = 'B';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$customField = new CustomField();
$customField->value = 'C';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$customField = new CustomField();
$customField->value = 'C';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$quote = DatabaseCompatibilityUtil::getQuote();
$customFieldTableName = CustomField::getTableName();
$baseCustomFieldTableName = BaseCustomField::getTableName();
$valueAttributeColumnName = 'value';
$dataAttributeColumnName = RedBeanModel::getForeignKeyName('CustomField', 'data');
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id}";
$ids = ZurmoRedBean::getCol($sql);
$beans = ZurmoRedBean::batch($customFieldTableName, $ids);
$customFields = RedBeanModel::makeModels($beans, 'CustomField');
$this->assertEquals(4, count($customFields));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'B'";
$this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'C'";
$this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'E'";
$this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
CustomField::updateValueByDataIdAndOldValueAndNewValue($id, 'C', 'E');
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'B'";
$this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'C'";
$this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'E'";
$this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
}
示例4: updateFolderForEmailMessageWithSQL
/**
* Update an email message's folder and save it using SQL
* @param EmailMessage $emailMessage
* @param EmailFolder $folder
* @throws NotSupportedException
*/
protected static function updateFolderForEmailMessageWithSQL(EmailMessage &$emailMessage, EmailFolder $folder)
{
// TODO: @Shoaibi/@Jason: Critical0: This fails CampaignItemsUtilTest.php:243
$folderForeignKeyName = RedBeanModel::getForeignKeyName('EmailMessage', 'folder');
$tableName = EmailMessage::getTableName();
$sql = "UPDATE " . DatabaseCompatibilityUtil::quoteString($tableName);
$sql .= " SET " . DatabaseCompatibilityUtil::quoteString($folderForeignKeyName);
$sql .= " = " . $folder->id;
$sql .= " WHERE " . DatabaseCompatibilityUtil::quoteString('id') . " = " . $emailMessage->id;
$effectedRows = ZurmoRedBean::exec($sql);
if ($effectedRows == 1) {
$emailMessageId = $emailMessage->id;
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
return true;
}
return false;
}
示例5: resolve
/**
* Generates a column definition or processes junctions table depending on relation and link type.
* @param string $modelClassName
* @param string $relationName
* @param array $relationMetadata
* @param $messageLogger
* @return array|null
*/
public static function resolve($modelClassName, $relationName, array $relationMetadata, &$messageLogger)
{
$column = null;
if (!empty($modelClassName) && @class_exists($modelClassName) && !empty($relationName) && count($relationMetadata) >= 2 && @class_exists($relationMetadata[1])) {
$relationType = $relationMetadata[0];
$relatedModelClass = $relationMetadata[1];
$linkType = RedBeanModel::LINK_TYPE_ASSUMPTIVE;
if (isset($relationMetadata[3])) {
$linkType = $relationMetadata[3];
}
if (!in_array($relationType, array(RedBeanModel::HAS_ONE_BELONGS_TO, RedBeanModel::HAS_MANY_BELONGS_TO, RedBeanModel::HAS_ONE, RedBeanModel::HAS_MANY, RedBeanModel::MANY_MANY))) {
return false;
}
if ($relationType == RedBeanModel::MANY_MANY) {
RedBeanModelToJoinTableAdapter::resolve($modelClassName, $relationMetadata, $messageLogger);
return null;
} elseif (in_array($relationType, array(RedBeanModel::HAS_ONE, RedBeanModel::HAS_MANY_BELONGS_TO))) {
$linkName = null;
if ($linkType == RedBeanModel::LINK_TYPE_ASSUMPTIVE && strtolower($relatedModelClass) != strtolower($relationName)) {
$linkName = strtolower($relationName) . '_';
}
$name = $linkName . RedBeanModel::getForeignKeyName($modelClassName, $relationName);
$column = RedBeanModelMemberToColumnUtil::resolveForeignKeyColumnMetadata($name);
} elseif ($relationType == RedBeanModel::HAS_MANY && $linkType == RedBeanModel::LINK_TYPE_POLYMORPHIC) {
static::setColumnsForPolymorphicLink($relatedModelClass, $relationMetadata[4]);
}
// ignore HAS_MANY(non-polymorphic) and HAS_ONE_BELONGS_TO as we are dealing with HAS_ONE and HAS_MANY_BELONGS e.g.
// we are ignore the sides which shouldn't have columns.
} else {
return false;
}
return $column;
}
示例6: resolveReadPermissionsOptimizationToSqlQuery
/**
* @param User $user
* @param RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter
* @param $where
* @param $selectDistinct
* @throws NotSupportedException
*/
public static function resolveReadPermissionsOptimizationToSqlQuery(User $user, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter, &$where, &$selectDistinct)
{
assert('$where == null || is_string($where)');
assert('is_bool($selectDistinct)');
$modelClassName = get_called_class();
$moduleClassName = $modelClassName::getModuleClassName();
//Currently only adds munge if the module is securable and this model supports it.
if (static::hasReadPermissionsOptimization() && $moduleClassName != null && is_subclass_of($moduleClassName, 'SecurableModule')) {
$permission = PermissionsUtil::getActualPermissionDataForReadByModuleNameForCurrentUser($moduleClassName);
if ($permission == Permission::NONE || $permission == Permission::DENY) {
$quote = DatabaseCompatibilityUtil::getQuote();
$modelAttributeToDataProviderAdapter = new OwnedSecurableItemIdToDataProviderAdapter($modelClassName, null);
$builder = new ModelJoinBuilder($modelAttributeToDataProviderAdapter, $joinTablesAdapter);
$ownedTableAliasName = $builder->resolveJoins();
$ownerColumnName = RedBeanModel::getForeignKeyName('OwnedSecurableItem', 'owner');
$mungeIds = ReadPermissionsOptimizationUtil::getMungeIdsByUser($user);
if ($where != null) {
$where = '(' . $where . ') and ';
}
if (count($mungeIds) > 0 && $permission == Permission::NONE) {
$extraOnQueryPart = " and {$quote}munge_id{$quote} in ('" . join("', '", $mungeIds) . "')";
$mungeTableName = ReadPermissionsOptimizationUtil::getMungeTableName($modelClassName);
$mungeTableAliasName = $joinTablesAdapter->addLeftTableAndGetAliasName($mungeTableName, 'securableitem_id', $ownedTableAliasName, 'securableitem_id', $extraOnQueryPart);
$where .= "({$quote}{$ownedTableAliasName}{$quote}.{$quote}{$ownerColumnName}{$quote} = {$user->id} OR ";
// Not Coding Standard
$where .= "{$quote}{$mungeTableName}{$quote}.{$quote}munge_id{$quote} IS NOT NULL)";
// Not Coding Standard
$selectDistinct = true;
//must use distinct since adding munge table query.
} elseif ($permission == Permission::DENY) {
$where .= "{$quote}{$ownedTableAliasName}{$quote}.{$quote}{$ownerColumnName}{$quote} = {$user->id}";
// Not Coding Standard
} else {
throw new NotSupportedException();
}
}
}
}
示例7: testRedBeanModelGetForeignKeyNameBarfsForBadAttribute
/**
* @expectedException NotSupportedException
*/
public function testRedBeanModelGetForeignKeyNameBarfsForBadAttribute()
{
RedBeanModel::getForeignKeyName('Account', 'massagedByUser');
}
示例8: getEmailMessageForeignKeyName
protected function getEmailMessageForeignKeyName()
{
$itemClassName = $this->getItemClassName();
return RedBeanModel::getForeignKeyName($itemClassName, 'emailMessage');
}
示例9: markItemAsProcessedWithSQL
protected function markItemAsProcessedWithSQL($emailMessageId = null)
{
$className = $this->itemClass;
$itemTableName = $className::getTableName();
$sql = "UPDATE " . DatabaseCompatibilityUtil::quoteString($itemTableName);
$sql .= " SET " . DatabaseCompatibilityUtil::quoteString('processed') . ' = 1';
if ($emailMessageId) {
$emailMessageForeignKey = RedBeanModel::getForeignKeyName($this->itemClass, 'emailMessage');
$sql .= ", " . DatabaseCompatibilityUtil::quoteString($emailMessageForeignKey);
$sql .= " = {$emailMessageId}";
}
$sql .= " WHERE " . DatabaseCompatibilityUtil::quoteString('id') . " = {$this->itemId};";
$effectedRows = ZurmoRedBean::exec($sql);
return $effectedRows == 1;
}