Inheritance: extends App\Model
Example #1
0
 public function actionNews()
 {
     for ($i = 1; $i <= 10; $i++) {
         $model = new News();
         $model->attributes = ['name' => 'Bài viết số ' . $i, 'title' => 'Title cua bai viet so ' . $i, 'slug' => 'bai-viet-so-' . $i, 'images' => '3.png', 'type_id' => rand(1, 100), 'user_id' => '1', 'created_at' => time(), 'updated_at' => time()];
         $model->save();
     }
 }
 public function actionSave_news()
 {
     $news = new News();
     $news->title = $_POST['title'];
     $news->content = $_POST['content'];
     $news->createTime = date('Y-m-d H:i:s');
     $news->tag = 'unnecessary';
     $news->save();
     echo 1;
 }
 public function actionIndex($page = 1)
 {
     $NewsModel = new News();
     $Query = $NewsModel->select();
     $totalNewsNumber = $Query->count();
     $Pagination = new Pages($totalNewsNumber, 20);
     $Pagination->setCurrent($page);
     $News = $Query->offset($Pagination->offset())->limit($Pagination->resultsOnPage())->get();
     $this->render('index', ['totalNewsNumber' => $totalNewsNumber, 'News' => $News, 'Pagination' => $Pagination, 'newsOnPage' => 10], !Application::$i->Input->isAjax());
 }
Example #4
0
 protected function actionCreate()
 {
     try {
         $article = new News();
         $article->fill([]);
         $article->save();
     } catch (MultiException $e) {
         $this->view->errors = $e;
     }
     echo $this->view->render(__DIR__ . '/../templates/update.php');
 }
Example #5
0
 public function cart($slug, News $news, Request $request)
 {
     $this->data['records'] = $news->getBySlug($slug);
     $id_data = $news->getBySlug($slug);
     $id_news_comment = $id_data->id;
     //Ід новини
     $this->data['newsComments'] = $news->newsComments($id_news_comment);
     $this->data['newsCommentsCount'] = $news->newsCommentsCount($id_news_comment);
     \DB::table('news')->WHERE('id', '=', $id_news_comment)->increment('count_views_news');
     // рахуємо кулькість переглядів новини
     if ($request->ajax()) {
         return response()->json(view('news.ajaxPaginate.Cart', $this->data)->render());
     }
     return view('news.cart', $this->data);
 }
Example #6
0
 protected function actionDelete()
 {
     $id = $_GET['id'] ?? false;
     $this->redirectIf('/admin/news/index', false === $id);
     $article = \App\Models\News::findByID($id);
     $this->redirectIf('/admin/news/index', $article->delete());
 }
Example #7
0
 /**
  * Действие для вывода одной новости по id
  */
 protected function actionOne()
 {
     if (false == ($this->view->article = \App\Models\News::findOneById($_GET['id']))) {
         throw new Exception404('Новость не найдена', 404);
     }
     $this->view->display(__DIR__ . '/../Templates/News/One.php');
 }
Example #8
0
 public function actionIndex($kinds = 'all')
 {
     $sort = new Sort(['attributes' => ['theme' => ['asc' => ['theme' => SORT_ASC], 'desc' => ['theme' => SORT_DESC], 'default' => SORT_ASC, 'label' => '主题'], 'author' => ['asc' => ['author' => SORT_ASC], 'desc' => ['author' => SORT_DESC], 'default' => SORT_DESC, 'label' => '作者'], 'reply' => ['asc' => ['reply' => SORT_ASC], 'desc' => ['reply' => SORT_DESC], 'default' => SORT_DESC, 'label' => '回复'], 'updated_at' => ['asc' => ['updated_at' => SORT_ASC], 'desc' => ['updated_at' => SORT_DESC], 'default' => SORT_DESC, 'label' => '最后更新'], 'plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞'], 'kinds' => ['asc' => ['kinds' => SORT_ASC], 'desc' => ['kinds' => SORT_DESC], 'default' => SORT_ASC, 'label' => '类别']], 'defaultOrder' => ['updated_at' => SORT_DESC]]);
     if ($kinds === 'all') {
         $query = Forum::find();
     } elseif ($kinds === 'tucao') {
         $query = Forum::find()->where(array('kinds' => 'tucao'));
     } elseif ($kinds === 'tactic') {
         $query = Forum::find()->where(array('kinds' => 'tactic'));
     } elseif ($kinds === 'rule') {
         $query = Forum::find()->where(array('kinds' => 'rule'));
     } elseif ($kinds === 'bug') {
         $query = Forum::find()->where(array('kinds' => 'bug'));
     } elseif ($kinds === 'team') {
         $query = Forum::find()->where(array('kinds' => 'team'));
     } elseif ($kinds === 'myposts') {
         //我发的帖子
         $query = Forum::find()->where(array('author' => Yii::$app->user->identity->username));
     } elseif ($kinds === 'myreplies') {
         //我回复的帖子
         $queryid = DetailForum::find()->select(['fatherindex'])->where(array('author' => Yii::$app->user->identity->username));
         $query = Forum::find()->where(array('id' => $queryid));
     } else {
         $query = Forum::find();
     }
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
     $forums = $query->orderBy($sort->orders)->offset($pagination->offset)->limit($pagination->limit)->all();
     //用来置顶2个点赞量最高的
     $sort1 = new Sort(['attributes' => ['plike' => ['asc' => ['plike' => SORT_ASC], 'desc' => ['plike' => SORT_DESC], 'default' => SORT_DESC, 'label' => '赞']], 'defaultOrder' => ['plike' => SORT_DESC]]);
     $topquery = Forum::find()->orderBy($sort1->orders)->limit(2)->all();
     //用来置顶2个点赞量最高的
     $news = News::find()->orderBy('addedat')->all();
     return $this->render('index', ['new' => $news[0], 'forums' => $forums, 'pagination' => $pagination, 'sort' => $sort, 'topquery' => $topquery]);
 }
 public static function gridForAdmins(&$filter, &$grid)
 {
     $filter = \DataFilter::source(News::with('createdBy', 'approvedBy', 'status'));
     //->where('status_id', '<>', 1)
     $filter->add('title', 'Title', 'text');
     $filter->add('content', 'Content', 'text');
     $filter->add('createdBy.name', 'created_by', 'text');
     $filter->add('approvedBy.name', 'approved_by', 'text');
     $filter->add('updated_at', 'Last update date', 'daterange')->format('m/d/Y', 'en');
     $filter->add('created_at', 'Create date', 'daterange')->format('m/d/Y', 'en');
     $filter->submit('search');
     $filter->reset('reset');
     $filter->build();
     $grid = DataGrid::source($filter);
     $grid->attributes(array("class" => "table table-striped"));
     $grid->add('title', 'Title', true);
     $grid->add('updated_at|strtotime|date[m/d/Y]', 'Last update date', true);
     $grid->add('created_at|strtotime|date[m/d/Y]', 'Create date', true);
     $grid->add('content|strip_tags|substr[0,20]', 'Content');
     $grid->add('createdBy.name', 'created_by');
     $grid->add('approvedBy.name', 'approved_by');
     $grid->add('status.title', 'Status');
     $grid->add('view', 'View')->cell(function ($value, $row) {
         return '<a class="btn btn-responsive" href="' . url('admin-news/view') . "/" . $row->id . '"><i class="glyphicon glyphicon-eye-open"></i></a>';
     });
     $grid->add('status.id', 'Approve')->cell(function ($value, $row) {
         if ($value == 2) {
             return '<a class="btn btn-success btn-responsive" href="' . url('admin-news/approve') . "/" . $row->id . '"><i class="glyphicon glyphicon-ok"></i> Approve</a>';
         }
         return '';
     });
     $grid->orderBy('id', 'desc');
     $grid->paginate(10);
 }
Example #10
0
 public function actionFindByColumn()
 {
     $item = News::findByColumn('title', 'Hello');
     $view = new View();
     $view->item = $item;
     $view->display('findByColumn.php');
 }
Example #11
0
 public function actionIndex()
 {
     $newsSearch = new NewsSearch();
     $dataProvider = $newsSearch->search(Yii::$app->request->get());
     $statuses = News::getStatuses();
     return $this->render('index', ['newsSearch' => $newsSearch, 'dataProvider' => $dataProvider, 'statuses' => $statuses]);
 }
Example #12
0
 public function actionView($id)
 {
     //Ищем запись по id
     $new = News::findOne($id);
     //Отправляем представлению
     return $this->render('view', ['new' => $new]);
 }
Example #13
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $cat)
 {
     if (Yii::$app->user->isGuest) {
         $isAdmin = false;
     } else {
         if (Yii::$app->user->identity->role == 1) {
             $isAdmin = true;
         } else {
             $isAdmin = false;
         }
     }
     if ($isAdmin) {
         $query = News::find();
     } else {
         $query = News::find()->where(['cat' => $cat]);
     }
     $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(['news_id' => $this->news_id, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'cat' => $this->cat, 'clickcnt' => $this->clickcnt]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Example #14
0
 public function actionArticle()
 {
     $id = $_GET['id'];
     $article = News::find()->where(["id" => $id])->one();
     // echo $id;
     return $this->render('article', ['article' => $article]);
 }
Example #15
0
 protected function actionOne()
 {
     $id = (int) $_GET['id'];
     $this->view->article = \App\Models\News::findById($id);
     $this->view->title .= $this->view->article->title;
     $this->view->display(__DIR__ . '/../Views/article.php');
 }
Example #16
0
 public function actionUpdate()
 {
     if (isset($_POST['submit'])) {
         if (empty($_POST['title']) || empty($_POST['text'])) {
             echo 'Title or text could not be empty';
             echo '<br><a href="/home2/admin">Back to admin panel</a>';
             exit;
         }
         $article = News::GetOne($_POST['id']);
         $article->title = $_POST['title'];
         $article->text = $_POST['text'];
         if (true === $article->Save()) {
             echo 'Article was updated';
             echo '<br><a href="/home2/admin">Back to admin panel</a>';
             exit;
         } else {
             echo 'Error updateing database';
             echo '<br><a href="/home2/admin">Back to admin panel</a>';
             exit;
         }
     }
     if (!isset($_GET['id'])) {
         echo 'Could not found the article';
         echo '<br><a href="/home2/admin">Back to admin panel</a>';
         exit;
     }
     $view = new ViewConstuctor();
     $view->article = News::GetOne($_GET['id']);
     $view->Display('Admin/Update');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('news')->delete();
     for ($i = 0; $i < 100; $i++) {
         News::create(['title' => 'Title ' . $i, 'meta_description' => 'meta desc ' . $i, 'views' => '1000', 'content' => 'Body ' . $i, 'user_id' => 1]);
     }
 }
Example #18
0
 public function actionIndex()
 {
     $news = News::find()->orderBy('createTime desc')->limit(3)->all();
     //  var_dump($news);
     //echo $news[0]->title;
     return $this->render('index', ['news' => $news]);
 }
Example #19
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $query = News::find();
     $pagination = new Pagination(['defaultPageSize' => 4, 'totalCount' => $query->count()]);
     $news = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['news' => $news, 'pagination' => $pagination]);
 }
 /**
  * 创建
  *
  * @param array $input
  * @return News
  * @throws GeneralException
  */
 public function create(array $input)
 {
     if ($id = News::create($input)) {
         return $id;
     }
     throw new GeneralException('There was a problem creating this news. Please try again.');
 }
 public function actionView()
 {
     $id = Yii::$app->request->get('id');
     $model = Teachers::findOne(['id' => $id]);
     $trainWind = News::getImgRecommendNewsByCategory(11, 12);
     return $this->render('view', ['data' => $model, 'trainWind' => $trainWind]);
 }
 public function run()
 {
     // query
     $news = News::find()->orderBy('date_news DESC')->limit(5)->all();
     // render view
     return $this->render('news', ['news' => $news]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $newses = [['title' => 'МИД Британии: Совет Безопасности ООН обсудит ответные меры на запуск ракеты КНДР', 'text' => 'КНДР в воскресенье запустила баллистическую ракету с космодрома "Сохэ". Глава МИД Великобритании назвал запуск "провокационным" и отметил, что Совет Безопасности ООН согласует коллективный ответ на испытания.'], ['title' => 'Китай обеспокоен возможным размещением ПРО США в Южной Корее', 'text' => 'Во внешнеполитическом ведомстве КНР подчеркнули, что позиция Китая по вопросу ПРО последовательна и ясна. Там отметили, что все страны, стремясь обеспечить свою безопасность, должны иметь в виду интересы в сфере безопасности других стран.']];
     foreach ($newses as $news) {
         \App\Models\News::create($news);
     }
 }
 public function execute($user, $item, $params)
 {
     $user_role = Users::findOne($user)->authAssignments->item_name;
     if (isset($params['news'])) {
         $news_status = $params['news']->status;
         $news_category = $params['news']->category_id;
         $relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category]));
         if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') {
             return true;
         }
         if ($news_status == News::MODER_NEWS) {
             if ($user_role == 'moderator') {
                 return $relCat;
             }
         }
         if ($news_status == News::SMODER_NEWS) {
             if ($user_role == 'super_moderator') {
                 return true;
             }
         }
     } elseif (isset($params['question'])) {
         if ($user_role == 'moderator') {
             $news = News::findOne($params['question']->news_id);
             if (!is_null($news)) {
                 if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Example #25
0
 public function actionFormDeletenews()
 {
     $id = $_GET['id'];
     $news = NewsModel::getOneById($id);
     $view = new View();
     $view->item = $news;
     $view->display('admin/deletenews.php');
 }
Example #26
0
 public function actionIndex()
 {
     $season = Season::findBySql('SELECT * FROM season WHERE invisible = 0 AND (unit1 != "" OR unit2 != "" OR unit3 != "" OR unit4 != "")')->all();
     $news = News::find()->where(['type' => '1'])->orderBy('id DESC')->one();
     $event = News::find()->where(['type' => '2'])->orderBy('id DESC')->one();
     $msgs = Chatmain::find()->orderBy('id DESC')->limit(50)->all();
     return $this->render('index', ['season' => $season, 'news' => $news, 'event' => $event, 'msgs' => $msgs]);
 }
Example #27
0
 public function actionFormSendEmail()
 {
     $id = $_GET['id'];
     $news = NewsModel::getOneById($id);
     $view = new View();
     $view->item = $news;
     $view->display('news/FormSendEmail.php');
 }
 /**
  * Show dashboard
  * 
  * @return Response
  */
 public function index()
 {
     $faculty = Faculty::count();
     $researchGroup = ResearchGroup::count();
     $researchArea = ResearchArea::count();
     $news = News::count();
     return view('admin.pages.dashboard', compact('faculty', 'researchGroup', 'researchArea', 'news'));
 }
Example #29
0
 /**
  * использование генератора
  * @throws \App\Exceptions\Err404
  */
 protected function actionIndex()
 {
     $this->view->news = \App\Models\News::findAllUseGen();
     if (!$this->view->news) {
         throw new \App\Exceptions\Err404('Новости не найдены ');
     }
     $this->view->displayTwig('index.twig', ['news' => $this->view->news]);
 }
Example #30
0
 public function actionNews($news_id)
 {
     $news = News::find()->where(['id' => $news_id, 'is_published' => 1])->asArray()->one();
     if ($news) {
         $news['categories'] = CategoryRelations::get_news_categories_names($news['id']);
         return $this->render('news', compact('news'));
     }
 }