public static function updateValueByDataIdAndOldValueAndNewValue($customFieldDataId, $oldValue, $newValue) { $quote = DatabaseCompatibilityUtil::getQuote(); $customFieldTableName = CustomField::getTableName(); $baseCustomFieldTableName = BaseCustomField::getTableName(); $baseCustomFieldJoinColumnName = $baseCustomFieldTableName . '_id'; $valueAttributeColumnName = 'value'; $dataAttributeColumnName = static::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}'"; ZurmoRedBean::exec($sql); }
/** * @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))); }
public static function getDefaultMetadata() { $metadata = parent::getDefaultMetadata(); $metadata[__CLASS__] = array('members' => array('value'), 'relations' => array(), 'rules' => array(array('value', 'type', 'type' => 'string')), 'defaultSortAttribute' => 'value'); return $metadata; }
public static function getDefaultMetadata() { $metadata = parent::getDefaultMetadata(); $metadata[__CLASS__] = array('members' => array(), 'relations' => array('values' => array(RedBeanModel::HAS_MANY, 'CustomFieldValue', RedBeanModel::OWNED)), 'rules' => array()); return $metadata; }