本文整理汇总了PHP中CustomField::updateValueByDataIdAndOldValueAndNewValue方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomField::updateValueByDataIdAndOldValueAndNewValue方法的具体用法?PHP CustomField::updateValueByDataIdAndOldValueAndNewValue怎么用?PHP CustomField::updateValueByDataIdAndOldValueAndNewValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CustomField
的用法示例。
在下文中一共展示了CustomField::updateValueByDataIdAndOldValueAndNewValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setAttributeMetadataFromForm
public function setAttributeMetadataFromForm(AttributeForm $attributeForm)
{
assert('$attributeForm instanceof DropDownAttributeForm');
$modelClassName = get_class($this->model);
$attributeName = $attributeForm->attributeName;
$attributeLabels = $attributeForm->attributeLabels;
$defaultValueOrder = $attributeForm->defaultValueOrder;
$elementType = $attributeForm->getAttributeTypeName();
$partialTypeRule = $attributeForm->getModelAttributePartialRule();
$isRequired = (bool) $attributeForm->isRequired;
$isAudited = (bool) $attributeForm->isAudited;
$customFieldDataName = $attributeForm->customFieldDataName;
if ($customFieldDataName == null) {
$customFieldDataName = ucfirst(strtolower($attributeForm->attributeName));
//should we do something else instead?
}
$customFieldDataData = $attributeForm->customFieldDataData;
$customFieldDataLabels = $attributeForm->customFieldDataLabels;
$defaultValue = DropDownDefaultValueOrderUtil::getDefaultValueFromDefaultValueOrder($defaultValueOrder, $customFieldDataData);
ModelMetadataUtil::addOrUpdateCustomFieldRelation($modelClassName, $attributeName, $attributeLabels, $defaultValue, $isRequired, $isAudited, $elementType, $customFieldDataName, $customFieldDataData, $customFieldDataLabels);
if ($attributeForm->getCustomFieldDataId() != null) {
$oldAndNewValuePairs = array();
foreach ($attributeForm->customFieldDataData as $order => $newValue) {
if (isset($attributeForm->customFieldDataDataExistingValues[$order]) && $attributeForm->customFieldDataDataExistingValues[$order] != $newValue) {
CustomField::updateValueByDataIdAndOldValueAndNewValue($attributeForm->getCustomFieldDataId(), $attributeForm->customFieldDataDataExistingValues[$order], $newValue);
$oldValue = $attributeForm->customFieldDataDataExistingValues[$order];
$oldAndNewValuePairs[$oldValue] = $newValue;
}
}
if (count($oldAndNewValuePairs) > 0) {
DropDownDependencyDerivedAttributeDesignerUtil::updateValueInMappingByOldAndNewValue($modelClassName, $attributeName, $oldAndNewValuePairs, $attributeForm->customFieldDataDataExistingValues[$order], $newValue);
}
DropDownDependencyDerivedAttributeDesignerUtil::resolveValuesInMappingWhenValueWasRemoved($modelClassName, $attributeName, $attributeForm->customFieldDataData);
}
$this->resolveDatabaseSchemaForModel($modelClassName);
}
示例2: 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)));
}