本文整理匯總了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);
}