本文整理汇总了PHP中yii\db\ActiveRecord::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::getAttribute方法的具体用法?PHP ActiveRecord::getAttribute怎么用?PHP ActiveRecord::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: moveNode
/**
* @param int $to
* @param int $depth
* @throws Exception
*/
protected function moveNode($to, $depth = 0)
{
$left = $this->owner->getAttribute($this->leftAttribute);
$right = $this->owner->getAttribute($this->rightAttribute);
$depth = $this->owner->getAttribute($this->depthAttribute) - $this->node->getAttribute($this->depthAttribute) - $depth;
if ($this->treeAttribute === null || $this->owner->getAttribute($this->treeAttribute) === $this->node->getAttribute($this->treeAttribute)) {
// same root
$this->owner->updateAll([$this->depthAttribute => new Expression("-[[{$this->depthAttribute}]]" . sprintf('%+d', $depth))], $this->getDescendants(null, true)->where);
$delta = $right - $left + 1;
if ($left >= $to) {
$this->shift($to, $left - 1, $delta);
$delta = $to - $left;
} else {
$this->shift($right + 1, $to, -$delta);
$delta = $to - $right;
}
$this->owner->updateAll([$this->leftAttribute => new Expression("[[{$this->leftAttribute}]]" . sprintf('%+d', $delta)), $this->rightAttribute => new Expression("[[{$this->rightAttribute}]]" . sprintf('%+d', $delta)), $this->depthAttribute => new Expression("-[[{$this->depthAttribute}]]")], ['and', $this->getDescendants(null, true)->where, ['<', $this->depthAttribute, 0]]);
} else {
// move from other root
$tree = $this->node->getAttribute($this->treeAttribute);
$this->shift($to, null, $right - $left + 1, $tree);
$delta = $to - $left;
$this->owner->updateAll([$this->leftAttribute => new Expression("[[{$this->leftAttribute}]]" . sprintf('%+d', $delta)), $this->rightAttribute => new Expression("[[{$this->rightAttribute}]]" . sprintf('%+d', $delta)), $this->depthAttribute => new Expression("[[{$this->depthAttribute}]]" . sprintf('%+d', -$depth)), $this->treeAttribute => $tree], $this->getDescendants(null, true)->where);
$this->shift($right + 1, null, $left - $right - 1);
}
}
示例2: moveTo
/**
* @param int $to
* @param bool $forward
*/
protected function moveTo($to, $forward)
{
$this->owner->setAttribute($this->sortAttribute, $to);
$tableName = $this->owner->tableName();
$path = $this->getParentPath($this->node->getAttribute($this->pathAttribute));
$like = strtr($path . $this->delimiter, ['%' => '\\%', '_' => '\\_', '\\' => '\\\\']);
$unallocated = (new Query())->select("{$tableName}.[[{$this->sortAttribute}]]")->from("{$tableName}")->leftJoin("{$tableName} n", ['and', ['like', "n.[[{$this->pathAttribute}]]", $like . '%', false], ["n.[[{$this->depthAttribute}]]" => $this->node->getAttribute($this->depthAttribute), "n.[[{$this->sortAttribute}]]" => new Expression("{$tableName}.[[{$this->sortAttribute}]] " . ($forward ? '+' : '-') . " 1")]])->where(['and', ['like', "{$tableName}.[[{$this->pathAttribute}]]", $like . '%', false], [$forward ? '>=' : '<=', "{$tableName}.[[{$this->sortAttribute}]]", $to], ["{$tableName}.[[{$this->depthAttribute}]]" => $this->node->getAttribute($this->depthAttribute), "n.[[{$this->sortAttribute}]]" => null]])->orderBy(["{$tableName}.[[{$this->sortAttribute}]]" => $forward ? SORT_ASC : SORT_DESC])->limit(1)->scalar($this->owner->getDb());
$this->owner->updateAll([$this->sortAttribute => new Expression("[[{$this->sortAttribute}]] " . ($forward ? '+' : '-') . " 1")], ['and', ['like', "[[{$this->pathAttribute}]]", $like . '%', false], ["[[{$this->depthAttribute}]]" => $this->node->getAttribute($this->depthAttribute)], ['between', $this->sortAttribute, $forward ? $to : $unallocated, $forward ? $unallocated : $to]]);
}
示例3: afterFindSingle
/**
* @return void
*/
public function afterFindSingle()
{
$file = array_map(function ($attribute) {
return $this->owner->getAttribute($attribute);
}, $this->fields());
if (array_key_exists('path', $file) && $file['path']) {
$this->owner->{$this->attribute} = $this->enrichFileData($file);
}
}
示例4: insertNearInternal
/**
* Insert operation internal handler
* @param bool $forward
* @throws Exception
*/
protected function insertNearInternal($forward)
{
$this->checkNode(true);
$this->owner->setAttribute($this->parentAttribute, $this->node->getAttribute($this->parentAttribute));
if ($this->sortable !== false) {
if ($forward) {
$this->owner->moveAfter($this->node);
} else {
$this->owner->moveBefore($this->node);
}
}
}
示例5: findInsertAfterRange
/**
* @param int $left
* @param int $right
* @return array|null
*/
protected function findInsertAfterRange(&$left, &$right)
{
$result = null;
$left = $this->node->getAttribute($this->rightAttribute);
$right = $this->getNodeBehavior()->getNext()->select($this->leftAttribute)->scalar();
if ($right === false) {
$result = $this->getNodeBehavior()->getParent()->select([$this->leftAttribute, $this->rightAttribute])->createCommand()->queryOne();
$right = $result[$this->rightAttribute];
}
$right = (int) $right;
return $result;
}
示例6: getSortableQuery
/**
* @return \yii\db\ActiveQuery
*/
protected function getSortableQuery()
{
switch ($this->operation) {
case self::OPERATION_PREPEND_TO:
case self::OPERATION_APPEND_TO:
$path = $this->node->getAttribute($this->pathAttribute);
$depth = $this->node->getAttribute($this->depthAttribute) + 1;
break;
case self::OPERATION_INSERT_BEFORE:
case self::OPERATION_INSERT_AFTER:
$path = $this->node->getParentPath();
$depth = $this->node->getAttribute($this->depthAttribute);
break;
default:
$path = $this->getParentPath();
$depth = $this->owner->getAttribute($this->depthAttribute);
}
$tableName = $this->owner->tableName();
return $this->owner->find()->andWhere($this->treeCondition())->andWhere($path !== null ? ['like', "{$tableName}.[[{$this->pathAttribute}]]", $this->getLike($path), false] : '1=0')->andWhere(["{$tableName}.[[{$this->depthAttribute}]]" => $depth]);
}
示例7: moveNode
/**
* @param integer $value
* @param integer $depth
*/
protected function moveNode($value, $depth)
{
$db = $this->owner->getDb();
$leftValue = $this->owner->getAttribute($this->leftAttribute);
$rightValue = $this->owner->getAttribute($this->rightAttribute);
$depthValue = $this->owner->getAttribute($this->depthAttribute);
$depthAttribute = $db->quoteColumnName($this->depthAttribute);
$depth = $this->node->getAttribute($this->depthAttribute) - $depthValue + $depth;
if ($this->treeAttribute === false || $this->owner->getAttribute($this->treeAttribute) === $this->node->getAttribute($this->treeAttribute)) {
$delta = $rightValue - $leftValue + 1;
$this->shiftLeftRightAttribute($value, $delta);
if ($leftValue >= $value) {
$leftValue += $delta;
$rightValue += $delta;
}
$condition = ['and', ['>=', $this->leftAttribute, $leftValue], ['<=', $this->rightAttribute, $rightValue]];
$this->applyTreeAttributeCondition($condition);
$this->owner->updateAll([$this->depthAttribute => new Expression($depthAttribute . sprintf('%+d', $depth))], $condition);
foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) {
$condition = ['and', ['>=', $attribute, $leftValue], ['<=', $attribute, $rightValue]];
$this->applyTreeAttributeCondition($condition);
$this->owner->updateAll([$attribute => new Expression($db->quoteColumnName($attribute) . sprintf('%+d', $value - $leftValue))], $condition);
}
$this->shiftLeftRightAttribute($rightValue + 1, -$delta);
} else {
$leftAttribute = $db->quoteColumnName($this->leftAttribute);
$rightAttribute = $db->quoteColumnName($this->rightAttribute);
$nodeRootValue = $this->node->getAttribute($this->treeAttribute);
foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) {
$this->owner->updateAll([$attribute => new Expression($db->quoteColumnName($attribute) . sprintf('%+d', $rightValue - $leftValue + 1))], ['and', ['>=', $attribute, $value], [$this->treeAttribute => $nodeRootValue]]);
}
$delta = $value - $leftValue;
$this->owner->updateAll([$this->leftAttribute => new Expression($leftAttribute . sprintf('%+d', $delta)), $this->rightAttribute => new Expression($rightAttribute . sprintf('%+d', $delta)), $this->depthAttribute => new Expression($depthAttribute . sprintf('%+d', $depth)), $this->treeAttribute => $nodeRootValue], ['and', ['>=', $this->leftAttribute, $leftValue], ['<=', $this->rightAttribute, $rightValue], [$this->treeAttribute => $this->owner->getAttribute($this->treeAttribute)]]);
$this->shiftLeftRightAttribute($rightValue + 1, $leftValue - $rightValue - 1);
}
}
示例8: compareValue
/**
* @inheritDoc
*/
public function compareValue(ActiveRecord $model, $value)
{
/** @var ActiveRecord $model */
return $model->getAttribute($this->attributeName) == $value;
}
示例9: editAttribute
/**
* @param ActiveRecord $model
* @return string
*/
public function editAttribute($model, $field, $params = [])
{
if (!isset($params['options'])) {
$params['options'] = [];
}
$options = $params['options'];
unset($params['options']);
/** @var \yii\widgets\ActiveField $form */
$form = $params['formField'];
unset($params['formField']);
$return = $form->fileInput($options);
$file = $model->getAttribute($field->varname);
if ($file) {
$return .= "<div class='form-group'><fieldset>";
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$root = Yii::getAlias('@webroot/' . $file);
$type = explode("/", finfo_file($finfo, $root));
$return .= Html::activeCheckBox($model, '[uwfdel]' . $field->varname, ['label' => Module::t('Delete file')]) . "<br>";
if ($type[0] == 'image') {
$return .= Html::img(Url::base() . "/" . $file, ['class' => 'UWfile-image-preview']);
} else {
$assetsPath = Yii::$app->assetManager->getBundle('marsoltys\\yii2user\\assets\\UserAssets')->basePath;
$assetsUrl = Yii::$app->assetManager->getBundle('marsoltys\\yii2user\\assets\\UserAssets')->baseUrl;
$img = "/img/" . pathinfo($file, PATHINFO_EXTENSION) . ".png";
if (file_exists($assetsPath . $img)) {
$return .= Html::img($assetsUrl . $img, ['class' => 'UWfile-image-preview']);
} else {
$return .= Html::img($assetsUrl . "/img/file.png", ['class' => 'UWfile-image-preview']);
}
$return .= pathinfo($file, PATHINFO_BASENAME) . " ";
$return .= Html::a(pathinfo($file, PATHINFO_BASENAME) . " ", Url::base() . "/" . $file);
}
$return .= "</fieldset></div>";
}
return $return;
}
示例10: getNode
/**
* @param ActiveRecord|TreeInterface $node
* @return array
*/
protected function getNode($node)
{
$items = [];
/** @var ActiveRecord[]|TreeInterface[] $children */
$children = $node->children;
foreach ($children as $n => $node) {
$items[$n]['id'] = $node->getPrimaryKey();
$items[$n]['name'] = $node->getAttribute($this->nameAttribute);
$items[$n]['children'] = $this->getNode($node);
$items[$n]['update-url'] = Url::to([$this->advancedUpdateRoute, 'id' => $node->getPrimaryKey()]);
}
return $items;
}
示例11: WhereConstruct
/**
* Формирует массив конструкции Where() ActiveQuery.
* @param ActiveRecord $ModelSearch Модель, для который создаем конструкцию Where().
* @param string $Field Атрибут модели, по которому осуществляем поиск, фильтрацию.
* @param integer $Type Тип значения в атрибуте модели (Proc::Time, Proc::Date, Proc::DateTime).
* @return array Массив конструкции Where().
*/
static function WhereConstruct($ModelSearch, $Field, $Type = 0)
{
$AttributeModelValue = $ModelSearch->getAttribute($Field);
$AttributeValue = empty($AttributeModelValue) ? $ModelSearch->{$Field} : $ModelSearch->getAttribute($Field);
preg_match('/(>=|<=|>|<|=)?(.*)/', $AttributeValue, $Matches);
$Operator = $Matches[1];
$Value = $Matches[2];
if (!empty($Value)) {
switch ($Type) {
case self::Time:
$Value = date("H:i:s", strtotime($Value));
break;
case self::Date:
$Value = date("Y-m-d", strtotime($Value));
break;
case self::DateTime:
$Value = date("Y-m-d H:i:s", strtotime($Value));
break;
}
}
return [empty($Operator) ? '=' : $Operator, $Field, $Value];
}
示例12: deleteTranslation
/**
* @param \yii\db\ActiveRecord $model
* @return bool
*/
private function deleteTranslation($model)
{
if (!$model->isNewRecord) {
$model->delete();
unset($this->_models[$model->getAttribute($this->languageAttribute)]);
}
return true;
}
示例13: getValue
/**
* @return int
*/
public function getValue()
{
return $this->owner->getAttribute($this->attributeName);
}
示例14: getAttribute
public function getAttribute($name)
{
return isset($this->{$name}) ? $this->{$name} : parent::getAttribute($name);
}
示例15: getAttribute
/**
* Returns the named attribute value.
* If this record is the result of a query and the attribute is not loaded,
* null will be returned.
* @param string $name the attribute name
* @return mixed the attribute value. Null if the attribute is not set or does not exist.
* @see hasAttribute()
*/
public function getAttribute($name)
{
if ($this->hasAttribute($name)) {
// we will now have optionally applied default values if this is a new record
return parent::getAttribute($name);
}
return null;
}