Пример #1
0
function news_show()
{
    global $news_show;
    $news = new News();
    $news_show = $news->find($_GET['id']);
    render();
}
Пример #2
0
 public function removeNews($id)
 {
     $news = News::find($id);
     $name = $news->title;
     $news->delete();
     return Redirect::route('account')->with('status', 'alert-success')->with('global', 'You just deleted ' . $name);
 }
Пример #3
0
 /**
  * @param $id
  * @return mixed
  */
 public function togglePublish($id)
 {
     $news = $this->news->find($id);
     $news->is_published = $news->is_published ? false : true;
     $news->save();
     return Response::json(array('result' => 'success', 'changed' => $news->is_published ? 1 : 0));
 }
Пример #4
0
 public function Insert_UpdateNews($data)
 {
     $id = Input::get("id");
     if (!Input::has('id')) {
         $news = new News();
     } else {
         $news = News::find(array_get($data, 'id'));
         //tìm id đã có trong data
     }
     $news->title = array_get($data, 'title');
     // Upload images
     if (Input::file('file')) {
         define('PATH_CATEGORY_ICON', rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/upload/');
         $file = array_get($data, 'file');
         $file->move(PATH_CATEGORY_ICON, $file->getClientOriginalName());
         $news->images = $file->getClientOriginalName();
     }
     // End Upload images
     $news->tomtat = array_get($data, 'tomtat');
     $news->content = array_get($data, 'content');
     $news->cat_id = array_get($data, 'cat_id');
     $news->hot = array_get($data, 'hot');
     $news->ngaydangbai = date('Y-m-d H:i:s');
     return $news->save();
 }
Пример #5
0
 public function listAction()
 {
     $params = $this->request->getQuery();
     if ($params['_url'] != null) {
         $string = ltrim($params['_url'], '/danh-muc');
     }
     $array = explode('-', $string);
     $id = $array[0];
     // Get name category
     $category = Category::findFirstById($id);
     $this->tag->setTitle($category->name);
     // Get list category of id
     if ($id != '' && $id > 0) {
         // The data set to paginate
         $news = News::find(array('active = 1 AND category =' . $id, 'order' => 'id DESC'));
         $currentPage = (int) $_GET["page"];
         // Create a Model paginator, show 10 rows by page starting from $currentPage
         $paginator = new PaginatorModel(array("data" => $news, "limit" => 13, "page" => $currentPage));
         // Get the paginated results
         $page = $paginator->getPaginate();
         $this->view->setVar('page', $page);
         $this->view->setVar('category', $category);
     } else {
         $this->response->redirect('error');
     }
 }
Пример #6
0
 public function testEmpty()
 {
     $news = News::find();
     $this->assertTrue($news->count() == 0);
     $news = new News();
     $news->title = "A new News!";
     $this->assertFalse($news->save());
 }
Пример #7
0
 public function showYearAction()
 {
     $activeYear = $this->filter->sanitize($this->_getParam('year'), "int");
     Phalcon_Tag::setTitle('News');
     $this->view->setVar("news", News::find(array("year='{$activeYear}'", "order" => "published DESC")));
     $this->view->setVar("activeYear", $activeYear);
     $this->view->setVar("years", News::count(array('group' => 'year')));
 }
Пример #8
0
 public function get_detail($id)
 {
     $news = News::find($id);
     if (is_null($news)) {
         return json_encode('News not found', 404);
     } else {
         return json_encode($news);
     }
 }
Пример #9
0
 public function hasUpdated()
 {
     $checksum = News::find()->select('SUM(`publishDate`)')->where(['or', ['in', 'categoryID', $this->categories], ['in', 'id', $this->articles]])->scalar();
     if (\Yii::$app->cache->get('rssfeed-' . $this->id . '-checksum') != $checksum) {
         \Yii::$app->cache->set('rssfeed-' . $this->id . '-checksum', $checksum);
         return true;
     }
     return false;
 }
Пример #10
0
 public function post_delete($id)
 {
     $news = News::find($id);
     if (empty($news)) {
         return View::make('msg.error')->with('error', 'That news item doesn\'t exist.');
     }
     $news->delete();
     return Redirect::to('/admin/news/overview');
 }
Пример #11
0
 public function get_delete($id = false)
 {
     if (!$id) {
         return Redirect::to('news');
     }
     $news = News::find($id);
     $news->delete();
     return Redirect::to('news');
 }
Пример #12
0
 public function indexAction()
 {
     $language = Phalcon_Session::get('language');
     $news = News::find(array("language='{$language}'", "limit" => 5, "order" => "published desc"));
     if (count($news) === 0) {
         $news = News::find(array("language='en'", "limit" => 5, "order" => "published desc"));
     }
     //Query the last 5 news
     $this->view->setVar("news", $news);
 }
Пример #13
0
 public function destroy($id, $request)
 {
     $data = ['success' => false];
     if (News::exists($id)) {
         $new = News::find($id);
         if ($new->belongsToUser(Session::get())) {
             $data['success'] = $new->delete();
         }
     }
     return new JsonResponse($data);
 }
Пример #14
0
    function index() {
        $recent_events = Event::find()->where(array('created_at >= NOW() - INTERVAL 1 WEEK'))->order('created_at DESC')->all();

        $find_news = News::find()
            ->order(array('weight ASC', 'updated_at DESC'))
            ->limit(5);

        $this->render(array(
            'recent_events' => $recent_events,
            'news' => $find_news->all(),
        ));
    }
 public function showSinglePressItem($slug, $id)
 {
     $pressItem = News::with('catalog')->find($id);
     if (!$pressItem || !$pressItem->isActive() || $pressItem->getSlug() != $slug) {
         App::abort(404);
     }
     $previousPressItemId = News::active()->where('id', '<', $pressItem->id)->max('id');
     $previousPressItem = News::find($previousPressItemId);
     $nextPressItemId = News::active()->where('id', '>', $pressItem->id)->min('id');
     $nextPressItem = News::find($nextPressItemId);
     return View::make('about.press.single', compact('pressItem', 'previousPressItem', 'nextPressItem'));
 }
Пример #16
0
 public function showYearAction()
 {
     $activeYear = $this->dispatcher->getParam('year', "int");
     $exists = $this->view->getCache()->exists($activeYear);
     if (!$exists) {
         Phalcon\Tag::setTitle('News');
         $this->view->setVar("news", News::find(array("year='{$activeYear}'", "order" => "published DESC")));
         $this->view->setVar("activeYear", $activeYear);
         $this->view->setVar("years", News::count(array('group' => 'year')));
     }
     $this->view->cache(array("lifetime" => 86400, "key" => $activeYear));
 }
 public function indexAction()
 {
     $news1 = News::find(array("typeid = 1", "order" => "inputtime desc", "limit" => 5));
     $news2 = News::find(array("typeid = 2", "order" => "inputtime desc", "limit" => 5));
     $news3 = News::find(array("typeid = 3", "order" => "inputtime desc", "limit" => 3));
     $news4 = News::find(array("typeid = 4", "order" => "inputtime desc", "limit" => 5));
     $indexProducts = Products::find(array("limit" => 5, "order" => "id asc"));
     $this->view->indexProducts = $indexProducts;
     $this->view->setVar("news1", $news1);
     $this->view->setVar("news2", $news2);
     $this->view->setVar("news3", $news3);
     $this->view->setVar("news4", $news4);
 }
Пример #18
0
 function delete($params){
     $news = News::find($params['id']);
     if (!empty($news)) {
         if ($news->destroy()) {
             $this->flash('success', 'Successfully Destroyed');
         } else {
             $this->flash('error', 'Can\'t destroy News! ' . $news->errors[0]);
         }
     } else {
         $this->flash('error', 'News not found!');
     }
     $this->redirect_back();
 }
Пример #19
0
 public function indexAction()
 {
     $language = $this->session->get('language');
     $exists = $this->view->getCache()->exists($language . 'index');
     if (!$exists) {
         $news = News::find(array("language='{$language}'", "limit" => 5, "order" => "published desc"));
         if (count($news) === 0) {
             $news = News::find(array("language='en'", "limit" => 5, "order" => "published desc"));
         }
         //Query the last 5 news
         $this->view->setVar("news", $news);
     }
     $this->view->cache(array("lifetime" => 86400, "key" => $language . 'index'));
 }
Пример #20
0
 public function getTestModel()
 {
     // $news = News::select('id', 'name')->getList();
     // echo '<pre>'; print_r($news); echo '</pre>';
     if ($news = News::find(1)) {
         $validator = $news->set(array('name' => 'test name', 'text' => 'a lot of text', 'another' => 'this is not a field'));
         if ($validator->success()) {
             echo "validation success\n";
             $news->save();
         } else {
             echo "validation fail\n";
             echo "error fields: " . implode(', ', $validator->errorFields) . "\n";
         }
         print_r($news);
     }
     return Response::text("end");
 }
Пример #21
0
 public function postEditNews($id)
 {
     /* validate input */
     $validator = Validator::make(Input::all(), array("title" => "required", "description" => "required"));
     /* if validated */
     if ($validator->passes()) {
         /* get input */
         $news = News::find($id);
         $news->title = Input::get("title");
         $news->description = Input::get("description");
         $news->save();
         return Redirect::to("admin/ews/edit_news/{$news->id}")->with('message', 'News edited!');
     } else {
         return Redirect::to("admin/news/edit_news/{$news->id}")->withErrors($validator);
     }
     // end validation
 }
 /**
  * 更新新闻
  * 
  */
 function actionEdit()
 {
     $form = Form_Admin_News::createForm('news', url('news/edit'));
     $newId = $this->_context->id;
     $news = News::find('id =?', $newId)->query();
     //数组导入到表单
     $form->import($news);
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         try {
             //改变属性的值
             $news->changeProps($form->values());
             $news->save();
             return $this->_redirectMessage('编辑文章内容成功', '如果你不做出选择系统将自动跳转', url('news/index'), 3);
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['form'] = $form;
 }
Пример #23
0
 public function getAnnouncementNews()
 {
     $conditions = [];
     if ($this->articles) {
         $conditions[] = ['in', 'id', $this->articles];
     }
     if ($this->categories) {
         $conditions[] = ['in', 'categoryID', $this->categories];
     }
     if (empty($conditions)) {
         return false;
     }
     if (count($conditions) > 1) {
         $conditions = array_merge(['or'], $conditions);
     } else {
         $conditions = array_shift($conditions);
     }
     return News::find()->with('category')->where($conditions)->orderBy('publishDate DESC')->limit(1)->one();
 }
 public function indexAction()
 {
     //$this->persistent->searchParams = null;
     $Newstype = Newstype::find();
     $this->view->setVar("Newstype", $Newstype);
     $News = News::find();
     $this->view->setVar("News", $News);
     /* 		$typeArr;
     		$type = Type::find();
     		foreach($type as $k=>$v){
     			$types = Types::find("fid = '".$v->id."'");
     			$typeArr[$v->name] = $types->toArray();
     		}
     		
     		$auth = $this->session->get("auth");
     		if($auth['did'] != 0){
     			Tag::setDefault("company", $auth['did']);
     		}
     		$this->view->setVar('did',$auth['did']);
     		$this->view->setVar("typeArr",$typeArr);	 */
 }
 public function indexAction()
 {
     $dynamicPageBegin = $this->request->getPost("dynamicPageBegin");
     $mediaPageBegin = $this->request->getPost("mediaPageBegin");
     $schdPageBegin = $this->request->getPost("schdPageBegin");
     $type = $this->request->getQuery("type");
     if ($type == '') {
         $type = $this->request->getPost("type");
     }
     if ($type == '') {
         $type = 'X_WXX';
     }
     $this->view->setVar("type", $type);
     /*		$news1 = News::find(array(
     			"typeid = 1",
     			"limit" => 5
     		));
     		$news2 = News::find(array(
     			"typeid = 2",
     			"limit" => 5
     		));
      		$news3 = News::find(array(
     			"typeid = 3",
     			"order" => "inputtime desc",
     			"limit" => array(
     				"number" => 3,
     				"offset" => 0
     			)
     		)); */
     $news1 = News::find(array("typeid = 1", "order" => "inputtime desc"));
     $paginator1 = new \Phalcon\Paginator\Adapter\Model(array("data" => $news1, "limit" => 6, "page" => $dynamicPageBegin));
     $news2 = News::find(array("typeid = 2", "order" => "inputtime desc"));
     $paginator2 = new \Phalcon\Paginator\Adapter\Model(array("data" => $news2, "limit" => 10, "page" => $mediaPageBegin));
     $news3 = News::find(array("typeid = 3", "order" => "inputtime desc"));
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $news3, "limit" => 3, "page" => $schdPageBegin));
     $this->view->page1 = $paginator1->getPaginate();
     $this->view->page2 = $paginator2->getPaginate();
     $this->view->page = $paginator->getPaginate();
     //$this->view->setVar("news3",$news3);
 }
Пример #26
0
 public function post_edit()
 {
     $rules = array('id' => 'required|exists:news', 'title' => 'required|max:255', 'content' => 'required', 'image' => 'image|max:2500');
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->fails()) {
         Messages::add('error', $validation->errors->all());
         return Redirect::to('admin/' . $this->views . '/edit')->with_input();
     } else {
         $article = News::find(Input::get('id'));
         $article->title = Input::get('title');
         $article->url_title = Str::slug(Input::get('title'), '-');
         $article->content = Input::get('content');
         $article->save();
         $upload = Uploadr::upload('image', 'news', $article->id, true);
         if ($upload) {
             WideImage::load('./uploads/' . $upload->filename)->resize(200, 200)->saveToFile('./uploads/' . $upload->small_filename);
             WideImage::load('./uploads/' . $upload->small_filename)->crop('center', 'center', 150, 150)->saveToFile('./uploads/' . $upload->thumb_filename);
         }
         Messages::add('success', 'News article saved');
         return Redirect::to('admin/' . $this->views . '');
     }
 }
Пример #27
0
 /**
  * @param int $count
  * @return News[]|bool
  */
 public function getNews($count = 0)
 {
     $news = News::find();
     if (empty($this->getCategories()) && empty($this->getArticles())) {
         return false;
     } else {
         $where = '';
         if (!empty($this->getCategories())) {
             $where = ['in', 'categoryID', $this->getCategories()];
         }
         if (!empty($this->getArticles())) {
             if (!empty($where)) {
                 $where = ['or', $where, ['in', 'id', $this->getArticles()]];
             } else {
                 $where = ['in', 'id', $this->getArticles()];
             }
         }
         $news->andWhere($where);
     }
     if (!empty($count)) {
         $news->limit($count);
     }
     return $news->orderBy('publishDate DESC')->with('category')->all();
 }
Пример #28
0
 public function delete($id)
 {
     $news = News::find($id);
     $news->delete();
     return Redirect::route('admin.news.index')->with('success', Lang::get('messages.news_delete'));
 }
Пример #29
0
<?php

error_reporting(E_ALL);
require 'app/config/config.php';
$modelManager = new Phalcon\Model\Manager();
$modelManager->setModelsDir(__DIR__ . '/' . $config->phalcon->modelsDir);
Phalcon\Db\Pool::setDefaultDescriptor($config->database);
$categoriesCode = array();
foreach (Categories::find() as $category) {
    $categoriesCode[$category->name] = $category->id;
}
foreach (News::find() as $new) {
    foreach ($new->getNewsCategories() as $newCategory) {
        $newCategory->delete();
    }
    $categories = array();
    if (stripos($new->title, 'conf') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'world') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'Rio') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'phpDay') !== false) {
        $categories['conf'] = true;
    }
    if (stripos($new->title, 'NW') !== false) {
        $categories['conf'] = true;
    }
 public function getEditNewsInfo()
 {
     $id = Input::get('id');
     $allNews = News::find($id);
     return $response[] = array("ban_id" => $allNews['id'], "ban_title" => $allNews['title'], "ban_content" => $allNews['content']);
 }