Пример #1
0
 public function init()
 {
     parent::init();
     if (Yii::app()->request->isAjaxRequest) {
         $cs = Yii::app()->clientScript;
         $cs->scriptMap = array('jquery.js' => false);
     }
     if (empty($this->name)) {
         $this->name = 'StarRating_' . $this->object_type . '_' . $this->object_id;
     }
     if ($this->readOnly) {
         $this->allowEmpty = false;
     }
     //如果为只读,则不加载默认callback
     if (!$this->readOnly) {
         $rate_num = $this->value;
         //根据id和id_type,uid 去查询 star_rate_log
         $model = new StarRateLog();
         $params['uid'] = Yii::app()->user->id;
         $params['object_id'] = $this->object_id;
         $params['object_type'] = $this->object_type;
         //$id = $this->id;
         $info = $model->findRateInfo($params);
         if (!empty($info)) {
             $rate_num = $info['star_num'];
         }
         $this->value = $rate_num;
         $this->callback = $this->getDefaultCallBack();
     }
 }
Пример #2
0
 public function actionStarRating()
 {
     $user_id = Yii::app()->user->id;
     $object_id = Yii::app()->request->getParam('object_id');
     $object_type = Yii::app()->request->getParam('object_type');
     $star_num = Yii::app()->request->getParam('rate');
     if ($user_id == NULL or $object_type == NULL or $object_id == NULL or $star_num == NULL) {
         echo -1;
         exit;
     } else {
         $model = new StarRateLog();
         $params = array('user_id' => $user_id, 'object_type' => $object_type, 'object_id' => $object_id, 'star_num' => $star_num);
         $rate = $model->setRateInfo($params);
     }
 }
Пример #3
0
 /**
  * 查找当前用户的评分信息
  */
 public function findRateInfo($params)
 {
     $model = new StarRateLog();
     $criteria = new CDbCriteria();
     $criteria->condition = 'uid=:uid AND object_type=:object_type AND object_id=:object_id';
     $criteria->params = array(':uid' => $params['uid'], ':object_type' => $params['object_type'], ':object_id' => $params['object_id']);
     return $model->find($criteria);
 }