model() public static method

Please note that you should have this exact method in all your CActiveRecord descendants!
public static model ( string $className = __CLASS__ ) : AttributeValue
$className string active record class name.
return AttributeValue the static model class
Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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();
 }
 /**
  * @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...'));
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @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;
     }
 }
Ejemplo n.º 5
0
 /**
  * @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);
 }