本文整理汇总了PHP中AttributeValue::model方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeValue::model方法的具体用法?PHP AttributeValue::model怎么用?PHP AttributeValue::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AttributeValue
的用法示例。
在下文中一共展示了AttributeValue::model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTeacherAttributeValue
public static function getTeacherAttributeValue($teacher, $attribute){
$result = '';
switch($attribute){
case '1': //capacity
$result = AttributeValue::model()->findByAttributes(array('teacher'=>$teacher, 'attribute'=>$attribute))->value;
break;
case '2': //trainer's students
$result = TeacherHelper::getTrainerStudents($teacher);
break;
case '3': //consultant_modules
$result = TeacherHelper::getConsultantModules($teacher);
break;
case '4':// leader's projects
$result = TeacherHelper::getLeaderProjects($teacher);
break;
case '6'://leader's modules
$result = TeacherHelper::getLeaderModules($teacher);
break;
case '7'://author's modules
$result = TeacherHelper::getLeaderModules($teacher);
break;
case '8'://leader's capacity
$result = AttributeValue::model()->findByAttributes(array('teacher'=>$teacher, 'attribute'=>$attribute))->value;
break;
default:
$result = AttributeValue::model()->findByAttributes(array('teacher'=>$teacher, 'attribute'=>$attribute))->value;
}
return $result;
}
示例2: actionDeleteFile
public function actionDeleteFile()
{
if (!Yii::app()->getRequest()->getIsPostRequest()) {
throw new CHttpException();
}
$product = (int) Yii::app()->getRequest()->getPost('product');
$attribute = (int) Yii::app()->getRequest()->getPost('attribute');
$model = AttributeValue::model()->find('product_id = :product AND attribute_id = :attribute', [':product' => $product, ':attribute' => $attribute]);
if (null === $model || null === $model->getFilePath()) {
Yii::app()->ajax->success();
}
$model->delete();
Yii::app()->ajax->success();
}
示例3: uploadAttributesFiles
/**
* @param $model
*/
protected function uploadAttributesFiles($model)
{
if (!empty($_FILES['Attribute']['name'])) {
foreach ($_FILES['Attribute']['name'] as $key => $file) {
$value = AttributeValue::model()->find('product_id = :product AND attribute_id = :attribute', [':product' => $model->id, ':attribute' => $key]);
$value = $value ?: new AttributeValue();
$value->setAttributes(['product_id' => $model->id, 'attribute_id' => $key]);
$value->addFileInstanceName('Attribute[' . $key . '][name]');
if (false === $value->save()) {
Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('StoreModule.store', 'Error uploading some files...'));
}
}
}
}
示例4: saveTypeAttributes
/**
* @param array $attributes
* @return bool
*/
public function saveTypeAttributes(array $attributes)
{
$transaction = Yii::app()->getDb()->beginTransaction();
try {
foreach ($attributes as $attribute => $value) {
if (null === $value) {
continue;
}
$model = AttributeValue::model()->find('product_id = :product AND attribute_id = :attribute', [':product' => $this->id, ':attribute' => $attribute]);
//множественные значения
if (is_array($value)) {
AttributeValue::model()->deleteAll('product_id = :product AND attribute_id = :attribute', [':product' => $this->id, ':attribute' => $attribute]);
foreach ($value as $val) {
$model = new AttributeValue();
if (false === $model->store($attribute, $val, $this)) {
throw new InvalidArgumentException('Error store attribute!');
}
}
} else {
$model = $model ?: new AttributeValue();
if (false === $model->store($attribute, $value, $this)) {
throw new InvalidArgumentException('Error store attribute!');
}
}
}
$transaction->commit();
return true;
} catch (Exception $e) {
$transaction->rollback();
return false;
}
}
示例5: attribute
/**
* @param $attribute
* @param null $default
* @return bool|float|int|null|string
*/
public function attribute($attribute, $default = null)
{
if ($this->getIsNewRecord()) {
return null;
}
//@TODO переделать на получение в 1 запрос
$model = AttributeValue::model()->with('attribute')->find('product_id = :product AND attribute_id = :attribute', [':product' => $this->id, ':attribute' => $attribute->id]);
if (null === $model) {
return null;
}
return $model->value($default);
}