model() public static method

public static model ( null | string $className = __CLASS__ )
$className null | string
Esempio n. 1
0
 public function setTypeAttributes($attributes)
 {
     TypeAttribute::model()->deleteAllByAttributes(['type_id' => $this->id]);
     if (is_array($attributes)) {
         foreach ($attributes as $attribute_id) {
             $typeAttribute = new TypeAttribute();
             $typeAttribute->type_id = $this->id;
             $typeAttribute->attribute_id = $attribute_id;
             $typeAttribute->save();
         }
     }
 }
Esempio n. 2
0
 /**
  * @param $attributes
  * @return bool
  */
 public function storeTypeAttributes(array $attributes)
 {
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         TypeAttribute::model()->deleteAllByAttributes(['type_id' => $this->id]);
         foreach ($attributes as $attributeId) {
             $typeAttribute = new TypeAttribute();
             $typeAttribute->type_id = $this->id;
             $typeAttribute->attribute_id = (int) $attributeId;
             $typeAttribute->save();
         }
         $transaction->commit();
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         return false;
     }
 }
Esempio n. 3
0
 /**
  * @param array $types
  * @return bool
  * @throws CDbException
  */
 public function setTypes(array $types)
 {
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         TypeAttribute::model()->deleteAll('attribute_id = :attribute', [':attribute' => $this->id]);
         foreach ($types as $type) {
             $attribute = new TypeAttribute();
             $attribute->setAttributes(['attribute_id' => $this->id, 'type_id' => (int) $type]);
             $attribute->save();
         }
         $transaction->commit();
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         return false;
     }
 }