/**
  * Sets variables for view of "Úvod" page
  */
 public function renderDefault()
 {
     $template = $this->template;
     $template->chronicle = $this->events->getNewestChronicle();
     $template->news = $this->news->getNewest(4);
     $template->leader = $this->members->getLeader();
 }
Ejemplo n.º 2
0
 /**
  * Processing of News editing form
  *
  * @Privilege('create', 'edit')
  *
  * @param $button
  */
 public function editNewsFormSucceded($button)
 {
     $values = $button->form->getValues(TRUE);
     $values['posted'] = new \DateTime();
     if ($this->user->isAllowed('Admin:Default:News', 'show')) {
         // User can choose
         $values['show'] = $values['show'] ? 1 : 0;
         //translate TRUE/FALSE to 1/0
     } else {
         $values['show'] = 0;
         //default value
     }
     if ($values['id']) {
         //update
         $this->loadItem($values['id'])->update($values);
         $this->flashMessage('Aktualita byla úspěšně upravena');
     } else {
         //insert
         if (empty($values['event_id'])) {
             $values['event_id'] = NULL;
         }
         $this->news->insert($values);
         $this->flashMessage('Aktualita byla úspěšně přidána');
     }
     $this->redirect('default');
 }
Ejemplo n.º 3
0
 /**
  * action - Удаление новости по id
  */
 protected function actionDelete()
 {
     $art = News::findById((int) $_GET['id']);
     $art->delete();
     header('Location: /../index.php?ctrl=AdminPanel');
     exit(0);
 }
Ejemplo n.º 4
0
 public function listen()
 {
     $routing = new BaseRoute();
     $routing->get('/', ['controller' => 'main', 'action' => 'index']);
     $routing->get('/article', ['controller' => 'main', 'action' => 'article']);
     $routing->post('/admin/edit/news', ['controller' => 'admin', 'action' => 'editNews']);
     $routing->get('/admin/edit/news', ['controller' => 'admin', 'action' => 'editNews']);
     $routing->get('/admin/delete/news', ['controller' => 'admin', 'action' => 'deleteNews']);
     //тесты
     $routing->get('/test/each', function () {
         $model = \Models\News::find()->queryEach();
         foreach ($model as $root) {
             echo $root->id . "<br>";
         }
     });
     //так как учебный пример, можно и в роуте
     $routing->get('/admin/test', function () {
         $user = User::findOne('id = 1');
         $news = News::findOne('id = 1');
         $data = new AdminDataTable([$user, $news], [function ($model) {
             return $model->id + 1;
         }, function ($model) {
             if ($model->name) {
                 return $model->name;
             }
             return "(no name)";
         }]);
         echo $data->render();
     });
     $routing->listen();
 }
Ejemplo n.º 5
0
 /**
  * 保存数据进数据库
  * @param $data
  * @author Mr.Cong <*****@*****.**>
  */
 public function saveData($data)
 {
     DB::table('news')->truncate();
     foreach ($data['items'] as $key => $item) {
         $News = new News();
         $News->title = $item->get_title();
         $News->tag = $this->tag;
         $News->link = $item->get_link();
         $News->description = html_entity_decode($item->get_description(), ENT_COMPAT);
         $News->category = $item->get_category()->get_term();
         $News->author = $item->get_author()->get_name();
         $News->pubDate = strtotime($item->get_date());
         $News->content = html_entity_decode($item->get_content(), ENT_COMPAT);
         $News->save();
     }
     writeLog('Save data to database.');
 }
Ejemplo n.º 6
0
 public function save($model)
 {
     if ($this->validate()) {
         $params = $model;
         if ($model === null) {
             $model = new News();
         }
         $model->title = $this->form_title;
         $model->text = $this->form_text;
         $this->_id = $model->save();
         if (null !== $params) {
             $this->_id = $model->id;
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 7
0
 protected function DeleteNewsAction()
 {
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $news = News::findById($_GET['id']);
         if ($news) {
             $news->delete();
         }
     }
     $this->redirect('/');
 }
Ejemplo n.º 8
0
 public function news($section, $newsId)
 {
     $news = News::findById($newsId);
     if (is_null($news)) {
         App::abort(404, 'Noticia no encontrada');
     }
     $related = News::query()->where('section', '=', $news->section)->limit(0, 2)->get();
     $user = User::get();
     $comments = Comment::query()->where('newsId', '=', $newsId)->get();
     return $this->base('news/news.t', array('comments' => $comments, 'user' => $user, 'news' => $news, 'related' => $related));
 }
Ejemplo n.º 9
0
 protected function ArticleAction()
 {
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $model = News::findById($_GET['id']);
         if ($model) {
             $this->view->model = $model;
             $this->view->display("article");
         } else {
             throw new E404Exception("статья еще не написана");
         }
     }
 }
Ejemplo n.º 10
0
 public function showAction($id = null, $slug = null)
 {
     $id = $this->filter->sanitize($id, "int");
     $images = array();
     $model = \Models\News::findFirst(array("conditions" => "id = ?1", "bind" => array(1 => "{$id}")));
     $images = $model->getImages();
     $user = $model->owner;
     Tag::setTitle($model->title);
     $this->view->setVar('model', $model);
     $this->view->setVar('images', $images);
     $this->view->setVar('user', $user);
 }
Ejemplo n.º 11
0
 /**
  * 显示内容
  * @param $name
  * @param $id
  * @return mixed
  * @author Mr.Cong <*****@*****.**>
  */
 public function show($name, $id)
 {
     /*
      * 开始查询数据
      */
     switch ($name) {
         case 'forums':
             $post = Forums::find($id);
             break;
         case 'news':
             $post = News::find($id);
             break;
         default:
             break;
     }
     return view('show')->with('post', $post)->with('name', $name);
 }
Ejemplo n.º 12
0
 /**
  * 显示内容
  * @param $name
  * @param $id
  * @return mixed
  * @author Mr.Cong <*****@*****.**>
  */
 public function show($name, $id)
 {
     /*
      * 开始查询数据
      */
     switch ($name) {
         case 'forums':
             $post = Forums::find($id);
             $post = $post->content = body_replace_with_forums_by_json($post->content);
             break;
         case 'news':
             $post = News::find($id);
             break;
         default:
             break;
     }
     return Response::json($post);
 }
Ejemplo n.º 13
0
 public function section($section)
 {
     $news = News::query()->where('section', '=', $section)->orderBy('created', 'DESC')->limit(0, 6)->get();
     $col1 = array();
     $col2 = array();
     $featured = null;
     foreach ($news as $idx => $model) {
         if (is_null($featured)) {
             $featured = $model;
             continue;
         }
         if ($idx) {
             if ($idx % 2) {
                 $col1[] = $model;
             } else {
                 $col2[] = $model;
             }
         }
     }
     return $this->base('home/section.t', array('section' => $section, 'featured' => $featured, 'col1' => $col1, 'col2' => $col2));
 }
Ejemplo n.º 14
0
 /**
  * action - Получение конкретной новости по id
  */
 protected function actionArt()
 {
     $this->view->article = \Models\News::findById($_GET['id']);
     $this->view->display(__DIR__ . '/../Templates/article.php');
 }
Ejemplo n.º 15
0
 public function loadModel($id)
 {
     $model = \Models\News::findFirst("id = '{$id}'");
     if ($model === null) {
         $this->flashSession->error("Новость не найдена");
         return $this->response->redirect("backend/news/index");
     }
     return $model;
 }
Ejemplo n.º 16
0
 public function delete($newsId)
 {
     $news = News::findById($newsId);
     $news->delete();
     Response::redirect('/admin/news');
 }
 public function deleteAction($id)
 {
     $news = News::findByPk($id);
     $news->del();
     header('Location: /news/all');
 }
Ejemplo n.º 18
0
 /**
  * Sets variables for view of "Aktuality" page
  */
 public function renderNews()
 {
     $template = $this->template;
     $template->title = "Aktuality";
     $template->news = $this->news->getNewest(10);
 }
Ejemplo n.º 19
0
 public function actionDetail(Request $request, Response $response)
 {
     $newsId = $request->getRequestData()['newsId'];
     $request->setView('site/details');
     return News::getByIdOr404($newsId);
 }