/**
  * 判断一个用户是否跟随者
  * @param unknown_type $userId
  */
 public function isCollector($userId)
 {
     $owner = $this->getOwner();
     //if(!$owner->entityId) return false;
     $collect = Collect::model()->findByAttributes(array('userId' => $userId, 'collectableEntityId' => $owner->entityId));
     if (!$collect) {
         return false;
     }
     return true;
 }
Пример #2
0
 public function actionDelAllCollection()
 {
     if (!empty($this->_account['userId'])) {
         $myCollection = Collect::model()->find('user_id=:user_id', array(':user_id' => $this->_account['userId']));
         if ($myCollection->delete()) {
             echo CJSON::encode(array('status' => 200, 'msg' => '删除成功'));
         } else {
             echo CJSON::encode(array('status' => 500, 'msg' => '删除失败'));
         }
     } else {
         echo CJSON::encode(array('status' => 404, 'msg' => '无权访问!'));
     }
 }
Пример #3
0
 public function actionCollection()
 {
     $id = Yii::app()->request->getPost('id');
     if (!empty($this->_account['userId'])) {
         $collect_model = Collect::model()->find('user_id=:user_id', array(':user_id' => $this->_account['userId']));
         if (!empty($collect_model)) {
             $collection = $collect_model->collection;
             $collection = explode(',', $collection);
             if (in_array($id, $collection)) {
                 echo CJSON::encode(array('status' => 500, 'msg' => '您已收藏过该房源'));
             } else {
                 array_push($collection, $id);
                 $collection = implode(',', $collection);
                 $collect_model->collection = $collection;
                 if ($collect_model->save()) {
                     echo CJSON::encode(array('status' => 200, 'msg' => '收藏成功'));
                 } else {
                     echo CJSON::encode(array('status' => 500, 'msg' => '收藏失败'));
                 }
             }
         } else {
             $collection = array();
             array_push($collection, $id);
             $collection = implode(',', $collection);
             $collect_model = new Collect();
             $collect_model->user_id = $this->_account['userId'];
             $collect_model->collection = $collection;
             if ($collect_model->save()) {
                 echo CJSON::encode(array('status' => 200, 'msg' => '收藏成功'));
             } else {
                 echo CJSON::encode(array('status' => 500, 'msg' => '收藏失败'));
             }
         }
     } else {
         echo CJSON::encode(array('status' => 404, 'msg' => '您还未登录,请先登录'));
     }
 }