Exemple #1
9
 public static function simpleAdd($logid, $type)
 {
     $attr = array('logid' => $logid, 'classify' => $type);
     $model = new Favorites();
     $model->attributes = $attr;
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Favorites();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Favorites'])) {
         $model->attributes = $_POST['Favorites'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemple #3
0
 public function actionSetFavorites($id) {
     $model = Favorites::model()->find(" user_id='" . Yii::app()->user->id
             . "' and obj_id='" . $id . "' and obj_type='0'");
     if ($model) {
         $model->delete();
         echo 'false';
     } else {
         $model = New Favorites();
         $model->user_id = Yii::app()->user->id;
         $model->obj_id = $id;
         $model->obj_type = 0;
         $model->save();
         echo 'true';
     }
 }
Exemple #4
0
         $session->save("content", "people/family/familychart.php");
         include_page('home.php');
     }
     exit;
 }
 if ($action == 'add_to_favorites') {
     $user = User::current_user();
     $user = recast('User', $user);
     $id = getRequest('id');
     $check = Favorites::getFavorites($user->id, $id);
     if (!$check) {
         $temp = new Favorites();
         $temp->id = null;
         $temp->user_id = $user->id;
         $temp->person_id = $id;
         $result = $temp->save();
         if ($result) {
             echo "Success";
             exit;
         } else {
             echo "Failure";
             exit;
         }
     } else {
         echo "That person was already favorited";
     }
     exit;
 }
 if ($action == 'remove_from_favorites') {
     $user = User::current_user();
     $user = recast('User', $user);
Exemple #5
0
 public static function favorite($code, $type, $from = 'web', $uid = '')
 {
     if (!$code || !$type) {
         return array('status' => 0, 'msg' => '数据不全,请核实');
     }
     if (!in_array($type, array('post'))) {
         return array('status' => 0, 'msg' => '暂不允许的分类');
     }
     if (is_numeric($code)) {
         $id = $code;
     } else {
         $codeArr = Posts::decode($code);
         if ($codeArr['type'] != $type || !is_numeric($codeArr['id']) || $codeArr['id'] < 1) {
             $this->jsonOutPut(0, '您所查看的内容不存在');
         }
         $id = $codeArr['id'];
     }
     if (!$uid) {
         $uid = zmf::uid();
     }
     if ($uid) {
         if (zmf::actionLimit('favorite-' . $type, $id)) {
             return array('status' => 0, 'msg' => '操作太频繁,请稍后再试');
         }
     } else {
         //没有登录的访客点收藏时判断是否已收藏过
         if (zmf::actionLimit('favorite-' . $type, $id, 1, 86400, true)) {
             return array('status' => 1, 'msg' => '已点赞', 'state' => 1);
         }
         $uid = 0;
     }
     $postInfo = Posts::model()->findByPk($id);
     if (!$postInfo || $postInfo['status'] != Posts::STATUS_PASSED) {
         return array('status' => 0, 'msg' => '文章不存在');
     }
     $attr = array('uid' => $uid, 'logid' => $id, 'classify' => $type);
     $info = false;
     if ($uid) {
         $info = Favorites::model()->findByAttributes($attr);
     }
     if ($info) {
         if (Favorites::model()->deleteByPk($info['id'])) {
             if ($type == 'post') {
                 Posts::updateCount($id, 'Posts', -1, 'favorite');
             }
             return array('status' => 1, 'msg' => '取消点赞', 'state' => 3);
         } else {
             return array('status' => 0, 'msg' => '取消点赞失败', 'state' => 4);
         }
     } else {
         $attr['cTime'] = zmf::now();
         $model = new Favorites();
         $model->attributes = $attr;
         if ($model->save()) {
             if ($type == 'post') {
                 Posts::updateCount($id, 'Posts', 1, 'favorite');
             }
             //点赞后给对方发提醒
             $_noticedata = array('uid' => $postInfo['uid'], 'authorid' => $uid, 'content' => "您的文章【{$postInfo['title']}】有了新的赞", 'new' => 1, 'type' => 'favorite', 'cTime' => zmf::now(), 'from_id' => $model->id, 'from_num' => 1);
             Notification::add($_noticedata);
             return array('status' => 1, 'msg' => '点赞成功', 'state' => 1);
         } else {
             return array('status' => 0, 'msg' => '点赞失败', 'state' => 2);
         }
     }
 }
 public function actionAdd_favorites()
 {
     $request = Yii::app()->request;
     if ($request->isAjaxRequest && !Yii::app()->user->isGuest) {
         $model = new Favorites();
         $model->mid = (int) $_POST['id'];
         $model->mtitle = $_POST['title'];
         $model->murl = $_POST['url'];
         $model->module = $_POST['module'];
         $model->user_id = Yii::app()->user->getId();
         $model->save();
         $this->widget('ext.favorites.FavoritesWidget', array('id' => (int) $_POST['id'], 'url' => $_POST['url'], 'title' => $_POST['title'], 'module' => $module, 'view' => false));
     }
 }
 public function actionAddFavorite()
 {
     $res = '';
     if (isset($_POST)) {
         $f = Favorites::model()->count('uid=:uid and user_id=:user_id', array(':uid' => $_POST['uid'], ':user_id' => $_POST['user_id']));
         if ($f > 0) {
             $res = 'Пользователь уже есть в Вашем списке Избранное';
         } else {
             $m = new Favorites();
             $m->uid = $_POST['uid'];
             $m->user_id = $_POST['user_id'];
             $user_name = Users::model()->findByPk($_POST['user_id'])->name;
             if ($m->save()) {
                 $res = $user_name . ' добавлен в Избранное';
             } else {
                 $res = 'Произошла ошибка.';
             }
         }
         //echo '<div class="apply">'.$res.'</div>';
         Yii::app()->user->setFlash('add_favorite', '<span id="apply1">' . $res . '</span>');
         return true;
     }
 }
Exemple #8
0
 /**
  * Удаляет из куки данные фавориты и посм.позже и добавляет ш базу
  * 
  */
 public function deleteCookieFavoriteProducts()
 {
     $cookieKeys = [Favorites::COOKIE_NAME_FAVORITE, Favorites::COOKIE_NAME_WATCH_LATER];
     foreach ($cookieKeys as $cookieKey) {
         if (Cookie::get($cookieKey)) {
             $models = Yii::app()->db->createCommand()->select('CONCAT(id_product, "_" , type) as concid')->from('favorites')->where('id_user=:user', [':user' => user()->id])->queryColumn();
             $cookies = CJSON::decode(Cookie::get($cookieKey));
             foreach ($cookies as $value) {
                 if (!in_array($value, $models)) {
                     $ex_val = explode('_', $value);
                     $newModel = new Favorites();
                     $newModel->id_user = user()->id;
                     $newModel->id_product = $ex_val[0];
                     $newModel->type = $ex_val[1];
                     $newModel->save();
                 }
             }
             // bazayum ave enq anum ev jnjum enq cookie-n
             setcookie($cookieKey, '', 0, '/');
         }
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function addFavorite($bookId = null)
 {
     $model = new Favorites();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if ($bookId) {
         $attributes['user_id'] = Yii::app()->user->userId;
         $attributes['book_id'] = $bookId;
         $model->attributes = $attributes;
         $model->save();
     }
 }
Exemple #10
0
 /**
  * 用户的关注与取消
  * @param type $uid
  */
 public function actionFavorUser($uid)
 {
     Users::checkPower('favorite');
     $uid = zmf::filterInput($uid);
     if (!$uid) {
         $this->jsonOutPut(0, '数据不全');
     }
     if ($uid == zmf::uid()) {
         $this->jsonOutPut(0, '不能关注自己哦');
     }
     if (zmf::actionLimit('favorUser', $uid)) {
         $this->jsonOutPut(0, '操作太频繁,请稍后再试');
     }
     $attr = array('uid' => zmf::uid(), 'logid' => $uid, 'classify' => 'user');
     $info = Favorites::model()->findByAttributes($attr);
     if ($info) {
         if (Favorites::model()->deleteByPk($info['id'])) {
             $this->jsonOutPut(3, '取消关注成功');
         } else {
             $this->jsonOutPut(0, '取消关注失败');
         }
     } else {
         $attr['status'] = 1;
         $attr['cTime'] = zmf::now();
         $attr['open'] = 1;
         $model = new Favorites();
         $model->attributes = $attr;
         if ($model->save()) {
             $_noticedata = array('uid' => $uid, 'authorid' => zmf::uid(), 'content' => '您有了新的粉丝', 'new' => 1, 'type' => 'user', 'cTime' => zmf::now(), 'from_id' => $uid, 'from_num' => 1);
             Notification::add($_noticedata);
             $this->jsonOutPut(1, '已关注');
         } else {
             $this->jsonOutPut(0, '关注失败');
         }
     }
 }