Example #1
0
 /**
  * Get or create field if not exists
  * 
  * @param int $category_id
  * @param string $fieldName
  * @return \Field 
  */
 public function createIfNotExists($category_id, $fieldName, $createAttributes = array())
 {
     $field = Field::model()->findSingleByAttributes(array('category_id' => $category_id, 'name' => $fieldName));
     if (!$field) {
         $field = new Field();
         $field->setAttributes($createAttributes, false);
         $field->category_id = $category_id;
         $field->name = $fieldName;
         $field->save();
     }
     return $field;
 }