Example #1
0
 public function getWishListForWeb($user_id)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "user_id = {$user_id}";
     $wishlists = Wishlist::model()->findAll($criteria);
     $wishlist_arr = array();
     foreach ($wishlists as $wishlist) {
         $wishlist_arr[] = $wishlist->post_id;
     }
     //var_dump($wishlist_arr); die;
     $returnArr = array();
     $criteria_post = new CDbCriteria();
     $criteria_post->addInCondition('t.post_id', $wishlist_arr);
     $count = Posts::model()->count($criteria_post);
     $pages = new CPagination($count);
     $pages->validateCurrentPage = FALSE;
     $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
     $pages->applyLimit($criteria_post);
     $posts = Posts::model()->findAll($criteria_post);
     $is_followed = User::model()->isFollowedByUser(Yii::app()->session['user_id'], $user_id, 'USER');
     $profile = User::model()->findByPk($user_id);
     foreach ($posts as $post) {
         $itemArr = Posts::model()->getPostById($post->post_id, Yii::app()->session['user_id']);
         $returnArr[] = $itemArr;
     }
     return array('data' => $returnArr, 'pages' => $pages, 'profile' => $profile, 'is_followed' => $is_followed);
     // return FALSE;
 }
 public function actionShowPosts($id, $mid, $sid)
 {
     $posts = Posts::model()->findByPk($sid);
     $multimedia = json_decode($posts->multimedia);
     $count = count($multimedia);
     foreach ($multimedia as $ind => $file) {
         if ($file->nomber == $mid) {
             $num = $ind + 1;
             if ($ind == 0) {
                 $prev = $multimedia[$count - 1]->nomber . '/' . $sid;
             } else {
                 $prev = $multimedia[$ind - 1]->nomber . '/' . $sid;
             }
             if ($ind == $count - 1) {
                 $next = $multimedia[0]->nomber . '/' . $sid;
             } else {
                 $next = $multimedia[$ind + 1]->nomber . '/' . $sid;
             }
             $current_photo = $file;
         }
     }
     $myPage = $id == Yii::app()->user->id;
     $myProfile = UserProfile::model()->getUserProfile(Yii::app()->user->id);
     $ext = Files::model()->findByPk($current_photo->id)->extension;
     $aroundInfo = array('num' => $num, 'count' => $count, 'prev' => $prev, 'next' => $next);
     $comments = Comments::model()->getLast('posts_' . $sid, $mid, 10);
     $comments = array_reverse($comments);
     $file = array('id' => $current_photo->id, 'file' => $current_photo->id, 'image' => array('extension' => $ext), 'description' => '', 'upload_date' => $current_photo->upload_date);
     $this->renderPartial('show_photo', array('photo' => $file, 'nav_link' => 'showposts', 'user_id' => $id, 'aroundInfo' => $aroundInfo, 'myProfile' => $myProfile, 'myPage' => $myPage, 'comments' => $comments, 'comments_tbl' => 'posts_' . $sid, 'comments_item_id' => $mid));
 }
 public function actionDelete($mid)
 {
     if (Yii::app()->request->isAjaxRequest) {
         $post = Posts::model()->findByPk($mid);
         if ($post->author_id == Yii::app()->user->id || $post->owner_id == Yii::app()->user->id) {
             // удаляем только если автор комментария == текущему авторизованному пользователю, либо если хозяин стены == текущему авторизованному пользователю
             // Удаление поста и его комментариев с использованием транзакций
             $transaction = $post->dbConnection->beginTransaction();
             PostsFiles::model()->deleteFiles($post->id);
             try {
                 $post->delete();
                 $transaction->commit();
                 $res = true;
             } catch (Exception $e) {
                 $transaction->rollback();
                 $res = false;
             }
             if ($res) {
                 echo json_encode(array('status' => 'ok'));
             } else {
                 echo json_encode(array('status' => 'error', 'data' => 'Не могу подключиться к БД'));
             }
         } else {
             throw new CException('Not Found', 404);
         }
     } else {
         throw new CException('Not Found', 404);
     }
 }
Example #4
0
 public function actionInsertPostCeleb()
 {
     $this->pageTitile = 'Thêm bài viết người nổi tiếng';
     $request = Yii::app()->request;
     try {
         $post_content = StringHelper::filterString($request->getPost('post_content'));
         $celeb_id = StringHelper::filterString($request->getPost('celeb_id'));
         $location = StringHelper::filterString($request->getPost('location'));
         $cats = $request->getPost('cats');
         if (count($_FILES['images']['tmp_name']) > 1) {
             $url_arr = UploadHelper::getUrlUploadMultiImages($_FILES['images'], $celeb_id . 'celeb');
         } else {
             $url_arr = UploadHelper::getUrlUploadMultiImages($_FILES['images'], $celeb_id . 'celeb');
         }
         // $album = StringHelper::filterString($request->getPost('album'));
         $album = NULL;
         $res = Posts::model()->addPostCeleb($celeb_id, $post_content, $location, $url_arr, $album, $cats);
         if ($res != FALSE) {
             Yii::app()->user->setFlash('success', 'Thêm bài viết thành công');
         } else {
             Yii::app()->user->setFlash('error', 'Có lỗi xảy ra');
         }
         $this->redirect(Yii::app()->createUrl('celebrity/addPost'));
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #5
0
 /**
  * 文章
  */
 private function blogSitemap()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'classify=' . $this->classify . ' AND status=' . Posts::STATUS_PASSED;
     $criteria->select = 'id, cTime';
     $criteria->order = 'id ASC';
     $criteria->limit = $this->limitPerPage;
     $criteria->offset = $this->pageStart;
     $model = Posts::model()->findAll($criteria);
     foreach ($model as $k => $v) {
         $this->blogItems[] = array('url' => $this->webSiteTitle . '/post/' . $v->id . '.html', 'date' => date(DATE_W3C, $v->cTime));
         //$tagArr = preg_split('#,|,#i', $v->tag);
         if (!empty($tagArr)) {
             foreach ($tagArr as $k => $v) {
                 if (!in_array($v, $this->tagItems)) {
                     $this->tagItems[] = $v;
                 }
             }
         }
     }
     //创建临时函数数组
     $tmp = array();
     $tmp = $this->tagItems;
     $this->tagItems = array();
     foreach ($tmp as $k => $v) {
         $this->tagItems[] = array('url' => $this->webSiteTitle . '/posts/tag-' . $v->id . '.html', 'date' => date(DATE_W3C, time()));
     }
     unset($tmp);
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     //		$this->render('view',array(
     //			'model'=>$this->loadModel($id),
     //		));
     $Posts = Posts::model()->findAll(array('condition' => "`secciones_idSeccion` = {$id}", 'limit' => 7, 'order' => 'fecha DESC'));
     $this->render('view', array('posts' => $Posts, 'model' => $this->loadModel($id)));
 }
Example #7
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Posts the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Posts::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #8
0
 public static function findAllCildrenAsArray($id)
 {
     $comment = Posts::model()->findByPk($id);
     $model = array_reduce($comment->children()->findAll(), function ($array, $item) {
         $array[] = $item->toJson();
         return $array;
     }, []);
     return $model;
 }
Example #9
0
 public function actionStat()
 {
     $posts = Posts::model()->count();
     $commentsNum = Comments::model()->count();
     $attachsNum = Attachments::model()->count();
     $feedbackNum = Feedback::model()->count();
     $arr = array('posts' => $posts, 'commentsNum' => $commentsNum, 'attachsNum' => $attachsNum, 'feedbackNum' => $feedbackNum);
     $this->render('stat', $arr);
 }
Example #10
0
 /**
  * This is method for delete post from list
  * @param  string $id postID
  * @return array[] {
  *         		'code':200,
  *         		'message':'SUCCESS'
  * }
  */
 public function deletePost($id)
 {
     $result = Posts::model()->findByAttributes(array('id' => $id));
     $result->status = '0';
     if ($result->save()) {
         $data = array('code' => 200, 'message' => 'SUCCESS');
     }
     return $data;
 }
Example #11
0
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  */
 public function search()
 {
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.
     $criteria = new CDbCriteria();
     $criteria->compare('idSeccion', $this->idSeccion);
     $criteria->compare('nombre', $this->nombre, true);
     $post = Posts::model()->findByPk('1');
     return new CActiveDataProvider($this, array('criteria' => $criteria));
 }
Example #12
0
 public function liked($id)
 {
     $result = Like::model()->findByAttributes(array('id' => $id));
     $result->status = 0;
     $post = Posts::model()->findByAttributes(array('id' => $result->postId));
     $post->like_num--;
     if ($result->save() && $post->save()) {
         echo CJSON::encode(array('code' => 200, 'mes' => 'success', 'data' => array('postId' => $result->postId)));
     }
 }
Example #13
0
 public function actionDetailCategory()
 {
     $request = Yii::app()->request;
     try {
         $cat_id = StringHelper::filterString($request->getQuery('cat_id'));
         $data = Posts::model()->getPostByCategoryId($cat_id);
         $this->render('categoryById', $data);
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #14
0
 public function actionExplore()
 {
     try {
         //            $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/frontend2/views/layouts";
         //            $this->layout = 'main_empty_2';
         $feed = Posts::model()->getExplore();
         $this->render('explore', $feed);
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #15
0
 public function actionSearchPostWeb()
 {
     $request = Yii::app()->request;
     try {
         $query = StringHelper::filterString($request->getQuery('query'));
         $data = Posts::model()->searchPost($query, Yii::app()->session['user_id']);
         //   var_dump($data); die;
         $this->render('index', $data);
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #16
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     //            $dataProvider = new CActiveDataProvider('Posts');
     //            $this->render('index', array(
     //            'dataProvider' => $dataProvider,
     //        ));
     // renders the view file 'protected/views/site/index.php'
     // using the default layout 'protected/views/layouts/main.php'
     //$this->render('index');
     $noticias = Posts::model()->findAll(array('order' => 'fecha DESC', 'condition' => "`secciones_idSeccion` = 1"));
     $this->render('index', array('noticias' => $noticias));
 }
Example #17
0
 public function addComment($user_id, $post_id, $content)
 {
     $model = new Comments();
     $model->post_id = $post_id;
     $model->created_by = $user_id;
     $model->updated_at = time();
     $model->comment_content = $content;
     $model->status = 1;
     $model->created_at = time();
     $model->updated_at = time();
     $model->save(FALSE);
     $post = Posts::model()->findByPk($post_id);
     $post->post_comment_count++;
     $user = User::model()->findByPk($model->created_by);
     $user_commented = User::model()->findByPk($post->user_id);
     if ($user_commented) {
         if ($user->id != $post->user_id) {
             $users_have_commented = $this->getListUserCommentedOnPost($post_id);
             if ($users_have_commented) {
                 foreach ($users_have_commented as $item) {
                     if ($user_id != $item->created_by && $post->user_id != $item->created_by) {
                         $arr_noti_others = array('user_id' => $user->id, 'content' => "{$user->username} cũng đã bình luận bài viết của {$user_commented->username}", 'type' => 'comment_also', 'recipient_id' => $item->created_by, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti'))));
                         Notifications::model()->add($arr_noti_others);
                     }
                 }
             }
             $arr_noti = array('user_id' => $user->id, 'content' => "{$user->username} vừa bình luận bài viết của bạn", 'type' => 'comment', 'recipient_id' => $user_commented->id, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti'))));
             Notifications::model()->add($arr_noti);
         } else {
             $users_have_commented = $this->getListUserCommentedOnPost($post_id);
             if ($users_have_commented) {
                 foreach ($users_have_commented as $item) {
                     if ($user_id != $item->created_by) {
                         $arr_noti_others = array('user_id' => $user->id, 'content' => "{$user->username} cũng đã bình luận bài viết của họ", 'type' => 'comment_also', 'recipient_id' => $item->created_by, 'url' => Yii::app()->createAbsoluteUrl('post/viewPost', array('post_id' => $post_id, array('ref' => 'noti'))));
                         Notifications::model()->add($arr_noti_others);
                     }
                 }
             }
         }
     }
     if ($model->save(FALSE) && $post->save(FALSE)) {
         $returnArr = array();
         $returnArr['created_by'] = $model->created_by;
         $returnArr['username'] = $user->username;
         $returnArr['photo'] = StringHelper::generateUrlImage($user->photo);
         $returnArr['created_at'] = Util::time_elapsed_string($model->created_at);
         $returnArr['comment_content'] = $model->comment_content;
         return $returnArr;
     }
     return FALSE;
 }
 public function actionShare()
 {
     $user_id = Yii::app()->user->id;
     $res = false;
     if (Yii::app()->request->isAjaxRequest && !empty($user_id)) {
         $item_id = Yii::app()->getRequest()->getPost('item_id');
         $sharedEntry = Posts::model()->findByPk($item_id);
         $newEntry = new Posts();
         $newEntryHash = md5($sharedEntry->author_type . $sharedEntry->author_id . $user_id . $sharedEntry->creation_date);
         if ($sharedEntry->owner_id == $user_id || $sharedEntry->author_id == $user_id || $sharedEntry->status != 1) {
             // если запись уже есть на стене или если запись заблочена то не добавляем
             echo json_encode(array('status' => 'error', 'data' => 'Ошибка при копировании записи'));
             exit;
         }
         $newEntry->parent_id = $sharedEntry->id;
         // поле parent_id устанавливаем отличное от нуля (id расшариваемого поста)
         $newEntry->post_type = 'userwall';
         // Все основные поля копируем как есть
         $newEntry->author_type = $sharedEntry->author_type;
         $newEntry->owner_type = 'user';
         $newEntry->content = $sharedEntry->content;
         $newEntry->multimedia = $sharedEntry->multimedia;
         $newEntry->status = $sharedEntry->status;
         $newEntry->creation_date = time();
         $newEntry->author_id = $sharedEntry->author_id;
         $newEntry->owner_id = $user_id;
         $newEntry->hash = $newEntryHash;
         // сохраняем новую и старую записи
         $transaction = $sharedEntry->dbConnection->beginTransaction();
         try {
             $newEntry->save();
             $sharedEntry->shares = intval($sharedEntry->shares) + 1;
             // увеличиваем счетчик share у копируемой записи
             $sharedEntry->save();
             $transaction->commit();
             $res = true;
         } catch (Exception $e) {
             $transaction->rollback();
             $res = false;
         }
         if ($res == true) {
             echo json_encode(array('status' => 'ok', 'data' => 'shared'));
         } else {
             echo json_encode(array('status' => 'error', 'data' => 'Ошибка подключения к БД'));
         }
     } else {
         throw new CException('Not Found', 404);
     }
 }
Example #19
0
 public function recommend($rate_height, $rate_weight, $ref)
 {
     $criteria = new CDbCriteria();
     $criteria->conditon = "celeb_heigt_rate = {$rate_height} AND celeb_weight_rate = {$rate_weight}";
     $celebs = Celebrities::model()->findAll($criteria);
     if ($ref == 'api') {
         $count = Posts::model()->count($celebs);
         $pages = new CPagination($count);
         $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
         $pages->applyLimit($criteria);
     }
     $returnArr = array();
     foreach ($celebs as $celeb) {
         $post_id = Posts::model()->findByAttributes(array('celeb_id' => $celeb->id));
         $returnArr[] = Posts::model()->getPostById($post_id->post_id, Yii::app()->session['user_id']);
     }
     return array('data' => $returnArr, 'pages' => $pages);
 }
Example #20
0
 public function actionRankPostByTime()
 {
     $request = Yii::app()->request;
     try {
         $time = StringHelper::filterString($request->getQuery('time'));
         $ref_api = StringHelper::filterString($request->getQuery('ref_api'));
         $limit = StringHelper::filterString($request->getQuery('limit'));
         $offset = StringHelper::filterString($request->getQuery('offset'));
         if ($ref_api == Yii::app()->params['REF_API'] && !empty($limit) && !empty($offset)) {
             $data = Posts::model()->rankByTimeApi($time, $limit, $offset);
             ResponseHelper::JsonReturnSuccess($data, 'Success');
         } else {
             $data = Posts::model()->rankByTimeForWeb($time);
             $this->render('index', $data);
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #21
0
 public function getWishListForWeb($user_id)
 {
     $returnArr = array();
     $criteria = new CDbCriteria();
     $criteria->condition = "user_id = {$user_id}";
     $count = Posts::model()->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
     $pages->applyLimit($criteria);
     $posts = Wishlist::model()->findAll($criteria);
     if ($posts) {
         foreach ($posts as $post) {
             $itemArr = Posts::model()->getPostById($post->post_id);
             $returnArr[] = $itemArr;
         }
         return array('data' => $returnArr, 'pages' => $pages);
     }
     return FALSE;
 }
Example #22
0
 public function getPostOfAlbum($album_id)
 {
     $albums = PostAlbum::model()->findAllByAttributes(array('album_id' => $album_id));
     $post_arr = array();
     foreach ($albums as $album) {
         $post_arr[] = $album->post_id;
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('t.post_id', $post_arr);
     $count = Posts::model()->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
     $pages->applyLimit($criteria);
     $data = Posts::model()->findAll($criteria);
     $returnArr = array();
     foreach ($data as $item) {
         $returnArr[] = Posts::model()->getPostById($item->post_id, Yii::app()->session['user_id']);
     }
     $album = Albums::model()->findByPk($album_id);
     return array('data' => $returnArr, 'pages' => $pages, 'album' => $album);
 }
Example #23
0
 public function sendcomment($data)
 {
     $user = Yii::app()->db->createCommand('select a.title,a.portrait,a.nickName,b.name as companyName,c.name as location from user a left join company b on a.company=b.id left join hub c on a.location=c.id where a.status!=0 and a.id=' . $data['userId'])->queryRow();
     $comment = new Comment();
     $comment->postId = $data['postId'];
     $comment->userId = $data['userId'];
     $comment->content = $data['content'];
     $comment->createTime = $data['createTime'];
     $posterId = Posts::model()->findByAttributes(array('id' => $data['postId']))->userId;
     $userName = User::model()->findByAttributes(array('id' => $data['userId']))->nickName;
     $messageRe = MessageRelation::model()->findByAttributes(array('id1' => $posterId, 'id2' => 0));
     if ($messageRe) {
         $messageRe->utime = date('U');
     } else {
         $messageRe = new MessageRelation();
         $messageRe->id1 = $posterId;
         $messageRe->id2 = 0;
         $messageRe->utime = date('u');
     }
     if ($posterId != $data['userId']) {
         $message = new Message();
         $message->senderID = 0;
         $message->RecID = $posterId;
         $message->body = $userName . ' commented on your post.';
         $message->data = $data['postId'];
         $message->type = 1;
         $message->status = 0;
         $message->ctime = date('U');
         $message->commenterId = $data['userId'];
         $message->save();
         $messageRe->save();
     }
     $post = Posts::model()->findByAttributes(array('id' => $data['postId']));
     $post->comment_num++;
     if ($comment->save() && $post->save()) {
         return array('code' => 200, 'mes' => 'success', 'data' => array('newcomment' => Comment::model()->findByAttributes(array('createTime' => $data['createTime'])), 'user' => $user));
     }
 }
 public function actionAddImage()
 {
     $request = Yii::app()->request;
     try {
         $post_content = StringHelper::filterString($request->getPost('post_content'));
         $user_id = StringHelper::filterString($request->getPost('user_id'));
         $location = StringHelper::filterString($request->getPost('location'));
         $cats_arr = StringHelper::filterArrayString($request->getPost('cats'));
         $cats = json_encode($cats_arr);
         $url = Yii::app()->request->getUrlReferrer();
         //   $url_arr = NULL;
         $url_arr = UploadHelper::getUrlUploadMultiImages($_FILES['images'], $user_id);
         // $album = StringHelper::filterString($request->getPost('album'));
         $album = NULL;
         if (Posts::model()->addPost($user_id, $post_content, $location, $url_arr, $album, $cats)) {
             $this->redirect($url);
         } else {
             $this->redirect($url);
         }
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #25
0
 public function addComment($user_id, $post_id, $content)
 {
     $model = new Comments();
     $model->post_id = $post_id;
     $model->created_by = $user_id;
     $model->updated_at = time();
     $model->comment_content = $content;
     $model->status = 1;
     $model->created_at = time();
     $model->updated_at = time();
     $post = Posts::model()->findByPk($post_id);
     $post->post_comment_count++;
     $user = User::model()->findByPk($model->created_by);
     if ($model->save(FALSE) && $post->save(FALSE)) {
         $returnArr = array();
         $returnArr['created_by'] = $model->created_by;
         $returnArr['username'] = $user->username;
         $returnArr['photo'] = $user->photo;
         $returnArr['created_at'] = Util::time_elapsed_string($model->created_at);
         $returnArr['comment_content'] = $model->comment_content;
         return $returnArr;
     }
     return FALSE;
 }
Example #26
0
 public function recommend($rate_height, $rate_weight)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "t.celeb_height_rate = '" . $rate_height . "' AND t.celeb_weight_rate = '" . $rate_weight . "'";
     $celebs = Celebrities::model()->findAll($criteria);
     $celebs_arr = array();
     foreach ($celebs as $celeb) {
         $celebs_arr[] = $celeb->id;
     }
     //   var_dump($celebs_arr); die;
     $returnArr = array();
     $criteria_post = new CDbCriteria();
     $criteria_post->addInCondition('t.celeb_id', $celebs_arr);
     $count = Posts::model()->count($criteria_post);
     $pages = new CPagination($count);
     $pages->validateCurrentPage = FALSE;
     $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
     $pages->applyLimit($criteria_post);
     $posts = Posts::model()->findAll($criteria_post);
     foreach ($posts as $post) {
         $returnArr[] = Posts::model()->getPostById($post->post_id, Yii::app()->session['user_id']);
     }
     return array('data' => $returnArr, 'pages' => $pages);
 }
Example #27
0
 /**
  * 验证用户具体发帖权限,并不影响其他权限
  * @param type $uid 验证的用户
  * @param type $type 验证的类型
  * @param type $field 是否检查总数
  * @return type
  */
 public static function check($type, $field = false, $uid = '')
 {
     if (!$uid) {
         $uid = Yii::app()->user->id;
     }
     if (!$uid) {
         if (zmf::config('officalUid')) {
             return array('status' => 1, 'msg' => '');
         }
         return array('status' => 0, 'msg' => '用户不存在');
     }
     $uinfo = Users::getUserInfo($uid);
     if (!$uinfo) {
         return array('status' => 0, 'msg' => '用户不存在');
     }
     if (!$uinfo['groupid']) {
         return array('status' => 0, 'msg' => '无组织用户');
     }
     $groupInfo = UserPower::model()->find('groupid=:gid', array(':gid' => $uinfo['groupid']));
     if (!$groupInfo) {
         return array('status' => 0, 'msg' => '无组织用户');
     }
     $num = $groupInfo->getAttribute($type);
     if ($num === null) {
         return array('status' => 0, 'msg' => '无法完成验证的type:' . $type);
     } elseif ($num === 0) {
         return array('status' => 0, 'msg' => '不允许');
     } elseif ($field) {
         switch ($field) {
             case 'addPost':
                 $totalNum = $groupInfo['postNum'];
                 $hasNum = Posts::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addQuestion':
                 $totalNum = $groupInfo['questionNum'];
                 $hasNum = Question::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addAnswer':
                 $totalNum = $groupInfo['answerNum'];
                 $hasNum = Answer::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addPoiPost':
                 $totalNum = $groupInfo['poiPostNum'];
                 $hasNum = PoiPost::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addPoiTips':
                 $totalNum = $groupInfo['poiTipsNum'];
                 $hasNum = PoiTips::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addImage':
                 $totalNum = $groupInfo['imageNum'];
                 $hasNum = Attachments::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addComment':
                 $totalNum = $groupInfo['commentNum'];
                 $hasNum = Comments::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'addPlan':
                 $totalNum = $groupInfo['planNum'];
                 $hasNum = Plans::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
             case 'yueban':
                 $totalNum = $groupInfo['yuebanNum'];
                 $hasNum = Posts::model()->count('uid=:uid AND cTime>=:cTime', array(':uid' => $uid, ':cTime' => $ctime));
                 break;
         }
         if (!$totalNum) {
             return array('status' => 1, 'msg' => '无限制');
         } else {
             if ($hasNum >= $totalNum) {
                 return array('status' => 0, 'msg' => '已超出限制:' . $totalNum);
             } else {
                 return array('status' => 1, 'msg' => '');
             }
         }
     } else {
         return array('status' => 1, 'msg' => '');
     }
 }
Example #28
0
 /**
  * MANY MANY relation ship
  * all you have to do is create another HAS MANY relationship in the other
  * model. For example. If you had posts and tags where a post can have many
  * tags and each tag can have many posts. You would define the two following
  * methods
  *
  * This setup is also assuming you have a separate Model for handling tags
  * that lists the mongo object _id's that belongs to it. And in each post you
  * have a list of tag names that this post has.
  * @return
  */
 public function tags()
 {
     return Posts::model()->findAllByAttributes(array('post_id' => $this->post_id));
 }
Example #29
0
<!-- 17:50, 15 октября 2012 -->
			<?php 
    if ($item->author_id == Yii::app()->user->id || $item->owner_id == Yii::app()->user->id) {
        ?>
				<span class="control" onclick="deleteWallPost(this, '<?php 
        echo Yii::app()->request->baseUrl;
        ?>
/posts/delete/', <?php 
        echo $item->id;
        ?>
)">Удалить</span>
			<?php 
    }
    ?>
			<?php 
    $o_post = Posts::model()->findByPk($item->parent_id);
    if ($o_post != null) {
        $o_author = UserProfile::model()->getUserProfile($o_post->author_id);
        $textPadding = 'style="padding-left: 12px"';
        ?>
			<div>
				<img style="margin-top: 4px;" src="<?php 
        echo Yii::app()->request->baseUrl;
        ?>
/static/css/publishedBy.gif" alt="" title="Автор оригинала" /> <a href="<?php 
        echo Yii::app()->request->baseUrl;
        ?>
/id<?php 
        echo $o_author->user_id;
        ?>
"><img width="32" style="margin-top: 4px;" src="<?php 
 public function actionDelete()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $id = Yii::app()->getRequest()->getPost('item_id');
         $post = Posts::model()->findByPk($id);
         if ($post->author_id == Yii::app()->user->id || $post->owner_id == Yii::app()->user->id) {
             // удаляем только если автор поста == текущему авторизованному пользователю, либо если хозяин стены == текущему авторизованному пользователю
             // Удаление поста и его комментариев (в mysql триггере)
             $transaction = $post->dbConnection->beginTransaction();
             try {
                 if ($post->parent_id > 0) {
                     // если удаляем расшаренную копию, то декрементим количество расшариваний у оригинала
                     $originalPost = Posts::model()->findByPk($post->parent_id);
                     $originalPost->shares = $originalPost->shares - 1;
                     $originalPost->save();
                 }
                 $post->delete();
                 $transaction->commit();
                 $res = true;
             } catch (Exception $e) {
                 $transaction->rollback();
                 $res = false;
             }
             if ($res) {
                 echo json_encode(array('status' => 'ok'));
             } else {
                 echo json_encode(array('status' => 'error', 'data' => 'Не могу подключиться к БД'));
             }
         } else {
             throw new CException('Not Found', 404);
         }
     } else {
         throw new CException('Not Found', 404);
     }
 }