本文整理汇总了PHP中AttributeValue::column方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeValue::column方法的具体用法?PHP AttributeValue::column怎么用?PHP AttributeValue::column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AttributeValue
的用法示例。
在下文中一共展示了AttributeValue::column方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTypeAttributesForSearchFromQuery
/**
* @param CHttpRequest $request
* @return array
*/
public function getTypeAttributesForSearchFromQuery(CHttpRequest $request)
{
$attributes = Yii::app()->getCache()->get('Store::filter::attributes');
if (false === $attributes) {
$attributes = [];
$models = Attribute::model()->findAll(['select' => ['name', 'id', 'type']]);
foreach ($models as $model) {
$attributes[$model->name] = $model;
}
Yii::app()->getCache()->set('Store::filter::attributes', $attributes);
}
$result = [];
$attributeValue = new AttributeValue();
foreach ($attributes as $name => $attribute) {
$searchParams = $request->getQuery($attribute->name);
//пропускаем пустые значения
if (null === $searchParams) {
continue;
}
if (is_array($searchParams)) {
if (isset($searchParams['from']) && null == $searchParams['from']) {
unset($searchParams['from']);
}
if (isset($searchParams['to']) && null == $searchParams['to']) {
unset($searchParams['to']);
}
if (empty($searchParams)) {
continue;
}
}
$result[$attribute->name] = ['value' => $searchParams, 'attribute_id' => (int) $attribute->id, 'column' => $attributeValue->column($attribute->type)];
}
return $result;
}
示例2: changeType
/**
* @param $currentType
* @param $newType
* @return bool
*/
public function changeType($currentType, $newType)
{
if ($currentType == $newType) {
return true;
}
$value = new AttributeValue();
$currentCol = $value->column($currentType);
$newCol = $value->column($newType);
if ($currentCol == $newCol) {
return true;
}
$transaction = Yii::app()->getDb()->beginTransaction();
try {
Yii::app()->getDb()->createCommand(sprintf('UPDATE {{store_product_attribute_value}} SET %s = %s WHERE attribute_id = :id', $newCol, $currentCol))->bindValue(':id', $this->id)->execute();
Yii::app()->getDb()->createCommand(sprintf('UPDATE {{store_product_attribute_value}} SET %s = null WHERE attribute_id = :id', $currentCol))->bindValue(':id', $this->id)->execute();
$transaction->commit();
return true;
} catch (Exception $e) {
$transaction->rollback();
return false;
}
}