protected function refreshRelatedStones() { $relatedStones = $this->relatedStonesArray; InteriorStoneRelation::model()->deleteAllByAttributes(array('entity_id' => $this->id, 'entity_name' => 'Interior')); if (is_array($relatedStones)) { foreach ($relatedStones as $id) { if (Stone::model()->exists('t.id = :id', array(':id' => $id))) { $relation = new InteriorStoneRelation(); $relation->entity_id = $this->id; $relation->stone_id = $id; $relation->save(); } } } }
public function actionAjaxstones($term) { if (Yii::app()->request->isAjaxRequest) { $criteria = new CDbCriteria(); $criteria->select = 't.id, t.title'; $criteria->condition = "t.title LIKE '{$term}%' " . "AND t.id IN (SELECT `stone_id` FROM " . InteriorStoneRelation::model()->tableName() . " WHERE `entity_name` = 'interior')"; $criteria->group = 't.title'; $criteria->order = 't.title ASC'; $items = array(); foreach (Stone::model()->findAll($criteria) as $item) { $items[] = array('id' => $item->id, 'label' => $item->title, 'value' => $item->title); } echo CJSON::encode($items); Yii::app()->end(); } }