/** * Save Asset with Tag * * @param ActiveRecordInterface $assetModel the Asset model to be linked with the current one. * @param ActiveRecordInterface $tagModel the Tag model to be linked with the current one. */ public static function saveAssetTag($assetModel, $tagModel) { $model = self::loadAssetTag($assetModel->Id, $tagModel->Id); if ($assetModel) { $assetModel->link('tagassetmaps', $model); } if ($tagModel) { $tagModel->link('tagassetmaps', $model); } }
/** * * @param string $name the case sensitive name of the relationship. * @param ActiveRecordInterface $model the model to be linked with the current one. * @param array $extraColumns additional column values to be saved into the junction table. */ public function link($name, $model, $extraColumns = []) { if ($model) { $reflect = null; if (isset($this->morphReflect) && $this->morphReflect) { $class = $model->classname(); $flip = array_flip($this->morphReflect); if (isset($flip[$class])) { $reflect = $flip[$class]; } } if (!$reflect) { $reflect = (new \ReflectionClass($model))->getShortName(); } $this->{$name . '_model'} = $reflect; parent::link($name, $model, $extraColumns); } else { $this->{$name . '_model'} = ''; parent::unlink($name); } }
protected static function applyRecordDelta(ActiveRecordInterface $Record, array $data) { if (static::$editableFields) { $Record->setFields(array_intersect_key($data, array_flip(static::$editableFields))); } else { return $Record->setFields($data); } }
public static function activeLabel(ActiveRecordInterface $record, $attribute, array $htmloptions = array()) { $label = $record->getAttributeLabel($attribute); return self::label($label, $htmloptions); }
/** * @param string $name the case sensitive name of the relationship. * @param ActiveRecordInterface $model the model to be linked with the current one. * @param array $extraColumns - not need inherit BaseActiveRecord class */ public function link($name, $model, $extraColumns = []) { $relation = $this->getRelation($name); if ($relation->embedded) { // throw new InvalidCallException('Unable to link models: EMBEDDED relation `' . $name . '` can\'t bee linked.'); Yii::trace('Convert LINK model to EMBEDDED (unset @rid)', __METHOD__); // $model->setAttribute('@rid', '#-1:-1'); $model->markAttributeDirty('@rid'); // call: unset($this->_oldAttributes[$name]); unset($model->{'@rid'}); // will call BaseActiveRecord::__unset if ($relation->multiple) { $tmpArr = is_array($this->{$name}) ? $this->{$name} : []; array_push($tmpArr, $model); $this->{$name} = $tmpArr; unset($tmpArr); } else { $this->{$name} = $model; } } else { if ($model->getIsNewRecord()) { //? or need auto save throw new InvalidCallException('Unable to link models: relation `' . $name . '` has no @rid.'); } if ($relation->multiple) { $tmpArr = is_array($this->{$name}) ? $this->{$name} : []; array_push($tmpArr, $model); $this->{$name} = $tmpArr; $this->populateRelation($name, $this->{$name}); unset($tmpArr); } else { $this->{$name} = $model; $this->populateRelation($name, $model); } } }