['typeId', 'typeCode', 'name', 'sorter', 'canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'factor', 'enabled', 'attributeCode', 'required', 'sortable', 'uofmPre', 'uofmPost', 'long'], 'numeric' => ['typeId', 'typeCode', 'name', 'sorter', 'canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'factor', 'enabled', 'attributeCode', 'required', 'sortable', 'uofmPre', 'uofmPost', 'decimalMin', 'decimalMax', 'decimalRound'], 'datetime' => ['typeId', 'typeCode', 'name', 'sorter', 'canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'factor', 'enabled', 'attributeCode', 'required', 'sortable', 'uofmPre', 'uofmPost', 'datetimeStorageId'] ]; protected $_attributeUpdateViaDbFunctionColumn = [ 'text' => ['id', 'sorter', 'canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'factor', 'enabled', 'attributeCode', 'required', 'sortable', 'long'], 'numeric' => ['id', 'sorter', 'canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'factor', 'enabled', 'attributeCode', 'required', 'sortable', 'decimalMin', 'decimalMax', 'decimalRound'], 'datetime' => ['id', 'sorter', 'canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'factor', 'enabled', 'attributeCode', 'required', 'sortable', 'datetimeStorageId'] ]; protected $_updateViaDbFunctionResetColumn = ['canSearchRaw', 'displayInObjectRaw', 'displayInObjectListRaw', 'decimalMin', 'decimalMax']; public $type; public $dataType; //властивості атрибуту типу "text" public $long; //властивості атрибуту типу "numeric" public $decimalMax; public $decimalMin; public $decimalRound; //властивості атрибуту типу "datetime" public $datetimeStorageId; public function scenarios() { return [ 'insert' => ['name', 'typeId', 'canSearchRaw', 'enabled', 'uofmPre', 'uofmPost'], 'update' => ['name', 'typeId', 'canSearchRaw', 'enabled', 'uofmPre', 'uofmPost'] ]; } public static function tableNameLocale() { return 'attributeTL'; } public function beforeSave($insert) { if (!$this->dataType) { $this->dataType = $this->getAttribute('attributeDataType'); } if (in_array($this->dataType, ['text', 'numeric', 'datetime'])) { $this->_insertViaDbFunctionColumn = $this->_attributeInsertViaDbFunctionColumn[$this->dataType]; $this->_updateViaDbFunctionColumn = $this->_attributeUpdateViaDbFunctionColumn[$this->dataType]; $this->_saveViaDbFunctionItemTemplate['insert'] .= ucfirst($this->dataType); $this->_saveViaDbFunctionItemTemplate['update'] .= ucfirst($this->dataType); } return parent::beforeSave($insert); } protected static function _getContentFields() { return array_merge(['name'], parent::_getContentFields()); } public function getAdditionalAttributes() { $result = []; $query = static::createQuery() ->from(['attributeTL']) ->andWhere(['id' => $this->getAttribute('id')]) ; $contentAttributes = $query->createCommand()->queryAll(); foreach ($contentAttributes as $contentAttribute) { $result['uofmPre_' . $contentAttribute['languageId']] = $contentAttribute['uofmPre']; $result['uofmPost_' . $contentAttribute['languageId']] = $contentAttribute['uofmPost']; } $query = static::createQuery() ->from(['attributeV']) ->select(['`textIsLong` `long`', '`datetimeStorageId` `storageId`', '`decimalMin` `min`', '`decimalMax` `max`', '`decimalRound` `round`']) ->andWhere(['id' => $this->getAttribute('id')]) ; $result = array_merge($result, $query->createCommand()->queryOne()); $result['min'] = isset($result['min']) ? (float) $result['min'] : null; $result['max'] = isset($result['max']) ? (float) $result['max'] : null; $result['round'] = isset($result['round']) ? (int) $result['round'] : null; return $result; } }