/** * Set attributes with attributes of embedded model or values specified in GET params */ public function init() { $scenario = $this->getScenario(); if ($scenario === 'search' && isset($_GET[get_called_class()])) { $this->setAttributes($_GET[get_called_class()], false); } elseif ($this->relatedModel) { $this->setAttributes($this->relatedModel->getAttributes(), false); $this->label = $this->relatedModel->getRelationshipLabel($this->myModel); } }
public function getModelFieldList() { $fields = array_keys(parent::getAttributes()); foreach ($fields as $k => $f) { if ($this->tableSchema->primaryKey == $f) { $type = "HiddenField"; } else { $type = "TextField"; } $array[] = ['name' => $f, 'type' => $type, 'label' => $this->getAttributeLabel($f)]; } return $array; }
/** * Returns the attributes */ public function getApiAttributes($names = true) { $attrs = parent::getAttributes($names); return $attrs; }
/** * @param CActiveRecord $model * @param array $attributes * @return array */ public static function getElements($model, $attributes = []) { $modelAttributes = $model->getAttributes(); $modelElements = []; foreach ($modelAttributes as $attrName => $attrVal) { if (!empty($attributes)) { foreach ($attributes as $attr) { if ($attrName === $attr) { $modelElements[$attr] = ['label' => $model->getAttributeLabel($attr), 'required' => $model->isAttributeRequired($attr), 'type' => 'text']; } } continue; } $modelElements[$attrName] = ['label' => $model->getAttributeLabel($attrName), 'required' => $model->isAttributeRequired($attrName), 'type' => 'text']; // if ($field->inputType == 'dropdownlist') { // $elements['elements']['contextFields']['elements'][$field->inputName . '-' . $field->id]['items'] = // Options::model()->getContextFieldOptions($field->id); // } } return $modelElements; }
/** * Returns all attribute and flags values. * @param array $names list of attributes whose value needs to be returned. * Defaults to null, meaning all attributes as listed in {@link attributeNames} and flags as listed in * {@link flagNames} will be returned. If it is an array, only the attributes in the array will be returned. * @return array attribute values (name=>value). */ public function getAttributes($names = null) { $attributes = parent::getAttributes($names); if (is_array($names)) { $flags = $this->cachedFlags(); $flagNames = array_intersect(array_keys($flags), $names); foreach ($flagNames as $name) { $attributes[$name] = $this->getFlag($flags[$name]); } } return $attributes; }
/** * Returns the viewable attributes of an active record model in an array. * * @param CActiveRecord $model */ public function attributesOf(CActiveRecord $model) { if ($model instanceof X2Model) { $attributes = $model->getAttributes($model->getReadableAttributeNames()); // Kludge for including actionDescription in Actions: if ($model instanceof Actions && $model->fieldPermissions['actionDescription'] >= 1) { $attributes['actionDescription'] = $model->getActionDescription(); } return $attributes; } elseif ($model instanceof User) { $excludeAttributes = array_fill_keys(array('password', 'userKey', 'googleRefreshToken'), ''); $attributes = array_diff_key(array_merge($model->attributes, $model->profile->attributes), $excludeAttributes); $uid = Yii::app()->getSuId(); if (!Yii::app()->authManager->checkAccess('UsersAdmin', $uid) && $model->id != $uid) { // Attribute whitelisting for privacy $attributes = array_intersect_key($attributes, array_fill_keys(array('id', 'firstName', 'lastName', 'emailAddress', 'username', 'userAlias', 'fullName'), '')); } return $attributes; } else { return $model->attributes; } }
/** * The followings are the available columns in table 'users': * @var integer $id * @var string $username * @var string $full_name * @var string $password * @var string $email * @var string $activkey * @var integer $createtime * @var integer $lastvisit * @var integer $superuser * @var integer $status * @var timestamp $create_at * @var timestamp $lastvisit_at */ public function getAttributes($name = true) { return parent::getAttributes($name); }
/** * Copies attributes from one active record to another, skips primary key. * * @param CActiveRecord $from record to copy from * @param CActiveRecord $to record to copy to * @param array $skipAttributes attribute names which should not be copied * @param array $forceCopyAttributes attribute names which should be force copied */ protected static function copyAttributes($from, $to, $skipAttributes = array(), $forceCopyAttributes = array()) { $attributes = $from->getAttributes(); $pk = $to->getMetaData()->tableSchema->primaryKey; if (!is_array($pk)) { $skipAttributes[] = $pk; } else { $skipAttributes = array_merge($skipAttributes, $pk); } $skipAttributes = array_diff($skipAttributes, $forceCopyAttributes); foreach ($skipAttributes as $attribute) { unset($attributes[$attribute]); } $to->setAttributes($attributes, true); }
public function getFilteredAttributes(\CActiveRecord $instance) { return $instance->getAttributes(Filter::getFilter($instance->getAttributes(), get_class($instance))); }
public function getAttributes($names = true) { $attrs = parent::getAttributes($names); $attrs['displayName'] = $this->username; $attrs['photoThmbnl64'] = $this->getPhotoThmbnl64(); $attrs['pageUrl'] = $this->pageUrl; return $attrs; }
public function getAttributes($names = true) { $attrs = parent::getAttributes($names); $attrs['imageThmbnl96'] = $this->getImageThmbnl96(); return $attrs; }