Example #1
0
 public function editAction()
 {
     $request = $this->getRequest();
     $cronId = $request->getParam('cron_id');
     $cron = Modules_News_Services_Cron::getById($cronId);
     if (null == $cron) {
         Modules_Core_Services_Exception::error('DATA_NOT_FOUND');
     }
     $webs = Modules_News_Services_Web::getAllWebs();
     $this->view->webs = $webs;
     $categories = explode('-', $cron['category_ids']);
     $cron['main_category_id'] = count($categories) > 0 ? $categories[0] : null;
     $this->view->categories = $categories;
     $this->view->cronData = $cron;
     if ($request->isPost()) {
         $cronData = $request->getPost('cron');
         $cronData = Modules_News_Services_Cron::validate($cronData);
         $categoryIds = '';
         $categories = $request->getPost('categories');
         if (isset($cronData['messages_error']) && $cronData['messages_error']) {
             $this->view->errorMessages = $cronData['messages'];
             $cronData['cron_id'] = $cron['cron_id'];
             $this->view->cronData = $cronData;
             $this->view->cronData = $cronData;
             return;
         }
         if (empty($categories)) {
             $categoryIds = $cronData['main_category_id'];
         } else {
             $categoryIds[] = $cronData['main_category_id'];
             foreach ($categories as $index => $categoryId) {
                 if ($categoryId != $cronData['main_category_id']) {
                     $categoryIds[] = $categoryId;
                 }
             }
             $categoryIds = implode('-', $categoryIds);
         }
         $cron['name'] = $this->view->STRING->escape($cronData['name']);
         $cron['source'] = $this->view->STRING->escape($cronData['source']);
         $cron['website'] = $this->view->STRING->escape($cronData['website']);
         $cron['website_name'] = $this->view->STRING->escape($cronData['website_name']);
         $cron['frequency'] = $this->view->STRING->escape($cronData['frequency']);
         $cron['priority'] = $this->view->STRING->escape($cronData['priority']);
         $cron['category_ids'] = $categoryIds;
         $cron['status'] = $cronData['status'];
         Modules_News_Services_Cron::update($cron);
         Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('cron_actions_edit_success'));
         $this->redirect($this->view->url('news_cron_edit', $cron));
     }
 }
Example #2
0
 /**
  * Edit news article
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $this->view->lang = $request->getParam('lang');
     $articleId = $request->getParam('article_id');
     $article = Modules_News_Services_Article::getById($articleId);
     $configs = Gio_Core_Config_Xml::getConfig('web');
     $this->view->frontendTemplate = $configs->template;
     $this->view->frontendSkin = $configs->skin;
     if (null == $article) {
         Modules_Core_Services_Exception::error('DATA_NOT_FOUND');
     }
     $this->view->categories = Modules_News_Services_Article::getCategoryIds($article);
     $this->view->articleData = $article;
     /**
      * Get source item
      */
     $this->view->sourceArticle = Modules_News_Services_Article::getSource($article);
     /**
      * Web source
      */
     $webSource = Modules_News_Services_Web::getAllWebs();
     $this->view->webSource = $webSource;
     if ($request->isPost()) {
         $user = Gio_Core_Session::getUser();
         $articleData = $request->getPost('article');
         $articleData = Modules_News_Services_Article::validate($articleData);
         if (isset($articleData['messages_error']) && $articleData['messages_error']) {
             $this->view->errorMessages = $articleData['messages'];
             $this->view->articleData = $articleData;
             return;
         }
         $hotArticle = isset($articleData['article_hot']) && $articleData['article_hot'] == 1 ? 1 : 0;
         $photoArticle = isset($articleData['article_photo']) && $articleData['article_photo'] == 1 ? 1 : 0;
         $videoArticle = isset($articleData['article_video']) && $articleData['article_video'] == 1 ? 1 : 0;
         $article = array('article_id' => $articleId, 'title' => $this->view->STRING->escape($articleData['title']), 'slug' => $this->view->STRING->escape($articleData['slug']), 'description' => $articleData['description'], 'content' => $articleData['content'], 'status' => $articleData['status'] == 'active' ? 'active' : 'inactive', 'category_id' => $articleData['category_id'], 'web_id' => $articleData['web_id'], 'link_source' => $this->view->STRING->escape($articleData['link_source']), 'image_url_data' => $articleData['image_url_data'], 'image_url' => $this->view->STRING->escape($articleData['image_url']), 'article_hot' => $hotArticle, 'article_photo' => $photoArticle, 'article_video' => $videoArticle, 'language' => $articleData['language'], 'author' => $this->view->STRING->escape($articleData['author']));
         $sourceItem = isset($articleData['source_item']) ? $articleData['source_item'] : null;
         $categories = $request->getPost('categories');
         Modules_News_Services_Article::update($article, $categories, $sourceItem);
         Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('article_edit_success'));
         $this->redirect($this->view->url('news_article_edit', $article));
     }
 }