상속: extends Illuminate\Database\Eloquent\Model
예제 #1
0
 public function Search($word)
 {
     $post_obj = new Post();
     $word = urldecode($word);
     $post = $post_obj->GetListPost($word);
     return view('mei.search')->with('posts', $post);
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Post $postModel, Request $request)
 {
     //dd($request->all());
     //$request=$request->except('_token');
     $postModel->create($request->all());
     return redirect()->route('posts');
 }
 /**
  * Fetches one post based on column value condition and status
  * @param string $column
  * @param $value
  * @param int $status
  * @return Post
  */
 public function getOneBy($column, $value, $status = Post::POST_PUBLISHED)
 {
     if ($status === null) {
         $status = Post::POST_PUBLISHED;
     }
     return $this->postModel->ofStatus($status)->where($column, $value)->take(1);
 }
예제 #4
0
 /**
  * new-Action (Formularauswertung)
  */
 public function postNew()
 {
     //$validator = Validator::make(Request::all(), Post::$rules);
     //if (/*$validator->passes()*/)
     //{
     // validation has passed, save user in DB
     $post = new Post();
     $post->title = " ";
     $post->content = Request::input('content');
     $user = Auth::user();
     $post->link = '';
     $post->user_id = $user->id;
     $post->event_id = Request::input('event_id');
     $post->save();
     $response = new \stdClass();
     $response->success = true;
     $response->total = 1;
     $response->data = $post;
     return response()->json($response);
     //}
     /*else
     		{
     			// validation has failed, display error messages
     			$response = new \stdClass;
     			$response->success = false;
     			$response->total = 1;
     			return  response()->json($response);
     		}*/
 }
 public function addReview(Request $request, Post $post)
 {
     $review = new Review();
     $review->post_id = $post->id;
     $review->body = $request->post_body;
     $post->reviews()->save($review);
     return back();
 }
예제 #6
0
 /**
  * 返回所有文章
  */
 function GetAllPost(Request $request)
 {
     DB::connection()->enableQueryLog();
     $postSrv = new Post();
     $res = $postSrv->GetAllPost($request->all());
     $res['success'] = $res['data'] ? true : false;
     $res['sql'] = DB::getQueryLog();
     return json_encode($res, JSON_UNESCAPED_UNICODE);
 }
예제 #7
0
 public function getNew()
 {
     $post = new Post();
     $post->user_id = 1;
     $post->title = md5(time() * rand());
     $post->content = md5(time() * rand());
     $post->link = '';
     $post->save();
 }
예제 #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $post = new \App\Models\Post();
     $json = json_decode(\Request::input('json'));
     $receiver = \Request::input('receiver');
     $post->text = \Request::input('text');
     $post->sender_id = Auth::user()->id;
     $post->receiver_id = User::where('name', '=', $receiver)->first()->id;
     $post->save();
     return \Redirect::to('/post/');
 }
예제 #9
0
 /**
  * Create a new post with a text message
  *
  * @param  \App\Models\Provider  $provider
  * @param  string  $message
  * @return \App\Models\Post
  */
 public function createMessage($provider, $message)
 {
     $post = new Post();
     $post->service = $provider->service;
     $post->message = $message;
     $post->user_id = $provider->user_id;
     $post->provider_id = $provider->id;
     $post->scheduled_at = time();
     $post->save();
     return $post;
 }
 /**
  * Seeds the table.
  *
  * @return void
  */
 public function run()
 {
     $post = new Post();
     $post->title = 'JSON API paints my bikeshed!';
     $post->body = 'If you\'ve ever argued with your team about the way your JSON responses should be ' . 'formatted, JSON API is your anti-bikeshedding weapon.';
     /** @var Site $site */
     $site = Site::firstOrFail();
     /** @var Author $author */
     $author = Author::firstOrFail();
     $post->site_id = $site->id;
     $post->author_id = $author->id;
     $post->save();
 }
예제 #11
0
 public function actionCreate()
 {
     $data = $_POST['data'];
     $time = time();
     $data['create_at'] = $time;
     $data['user_id'] = User::getCurrentId();
     $comment = new Comment();
     $comment->attributes = $data;
     $post = new Post();
     $post->updateAll(['reply_at' => $time, 'last_reply_id' => $data['user_id']], 'id=:id', [':id' => $data['post_id']]);
     $comment->save();
     $this->redirect(array('/post/view', 'id' => $data['post_id']));
 }
예제 #12
0
 /**
  * Create or update a post.
  *
  * @param  App\Models\Post $post
  * @param  array  $inputs
  * @param  bool   $user_id
  * @return App\Models\Post
  */
 private function savePost($post, $inputs, $user_id = null)
 {
     $post->title = $inputs['title'];
     $post->summary = $inputs['summary'];
     $post->content = $inputs['content'];
     $post->slug = $inputs['slug'];
     $post->active = isset($inputs['active']);
     if ($user_id) {
         $post->user_id = $user_id;
     }
     $post->save();
     return $post;
 }
예제 #13
0
 public function store(Request $request)
 {
     $input = $request->all();
     $validator = Validator::make($input, Post::getCreateRules());
     if ($validator->passes()) {
         $post = new Post();
         $post->user_id = $request->user_id;
         $post->text = $request->text;
         $post->save();
         return $this->response->array($post);
     } else {
         throw new \Dingo\Api\Exception\StoreResourceFailedException('Could not create new user.', $validator->errors());
     }
 }
예제 #14
0
 /**
  * @inheritdoc
  */
 public function getRelationships($comment, array $includeRelationships = [])
 {
     /** @var Comment $comment */
     // that's an example how $includeRelationships could be used for reducing requests to database
     if (isset($includeRelationships['post']) === true) {
         // as post will be included as full resource we have to give full resource
         $post = $comment->post;
     } else {
         // as post will be included as just id and type so it's not necessary to load it from database
         $post = new Post();
         $post->setAttribute($post->getKeyName(), $comment->post_id);
     }
     return ['post' => [self::DATA => $post]];
 }
예제 #15
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;
 }
예제 #16
0
 /**
  * @param $id
  * @param $id_acc
  * @param $title
  * @param $post
  * @param int $category
  */
 public static function edit($id, $id_acc, $title, $post, $category = 2)
 {
     $cleanPost = \Post::sensor($post, false);
     $sql = sprintf("UPDATE `iniforum`.`posts`\n            SET `post` = :post, `title` = :title, `id_category` = :category, `modified_at`=now()\n            WHERE `posts`.`id` = :id AND `posts`.`id_account` = :id_acc");
     $bindArray = [':id' => $id, ':id_acc' => $id_acc, ':title' => $title, ':post' => $cleanPost, ':category' => $category];
     self::query($sql, $bindArray);
 }
 /**
  * Store a newly created post in storage.
  *
  * @param CreatepostRequest $request
  *
  * @return Response
  */
 public function store(CreatePostRequest $request)
 {
     $input = Request::all();
     if (!empty($input['imagen'])) {
         $this->carpeta = 'posts/' . $input['id_usuario'] . '/';
         if (!File::exists($this->carpeta)) {
             //Crear carpeta de archivos adjuntos
             File::makeDirectory($this->carpeta);
         }
         $filename = 'posts/' . $input['id_usuario'] . '/' . $input['titulo'] . date("GisdY") . '.jpg';
         $input['imagen'] = $filename;
         Image::make(Input::file('imagen'))->resize(480, 360)->save($filename);
     }
     if (!empty($input['archivo'])) {
         $this->carpeta = 'posts/' . $input['id_usuario'] . '/';
         if (!File::exists($this->carpeta)) {
             //Crear carpeta de archivos adjuntos
             File::makeDirectory($this->carpeta);
         }
         $destinationPath = 'posts/' . $input['id_usuario'] . '/';
         // upload path
         $nombre = Input::file('archivo')->getClientOriginalName();
         // getting image extension
         Input::file('archivo')->move($destinationPath, $nombre);
         $input['archivo'] = $destinationPath . $nombre;
     }
     $post = Post::create($input);
     return redirect('home');
 }
예제 #18
0
 /**
  * TODO: In future models will have more relations which might not delete automatically. It should be tested properly
  * TODO: Files should be deleted too
  * Deletes all boards, threads and posts with 'is_deleted = 1', handles relation between them.
  * @return array with deleted rows
  */
 public static function clean()
 {
     $itemsToDelete = ['boardsIds' => [], 'threadsIds' => [], 'postsIds' => [], 'postDataIds' => [], 'postMessageIds' => []];
     Post::getDeletedRows($itemsToDelete);
     Thread::getDeletedRows($itemsToDelete);
     Board::getDeletedRows($itemsToDelete);
     self::getPostDataIds($itemsToDelete);
     self::getPostMessageIds($itemsToDelete);
     /**
      * Deletes post_message's related to threads and posts
      */
     $deleted['post_messages'] = PostMessage::deleteAll(['in', 'id', array_unique($itemsToDelete['postMessageIds'])]);
     /**
      * Deletes threads and posts because of FK
      */
     $deleted['threads'] = Thread::deleteAll(['in', 'id', array_unique($itemsToDelete['threadsIds'])]);
     /**
      * Deleted posts and threads related to post_data
      */
     $deleted['post_data'] = PostData::deleteAll(['in', 'id', array_unique($itemsToDelete['postDataIds'])]);
     /**
      * Deleted boards
      */
     $deleted['boards'] = Board::deleteAll(['in', 'id', array_unique($itemsToDelete['boardsIds'])]);
     $deleted['posts'] = $deleted['post_data'] - $deleted['threads'];
     $deleted['total'] = $deleted['boards'] + $deleted['threads'] + $deleted['posts'] + $deleted['post_data'] + $deleted['post_messages'];
     return $deleted;
 }
예제 #19
0
 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['title' => 'First Post', 'author' => 'Евгений', 'excerpt' => 'First Post body', 'text' => 'Content First Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Second Post', 'author' => 'Евгений', 'excerpt' => 'Second Post body', 'text' => 'Content Second Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Third Post', 'author' => 'Евгений', 'excerpt' => 'Third Post body', 'text' => 'Content Third Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
 }
예제 #20
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));
     });
 }
 /**
  * @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;
 }
예제 #22
0
 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['name' => 'First Name', 'email' => '*****@*****.**', 'city' => 1, 'content' => 'First Feedbuck 24', 'slag' => 'first-feed', 'published' => true, 'created_at' => time(), 'mood' => '1']);
     Post::create(['name' => 'Second Name', 'email' => '*****@*****.**', 'city' => 2, 'content' => 'Second Feedbuck 24', 'slag' => 'second-feed', 'published' => true, 'created_at' => time(), 'mood' => '2']);
     Post::create(['name' => 'Third Name', 'email' => '*****@*****.**', 'city' => 3, 'content' => 'Third Feedbuck 24sdsds', 'slag' => 'third-feed', 'published' => true, 'created_at' => time(), 'mood' => '1']);
 }
예제 #23
0
 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['title' => 'First Post', 'slug' => 'first-post', 'excerpt' => 'First Post body', 'content' => 'Content First Post body', 'published' => true, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Second Post', 'slug' => 'second-post', 'excerpt' => 'Second Post body', 'content' => 'Content Second Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Third Post', 'slug' => 'third-post', 'excerpt' => 'Third Post body', 'content' => 'Content Third Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
 }
예제 #24
0
 public function actionNew()
 {
     $postModel = new Post();
     $category = new Category();
     $categoryList = ArrayHelper::map($category->find()->asArray()->all(), 'id', 'title');
     $postList = $postModel->find()->asArray()->all();
     $message = '';
     if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) {
         $selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all();
         foreach ($selectedCategories as $category) {
             $postModel->link('categories', $category);
         }
         $message = 'Category added success';
     }
     return $this->render('new', ['model' => $postModel, 'message' => $message, 'categoryList' => $categoryList, 'postList' => $postList]);
 }
예제 #25
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id = null)
 {
     //$posts = Post::all();
     $posts = Post::latest('id')->paginate(2);
     //$posts = DB::table('posts')->paginate(2);
     return view('post.list', array('posts' => $posts));
 }
예제 #26
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]);
 }
예제 #27
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');
 }
예제 #29
0
 public function upload()
 {
     $uploader_id = Auth::user()->active_contact->id;
     if (Input::file('file')->isValid()) {
         if (Input::get('target') == "posts") {
             if (Input::get('target_action') == "create") {
                 $target = Post::where('author_id', $uploader_id)->where("status_id", "=", POST_DRAFT_STATUS_ID)->where("ticket_id", Input::get('target_id'))->first();
             } elseif (Input::get('target_action') == "edit") {
                 $target = Post::where("id", Input::get('target_id'))->first();
             }
         } elseif (Input::get('target') == "tickets") {
             if (Input::get('target_action') == "create") {
                 $target = Ticket::where('status_id', TICKET_DRAFT_STATUS_ID)->where('creator_id', $uploader_id)->first();
             } elseif (Input::get('target_action') == "edit") {
                 $target = Ticket::where("id", Input::get('target_id'))->first();
             }
         }
         $id = $target->id;
         $request['target_id'] = $id;
         $request['uploader_id'] = $uploader_id;
         $request['file'] = Input::file('file');
         $request['target'] = Input::get('target');
         $request['target_action'] = Input::get('target_action');
         $response = $this->repo->upload($request);
         $response = Response::json($response, 200);
         return $response;
     }
 }
 /**
  * @param $sender
  * @param $receiver
  * @param $object
  */
 private static function createNewNotification($sender, $event)
 {
     $noti = new Notification();
     $noti["sender_id"] = $sender;
     $noti["is_read"] = 0;
     $noti["objectType"] = POST;
     if ($event instanceof FollowEvent) {
         $noti["type"] = FOLLOW;
         $noti["receiver_id"] = $event["following_id"];
         if ($event["follow_type"] == 2) {
             $noti["objectType"] = BOARD;
         } else {
             $noti["objectType"] = USER;
         }
     } else {
         $post = Post::getPostById($event["post_id"]);
         $noti["receiver_id"] = $post["user_id"];
         if ($event instanceof LikeEvent) {
             $noti["type"] = LIKE;
             $noti["objectID"] = $event["post_id"];
         } else {
             if ($event instanceof CommentEvent) {
                 $noti["type"] = COMMENT;
                 $noti["objectID"] = $event["post_id"];
             } else {
                 if ($event instanceof PinEvent) {
                     $noti["type"] = PIN;
                     $noti["objectID"] = $event["post_id"];
                 }
             }
         }
     }
     return $noti;
 }