예제 #1
0
 public function update($id, UpdatePostRequest $request)
 {
     $post = Post::find($id);
     $post->post = $request->get('post');
     $post->save();
     return redirect()->route('posts.show', $post->id)->with('successes', ['Post updated successfully']);
 }
 public function postsAndGrants()
 {
     $id = $this->request->query['id'];
     // First find all posts for group
     $posts = Post::find('all', array('conditions' => array('groupId' => new \MongoId($id)), 'limit' => 10))->to('array');
     $ids = array();
     $total = 0;
     foreach ($posts as &$p) {
         $total += $p['y2011'];
         /*
                     $post = $p['post'];
                     $ids[] = $post;
         */
     }
     /*
             $grants = Grant::find('all', array(
        'conditions' => array(
            'post' => array(
                '$in' => $ids
            )
        ),
        'limit' => 100
             ))->to('array');
     */
     return compact('total', 'posts');
 }
예제 #3
0
 public static function __init(array $options = array())
 {
     parent::__init($options);
     $self = static::_instance();
     $self->_finders['count'] = function ($self, $params, $chain) use(&$query, &$classes) {
         $db = Connections::get($self::meta('connection'));
         $records = $db->read('SELECT count(*) as count FROM posts', array('return' => 'array'));
         return $records[0]['count'];
     };
     Post::applyFilter('save', function ($self, $params, $chain) {
         $post = $params['record'];
         if (!$post->id) {
             $post->created = date('Y-m-d H:i:s');
         } else {
             $post->modified = date('Y-m-d H:i:s');
         }
         $params['record'] = $post;
         return $chain->next($self, $params, $chain);
     });
     Validator::add('isUniqueTitle', function ($value, $format, $options) {
         $conditions = array('title' => $value);
         // If editing the post, skip the current psot
         if (isset($options['values']['id'])) {
             $conditions[] = 'id != ' . $options['values']['id'];
         }
         // Lookup for posts with same title
         return !Post::find('first', array('conditions' => $conditions));
     });
 }
예제 #4
0
 public function actionIndex()
 {
     $query = Post::find();
     $pagination = new Pagination(['defaultPageSize' => 6, 'totalCount' => $query->count()]);
     $posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['posts' => $posts, 'pagination' => $pagination]);
 }
예제 #5
0
 function love(array $params)
 {
     $response = new ResponseEntity();
     DB::transaction(function () use(&$response, $params) {
         if ($params['postId']) {
             $ep = Post::find($params['postId']);
             if (!$ep) {
                 $response->setMessages(['Post is not available']);
             } else {
                 $p = new PostLove();
                 $p->post_id = $params['postId'];
                 $p->user_id = Auth::user()->id;
                 $ok = $p->save();
                 if ($ok) {
                     $response->setSuccess(true);
                 } else {
                     $response->setMessages(['Something went wrong!']);
                 }
             }
         } else {
             $response->setMessages(['Post is not available']);
         }
     });
     return $response;
 }
예제 #6
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $request = Yii::$app->request;
     $page_id = $request->get('page_id');
     $search = $request->get('search');
     $columns = Page::find()->where(['type' => 3])->all();
     if ($search) {
         $query = Post::find()->where(['like', 'name', $search])->orWhere(['like', 'content', $search]);
         $countQuery = clone $query;
         $pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
         $post = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all();
         return $this->render('index', ['page_id' => $page_id, 'pnation' => $pnation, 'post' => $post, 'columns' => $columns]);
     }
     if ($page_id) {
         $query = Post::find()->where(['page_id' => $page_id]);
         $countQuery = clone $query;
         $pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
         $post = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all();
     } else {
         $query = Post::find();
         $countQuery = clone $query;
         $pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
         $post = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all();
     }
     return $this->render('index', ['page_id' => $page_id, 'pnation' => $pnation, 'post' => $post, 'columns' => $columns]);
 }
 /**
  * @param ATOM|RSS2 $feed
  * @return ATOM|RSS2
  */
 protected function generateFeed($feed)
 {
     /* @var Post[] $posts */
     $site_name = ArrayHelper::getValue(Yii::$app->params, 'site_name', Yii::$app->name);
     $posts = Post::find()->where(['status' => Post::STATUS_PUBLISHED])->orderBy(['post_time' => SORT_DESC, 'update_time' => SORT_DESC])->limit(20)->all();
     $feed->setTitle($site_name);
     $feed->setLink(Url::home(true));
     $feed->setSelfLink(Url::to(['feed/rss'], true));
     $feed->setAtomLink(Url::to(['feed/atom'], true));
     $feed->setDescription(ArrayHelper::getValue(Yii::$app->params, 'seo_description', '最新更新的文章'));
     if ($posts) {
         $feed->setDate($posts[0]->update_time);
     } else {
         $feed->setDate(time());
     }
     foreach ($posts as $post) {
         $entry = $feed->createNewItem();
         $entry->setTitle($post->title);
         $entry->setLink($post->getUrl(true));
         $entry->setDate(intval($post->post_time));
         $entry->setDescription($post->excerpt);
         $entry->setAuthor($post->author_name ? $post->author_name : $post->author->nickname);
         $entry->setId($post->alias);
         if ($feed instanceof ATOM) {
             $entry->setContent($post->content);
         }
         $feed->addItem($entry);
     }
     return $feed;
 }
예제 #8
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = Post::find();
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $dataProvider->count()]);
     $posts = $dataProvider->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['posts' => $posts, 'pagination' => $pagination, 'category' => Category::find()->all(), 'comment_list' => Comment::find()->all()]);
 }
 public function run()
 {
     $post = Post::find(1);
     $post->categories()->attach([13]);
     $post = Post::find(2);
     $post->categories()->attach([15]);
     $post = Post::find(3);
     $post->categories()->attach([22]);
     $post = Post::find(4);
     $post->categories()->attach([5, 24]);
     $post = Post::find(5);
     $post->categories()->attach([4, 12]);
     $post = Post::find(6);
     $post->categories()->attach([10]);
     $post = Post::find(7);
     $post->categories()->attach([4, 12]);
     $post = Post::find(8);
     $post->categories()->attach([18]);
     $post = Post::find(9);
     $post->categories()->attach([3, 4, 12]);
     $post = Post::find(10);
     $post->categories()->attach([5]);
     $post = Post::find(11);
     $post->categories()->attach([5]);
     $post = Post::find(12);
     $post->categories()->attach([18]);
 }
예제 #10
0
 function destroy($id)
 {
     $post = \App\Models\Post::find($id);
     unlink(public_path($post->imagens));
     unlink(public_path($post->imagenl));
     $post->delete();
     return redirect('posts');
 }
예제 #11
0
 public function story(Request $request, $id)
 {
     $post = Post::find($id);
     if (!$post) {
         return redirect('/');
     }
     return view('posts.view', array('post' => $post));
 }
 public function view(Request $request, $id = '')
 {
     $model = \App\Models\Post::find($id);
     if (!is_null($model)) {
         return view('post.view', ['model' => $model]);
     }
     return response()->view('errors.404', array(), 404);
 }
예제 #13
0
 /**
  * [postdetail description]
  * @param  [type] $post_id [description]
  * @return [type]          [description]
  */
 public function postdetail($post_id)
 {
     $post = Post::find($post_id);
     $post->category = Category::find($post->category_id);
     $randomposts = Post::getRandomPost();
     $postfeatures = Post::getPostFeaturedWidget();
     $commentposts = Comment::getCommentByPostId($post_id);
     return view('home.detailpost', compact('post', 'randomposts', 'postfeatures', 'commentposts'));
 }
예제 #14
0
 public static function sendPost($id, $ticket_updated, $request)
 {
     $post = Post::find($id);
     $emails = array();
     if ($request) {
         foreach ($request as $key => $target) {
             switch ($key) {
                 case 'account_manager':
                     if ($target == 'true') {
                         $emails[] = $post->ticket->company->account_manager->company_person->email;
                     }
                     break;
                 case 'company_group_email':
                     if ($target == 'true') {
                         $emails[] = $post->ticket->company->group_email;
                     }
                     break;
                 case 'company_contact':
                     if ($target == 'true') {
                         $emails[] = $post->ticket->contact->email;
                     }
                     break;
                 case 'ticket_emails':
                     if ($target == 'true') {
                         $emails = array_merge($emails, explode(",", $post->ticket->emails));
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     $emails[] = $post->ticket->assignee->email;
     foreach ($emails as $email) {
         self::add('to', $email);
     }
     switch ($post->ticket->division->id) {
         case LGV_DIVISION_ID:
             self::add("cc", self::LGV_TEAM_LEADER_EMAIL);
             break;
         case PC_DIVISION_ID:
             self::add("cc", self::PC_TEAM_LEADER_EMAIL);
             break;
         case PLC_DIVISION_ID:
             self::add("cc", self::PLC_TEAM_LEADER_EMAIL);
             break;
         default:
             break;
     }
     self::setSubject("New Post | Ticket #" . $post->ticket->id . " | " . $post->author->person->name());
     self::$view = "emails/post";
     self::$data['post'] = $post;
     self::$data['title'] = "New Post for Ticket #" . $post->ticket->id;
     self::$data['ticket_updated'] = $ticket_updated;
     self::send();
     Activity::log("Email Post Send", self::$data);
 }
예제 #15
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $post = Post::find($id);
     if (!$post) {
         return $this->respondNotFound('Post Not Found');
     }
     $data = fractal()->item($post)->transformWith(new PostTransformer())->includeUser()->includeCategories()->toArray();
     return $this->respond($data);
 }
예제 #16
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = Post::find();
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     $dataProvider = new ActiveDataProvider(['query' => Post::find()->orderBy('id DESC')]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'models' => $models, 'pages' => $pages]);
 }
예제 #17
0
 public function actionIndex()
 {
     $pageSize = 10;
     $pages = new Pagination(['totalCount' => Post::find()->where('status=1')->count(), 'pageSize' => $pageSize]);
     $posts = Post::find()->where('status=1')->orderBy(['published_at' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->all();
     $recommend = Post::find()->where('status=1 AND type=3')->orderBy(['published_at' => SORT_DESC])->limit(2)->all();
     $headline = Post::find()->where('status=1 AND type=2')->orderBy(['published_at' => SORT_DESC])->one();
     return $this->render('index', ['posts' => $posts, 'pages' => $pages, 'recommend' => $recommend, 'headline' => $headline]);
 }
예제 #18
0
파일: Post.php 프로젝트: phucnv206/pharma
 public static function listPostsUrl()
 {
     $model = Post::find()->asArray()->all();
     $result = [];
     foreach ($model as $item) {
         $url = Url::to(['post/view', 'id' => $item['id'], 'slug' => $item['slug']]);
         $result[$url] = $item['title'];
     }
     return $result;
 }
 /**
  * @todo 归档的细化操作
  * @param $year
  * @param $month
  */
 public function actionArchivesDate($year, $month)
 {
     $this->layout = 'column-list';
     $date = "{$year}-{$month}";
     $start = strtotime($date);
     $end = strtotime('+1 month', $start);
     $dataProvider = new ActiveDataProvider(['query' => Post::find()->where(['between', 'post_time', $start, $end]), 'pagination' => ['pageSize' => 10]]);
     $this->view->title = '文章归档:' . $date;
     echo $this->render('archives-date', ['date' => $date, 'dataProvider' => $dataProvider]);
 }
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     if (empty(Yii::$app->request->getQueryParam('PostSearch'))) {
         $dataProvider = new ActiveDataProvider(['query' => Post::find()]);
     } else {
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     }
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
 }
예제 #21
0
 /**
  * Lists all Post models with CRUD actions
  *
  * @return mixed
  */
 public function actionIndex()
 {
     try {
         Yii::trace('Trace : ' . __METHOD__, __METHOD__);
         $dataProvider = new ActiveDataProvider(['query' => Post::find(), 'pagination' => ['pageSize' => Yii::$app->params['pagination']]]);
         return $this->render('index', ['dataProvider' => $dataProvider]);
     } catch (Exception $e) {
         Yii::error($e->getMessage(), __METHOD__);
         throw $e;
     }
 }
예제 #22
0
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'cid' => $this->cid, 'type' => $this->type, 'status' => $this->status, 'author_id' => $this->author_id, 'create_time' => $this->create_time, 'post_time' => $this->post_time, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'author_name', $this->author_name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'tags', $this->tags]);
     return $dataProvider;
 }
예제 #23
0
 public function actionRead($id = NULL)
 {
     if ($id === NULL) {
         throw new HttpException(404, 'Not Found');
     }
     $post = Post::find($id);
     if ($post === NULL) {
         throw new HttpException(404, 'Document Does Not Exist');
     }
     echo $this->render('read', array('post' => $post));
 }
예제 #24
0
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'published_at' => $this->published_at, 'views' => $this->views, 'likes' => $this->likes, 'comment_count' => $this->comment_count, 'disallow_comment' => $this->disallow_comment, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'thumbnail', $this->thumbnail])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'writer', $this->writer])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords])->andFilterWhere(['like', 'seo_description', $this->seo_description]);
     return $dataProvider;
 }
 /**
  * 通过nickname获取用户信息
  * @param $name
  * @throws NotFoundHttpException
  */
 public function actionViewUser($name)
 {
     /* @var User $model */
     $model = User::findOne(['nickname' => $name]);
     if ($model == null) {
         throw new NotFoundHttpException('未找到相关用户的资料。');
     }
     $dataProvider = new ActiveDataProvider(['query' => Post::find()->where(['status' => [Post::STATUS_HIDDEN, Post::STATUS_PUBLISHED], 'author_id' => $model->id])->orderBy(['is_top' => SORT_DESC, 'post_time' => SORT_DESC]), 'pagination' => ['pageSize' => 10]]);
     $this->view->params['seo_description'] = "{$model->nickname}在「" . ArrayHelper::getValue(Yii::$app->params, 'site_name') . "」共发表{$dataProvider->totalCount}篇文章,个人资料:{$model->info}。";
     $this->view->params['seo_keywords'] = "{$model->nickname}," . ArrayHelper::getValue(Yii::$app->params, 'seo_keywords');
     $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider]);
 }
예제 #26
0
 public function view(Request $request, $id = '')
 {
     $model = \App\Models\Post::find($id);
     if (!is_null($model)) {
         //$comments = \App\Models\Comment::where('post_id', $id)->get();
         $comment = new \App\Models\Comment();
         $tree = $comment->getTree($id);
         //echo "<pre>"; print_r($tree); exit;
         return view('post.view', ['model' => $model, 'comments' => $tree]);
     }
     return response()->view('errors.404', array(), 404);
 }
예제 #27
0
 public static function getById($id)
 {
     if (empty($id)) {
         return false;
     }
     try {
         return Post::find($id);
     } catch (Exception $e) {
         Log::info('Post:getById(): ' . $e->getMessage());
         return false;
     }
 }
예제 #28
0
 protected function findModel($id, $withComments = false)
 {
     $related = ['user0'];
     if ($withComments) {
         $related[] = 'comments.user0';
     }
     $model = Post::find()->with($related)->where(['id' => $id])->one();
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрошенная статья не найдена.');
     }
 }
 /**
  * Action that displays posts list
  * @return string
  */
 public function actionIndex()
 {
     $languageId = Yii::$app->multilingual->language_id;
     $posts = Post::find()->orderBy(['created_at' => SORT_DESC]);
     $count = Yii::$app->cache->lazy(function () use($posts) {
         return $posts->count();
     }, "PostsCount:{$languageId}", 86400, Post::commonTag());
     $pagination = new Pagination(['totalCount' => $count]);
     $posts = Yii::$app->cache->lazy(function () use($posts, $pagination) {
         return $posts->offset($pagination->offset)->limit($pagination->limit)->all();
     }, "Posts:{$pagination->offset}:{$pagination->limit}:{$languageId}", 86400, Post::commonTag());
     return $this->render('index', ['posts' => $posts, 'pagination' => $pagination]);
 }
예제 #30
0
 public function comment(Request $request)
 {
     $post = Post::find($request->get('post'));
     if (!$post || empty($request->get('comment'))) {
         return new JsonResponse(array('message' => 'Unable to add comment'), 500);
     }
     $comment = new Comment();
     $comment->author = Auth::user()->email;
     $comment->description = $request->get('comment');
     $comment->is_active = 0;
     $post->comments()->save($comment);
     return new JsonResponse(array('message' => 'Comment successfully added. It will appear once approved'), 200);
 }