public function actionIndex() { $mainSlider = Slider::find()->all(); $gallery = Gallery::find()->all(); $blog = Blog::find()->limit(2)->all(); return $this->render('index', ['mainSlider' => $mainSlider, 'gallery' => $gallery, 'blog' => $blog]); }
public static function getComments($user_id, $type, $limit, $contentId, $contentType) { if ($contentId) { $date = (new Query())->select('date_time')->from('comments_' . $contentType)->where(['id' => $contentId])->scalar(); } if ($type == 'user') { $articles_id = false; $photos_id = false; $club_photos_id = false; } else { $articles_id = Blog::getAllArticlesIdByAuthor($user_id); $photos_id = Photo::getAllPhotosIdByAuthor($user_id); $club_photos_id = ClubPhoto::getAllClubPhotosIdByAuthor($user_id); } $comment_blog_query = CommentsBlog::getCommentsQuery($user_id, $type, $articles_id); $comment_photo_query = CommentsPhoto::getCommentsQuery($user_id, $type, $photos_id); $comment_club_query = CommentsClub::getCommentsQuery($user_id, $type, $club_photos_id); $all_comments = $comment_blog_query->union($comment_photo_query, true)->union($comment_club_query, true); $sql = (new Query())->from(['ac' => $all_comments])->limit($limit)->orderBy('comment_date_time desc'); if ($contentId) { $sql->andWhere(['<', 'comment_date_time', $date]); } $all_comments = $sql->all(); foreach ($all_comments as &$comment) { self::DateCommentsInCorrectFormat($comment); } return $all_comments; }
public function update($post, Request $request) { $post = Blog::find($post); $post->fill($request->all()); $post->save(); flash()->success('Ви успішно змінили статтю!'); return redirect(route('blog.page', ['id' => $post->id])); }
public function getBlog() { $dataMenu = new Main(); $dataBlog = new Blog(); $dataMenu = Main::all(); $dataBlog = Blog::all(); return view('main.blog', compact('dataMenu', 'dataFitur', 'dataBlog')); }
/** * Apply for lessons/workshops page * @param $workshop_id int * @return \Illuminate\View\View */ public function showApply($workshop_id) { $include_right = false; $page_workshop = $this->workshop->findOrNew($workshop_id); //Check if the workshop is already full if ($page_workshop->isFull()) { return $this->getView('lessonfull', ['page_workshop' => $page_workshop]); } //Check if the workshop is still current if ($page_workshop->isPassedDate()) { return $this->getView('lessonexpired', ['page_workshop' => $page_workshop]); } $left_image = $this->getLeftGutterImage(); $blog_menu = $this->blog->getBlogMenu(); $this->title = 'Yogaground Apply for ' . $page_workshop->name; return $this->getView('lessonform', ['include_right' => $include_right, 'page_workshop' => $page_workshop, 'left_image' => $left_image, 'blog_menu' => $blog_menu]); }
/** * Show article. * * @return Response */ public function show($slug) { $blog = Blog::where('slug', $slug)->first(); if (!$blog) { \App::abort(404); } return view('themes/kudos/blog/show', ['blog' => $blog]); }
public function delete(DeleteRequest $request, $blogId) { if ($deleted = BlogModel::deleteBlog($request->input(), $blogId)) { $message = $this->getMessage('success', [$deleted]); } else { $message = $this->getMessage('error', [Request::ERROR_DATABASE_BLOG_NOT_FOUND]); } return json_encode($message); }
public static function getTagsByBlogId(array $data, $blogId) { if ($blog = Blog::findBlog($data, $blogId)) { $tags = []; foreach ($blog->tags as $tag) { $tags[] = $tag->toArray(); } return $tags; } return false; }
/** * AJAX * Добавляет site_update * Делает рассылку * * @param integer $id - идентификатор статьи * * @return string */ public function actionSubscribe($id) { $item = Blog::find($id); if (is_null($item)) { return self::jsonError(101, 'Не найдена статья'); } Subscribe::add($item); SiteUpdate::add($item); $item->update(['is_added_site_update' => 1]); return self::jsonSuccess(); }
/** * Show the application dashboard. * * @return Response */ public function show(Request $request) { $stats['categories'] = Category::where('shop_id', '=', $request->session()->get('shop'))->count(); $stats['products'] = Product::where('shop_id', '=', $request->session()->get('shop'))->count(); $stats['customers'] = User::where('shop_id', '=', $request->session()->get('shop'))->count(); $stats['pages'] = Page::where('shop_id', '=', $request->session()->get('shop'))->count(); $stats['blogs'] = Blog::where('shop_id', '=', $request->session()->get('shop'))->count(); $stats['orders'] = Order::where('shop_id', '=', $request->session()->get('shop'))->count(); $stats['revenue'] = Order::where('shop_id', '=', $request->session()->get('shop'))->sum('total'); return view('admin/dashboard', ['stats' => $stats]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'create_date' => $this->create_date]); $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'artictle', $this->artictle]); return $dataProvider; }
public function actionArticle_edit($article_id) { $model = Blog::findOne($article_id); $categories = Category::getAllCategory(); $marks = AdminBlog::getArticlesMarks($article_id); $comments = AdminCommon::getComments('blog', $article_id, 0, 5); $content = ['content_type' => 'blog', 'content_id' => $article_id]; if (Yii::$app->request->post() && $model->validate()) { $model['id_level_1'] = $_POST['Blog']['id_level_1']; $model->save(); $this->redirect('/admin/blog?page=1'); } return $this->render('article_edit', ['model' => $model, 'categories' => $categories, 'marks' => $marks, 'comments' => $comments, 'content' => $content]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => []]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'department_id' => $this->department_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'topic', $this->topic])->andFilterWhere(['like', 'detail', $this->detail])->andFilterWhere(['like', 'tag', $this->tag]); return $dataProvider; }
public static function viewArticle($article_id, &$views) { if (!Yii::$app->user->isGuest) { $cookies_req = Yii::$app->request->cookies; $cookies_res = Yii::$app->response->cookies; $article_views = $cookies_req->getValue('article_views'); $article_views = explode('|', $article_views); if (!in_array($article_id, $article_views)) { $article_views[] = $article_id; $cookies_res->remove('article_views'); $cookies_res->add(new Cookie(['name' => 'article_views', 'value' => implode('|', $article_views), 'expire' => time() + 86400 * 30])); Blog::updateViews($article_id); $views++; Rating::view($article_id, Rating::ARTICLE); } } }
public function actionReview() { $id = \Yii::$app->request->post('id'); $session_name = 'blog_review_' . $id; if (!$this->defend($session_name)) { return $this->ajaxReturn('评论过于频繁,稍后尝试', false); } if (!Blog::allowReview($id)) { return $this->ajaxReturn('博客禁止评论', false); } $nickname = \Yii::$app->request->post('nickname'); $content = \Yii::$app->request->post('content'); if ($info = Review::add(['pid' => 0, 'blog_id' => $id, 'nickname' => $nickname, 'content' => $content], true)) { $review = ['nickname' => $info->nickname, 'content' => htmlspecialchars_decode($info->content), 'time' => $info->time, 'date' => date('y/m/d', $info->time)]; return $this->ajaxReturn(['info' => $review]); } else { return $this->ajaxReturn(Review::getError(), false); } }
public static function likeArticle() { $post = Yii::$app->request->post(); $response = []; if (Yii::$app->user->isGuest) { $response['error'] = 'Ви не авторизовані!'; } else { if (!Blog::checkLikeArticle($post['article_id'], Yii::$app->user->getId())) { $response['success'] = '+'; $response['count-likes'] = Blog::likeArticle($post['article_id'], Yii::$app->user->getId()); Rating::like($post['article_id'], Rating::ARTICLE, 1); } else { $response['count-likes'] = Blog::disLikeArticle($post['article_id'], Yii::$app->user->getId()); $response['success'] = '-'; Rating::like($post['article_id'], Rating::ARTICLE, -1); } } echo json_encode($response); }
public static function add($data, $returnInfo = false) { $review = new Review(); $uid = \Yii::$app->user->getId(); if ($uid) { $review->uid = $uid; } $review->pid = $data['pid']; $review->blog_id = $data['blog_id']; $review->nickname = $data['nickname']; $review->content = htmlspecialchars(strip_tags($data['content'])); $review->time = time(); $result = $review->insert(); if ($result) { Blog::reviewInc($review->blog_id); if ($returnInfo) { return $review; } } return $result; }
function getRead(Request $request, $id = null) { $row = Blog::getRowBlog($id); if ($row) { $this->data['row'] = $row; $this->data['id'] = $row->blogID; $this->data['alias'] = $row->slug; $this->data['blogcategories'] = Blog::summaryCategory(); $this->data['clouds'] = Blog::clouds(); $this->data['recent'] = Blog::recentPosts(); $this->data['comments'] = Blog::getComments($row->blogID); $this->data['access'] = $this->access; $this->data['pageMetakey'] = CNF_METAKEY; $this->data['pageMetadesc'] = CNF_METADESC; $this->data['pageTitle'] = $row->title; $this->data['pages'] = 'blog.view'; $page = 'layouts.' . CNF_THEME . '.index'; return view($page, $this->data); } else { return redirect('blog')->with('message', \SiteHelpers::alert('error', ' Article not found !')); } }
public static function detail($id, array $condition = []) { return parent::detail($id, ['b.uid' => \Yii::$app->user->getId()]); }
/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { $society = $view->getData()['soc']; $data['services'] = Society::with('service')->where('society', '=', $society)->first(); foreach ($data['services']->service as $service) { if ($service['language'] == "English" and $service['description'] == "") { $service->description = "Our " . $service->servicetime . " service is led in English by a minister or local preacher and a team of musicians. Everyone is welcome!"; } elseif ($service['language'] == "isiZulu" and $service['description'] == "") { $service->description = "Our " . $service->servicetime . " service is led in isiZulu by a minister or local preacher and uses the liturgy and music of the Methodist Hymn Book. Everyone is welcome!"; } $data['allservices'][] = $service; } if (!count($data['services'])) { return View::make('errors.404'); } if (isset($view->getData()['pagetitle'])) { $data['pagetitle'] = $view->getData()['pagetitle']; } else { $data['pagetitle'] = $society; } $socid = Society::where('society', '=', $society)->select('id')->first()->id; if (Helpers::is_online() and $data['services']->society_calendar != "") { $privatecal = new GoogleCalendar(); $data['cals'] = $privatecal->getTen($data['services']->society_calendar, 8); } $data['sermon'] = Sermon::with(['series' => function ($query) use($socid) { $query->where('society_id', '=', $socid); }])->orderBy('servicedate', 'DESC')->first(); if (!$data['sermon'] or !$data['sermon']->series) { $data['sermon'] = "None"; } else { if ($data['sermon']->preachable_type == 'App\\Models\\Minister') { $data['preacher'] = Minister::find($data['sermon']->preachable_id); } elseif ($data['sermon']->preachable_type == 'App\\Models\\Guest') { $data['preacher'] = Guest::find($data['sermon']->preachable_id); } else { $data['preacher'] = Preacher::find($data['sermon']->preachable_id); } } $data['welcome_page'] = "together a transforming discipleship movement"; $data['welcome_page_pic'] = "/public/images/715.jpg"; if ($data['services']->roster) { $data['roster'] = $data['services']->roster; } $data['society'] = Society::where('society', '=', $society)->first(); if ($data['society']->roster) { $data['roster'] = $data['society']->roster; } $webpage = Webpage::where('society_id', '=', $data['society']->id)->get(); foreach ($webpage as $pg) { $data[$pg->fieldname] = $pg->fieldvalue; $data[$pg->fieldname . '_pic'] = $pg->pageimage; } $data['route'] = Route::getCurrentRoute()->getPath(); if ($data['route'] != "{society}" and $data['route'] != "/") { $linkadd = Helpers::makeUrl(strtolower($society), ''); } else { $linkadd = ""; } $menu['link'] = $linkadd . "#sundays"; $menu['label'] = "Sundays"; $menu['longlabel'] = "Sunday services"; $data['menu'][] = $menu; $data['youth'] = Mission::where('society_id', '=', $data['society']->id)->where('category', '=', 'youth')->orderBy('created_at')->take(5)->get(); if (count($data['youth'])) { $menu['link'] = $linkadd . "#youth"; $menu['label'] = "Youth"; $menu['longlabel'] = "Children and Youth"; $data['menu'][] = $menu; } $data['groups'] = Group::where('society_id', '=', $data['society']->id)->where('publish', '=', 1)->get(); if (count($data['groups'])) { foreach ($data['groups'] as $obj) { $dum[0] = $obj->groupname; $dum[1] = $obj->latitude; $dum[2] = $obj->longitude; $dum[3] = Helpers::makeUrl(strtolower($data['services']->society), 'groups/' . $obj->slug); $fin[] = $dum; } $data['fin'] = json_encode($fin); $menu['link'] = "#groups"; $menu['label'] = "Groups"; $menu['longlabel'] = "Small groups"; $data['menu'][] = $menu; } else { $data['fin'] = ""; } $data['missions'] = Mission::where('society_id', '=', $data['society']->id)->where('category', '=', 'project')->take(5)->get(); if (count($data['missions'])) { $menu['link'] = $linkadd . "#projects"; $menu['label'] = "Projects"; $menu['longlabel'] = "Mission projects"; $data['menu'][] = $menu; } $blogs = Blog::with('individual')->orderBy('created_at', 'desc')->take(10)->get(); if (count($blogs)) { $first = true; foreach ($blogs as $blog) { $societies = explode(',', $blog->societies); if (in_array($data['society']->id, $societies)) { if ($first) { $data['firstblog'] = $blog; $first = false; } else { $data['blogs'][] = $blog; } } } if (isset($data['firstblog'])) { $menu['link'] = $linkadd . "#blog"; $menu['label'] = "Blog"; $menu['longlabel'] = "Latest blogs"; $data['menu'][] = $menu; } } $menu['link'] = $linkadd . "#contact"; $menu['label'] = "Contact"; $menu['longlabel'] = "Contact us"; $data['menu'][] = $menu; $data['counter'] = 1; $view->with('data', $data); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * * @return \Illuminate\Http\Response */ public function update(BlogsRequest $request, $society, $id) { $blog = Blog::find($id); $blog->fill($request->except('societies', 'subjects')); $blog->societies = implode(',', $request->input('societies')); if ($request->input('subjects') != "") { $newsubjs = array_map('intval', $request->input('subjects')); $blog->subject()->sync($newsubjs); } else { $blog->subject()->detach(); } if ($request->file('blogimage')) { $fileName = "blogimage_" . $blog->id . "." . $request->file('blogimage')->getClientOriginalExtension(); $request->file('blogimage')->move(base_path() . '/storage/app/images/', $fileName); $blog->blogimage = '/storage/app/images/' . $fileName; } $blog->save(); return redirect(url('/') . '/' . $society . '/blogs')->with('okmessage', 'Data updated'); }
public function getDeletePost($id) { $blog = Blog::findOrFail($id); $blog->destroy($id); return redirect()->route('blog')->with('info', 'data berhasil di ubah'); }
/** * @return \yii\db\ActiveQuery */ public function getBlogs() { return $this->hasMany(Blog::className(), ['id_user' => 'id']); }
public function actionBlog_item($year, $month, $day, $id) { $date = $year . $month . $day; $pattern = '#^[a-z\\d_-]+$#'; if (!preg_match($pattern, $id)) { throw new BadRequestHttpException('Имеются запрещенные символы'); } $item = Blog::find(['date' => $date, 'id_string' => $id]); if (is_null($item)) { throw new HttpException(404, 'Нет такой статьи'); } $item->incViewCounter(); $nearList = Blog::query()->select('id,header,id_string,image,view_counter,description,date_insert,date')->orderBy(['date_insert' => SORT_DESC])->andWhere(['not in', 'id', $item->getId()])->limit(3)->all(); return $this->render(['item' => $item, 'nearList' => $nearList]); }
public function view() { $slug = Blog::whereslug($slug)->first(); // select * from mon_cases where slug=$slug limit 1 return View::make('blogs.view')->with('slug', $slug); }
/** * @param Blog $model * @param Array $post * @return mixed */ public static function saveImageAndModel($model, $post) { if ($model->load($post)) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); if ($model->imageFile->baseName) { $model->image = 'images/' . md5($model->imageFile->baseName . time()) . '.' . $model->imageFile->extension; file_put_contents(Yii::getAlias('@app/web/' . $model->image), file_get_contents($model->imageFile->tempName)); } return $model->validate() && $model->save(); } return false; }
/** * @return \yii\db\ActiveQuery */ public function getBlogs() { return $this->hasMany(Blog::className(), ['department_id' => 'id']); }
/** * Delete a blog. * * @param string $id * * @return Redirect */ public function destroy($id) { // delete $blog = Blog::find($id); $blog->delete(); // redirect $request->session()->flash('success', trans('blog.blog') . ' ' . trans('crud.deleted')); return redirect('admin/blog'); }
/** * Finds the Blog model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Blog the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Blog::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }