示例#1
0
 public function execute()
 {
     $errors = array();
     $action = $this->getNewsAction();
     $tp = SJB_System::getTemplateProcessor();
     $categoryId = SJB_Request::getVar('category_sid');
     if (empty($categoryId)) {
         $categoryId = SJB_Request::getVar('category_id');
     }
     $category = SJB_NewsManager::getCategoryBySid($categoryId);
     $tp->assign('category_id', $categoryId);
     $tp->assign('category', $category);
     $allCategories = SJB_NewsManager::getCategories();
     $tp->assign('all_categories', $allCategories);
     /****************** ACTIONS ***************************/
     switch ($action) {
         case 'add':
             $article = new SJB_NewsArticle($_REQUEST);
             $articleAddForm = new SJB_Form($article);
             $articleAddForm->registerTags($tp);
             $formSubmitted = SJB_Request::getVar('form_submit', false);
             if ($formSubmitted && $articleAddForm->isDataValid($errors)) {
                 SJB_NewsDBManager::saveNewsArticle($article);
                 $articleSID = $article->getSID();
                 if ($articleSID) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}&newsAdded=1");
                     exit;
                 } else {
                     $errors[] = 'UNABLE_TO_ADD_ARTICLE';
                 }
             } else {
                 $article = new SJB_NewsArticle($_REQUEST);
                 $article->deleteProperty('category_id');
                 // cause it set in form by get param
                 $articleAddForm = new SJB_Form($article);
                 $articleAddForm->registerTags($tp);
                 $formFields = $articleAddForm->getFormFieldsInfo();
                 $tp->assign('form_fields', $formFields);
                 $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                 $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
             }
             $tp->assign('uploadMaxFilesize', SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->assign('errors', $errors);
             $tp->display('add_article.tpl');
             break;
         case 'edit':
             $itemSID = SJB_Request::getVar('article_sid', false);
             if (!$itemSID) {
                 $errors[] = 'NO_ITEM_SID_PRESENT';
             } else {
                 $articleInfo = SJB_NewsManager::getNewsArticleInfoBySid($itemSID);
                 $articleInfo = array_merge($articleInfo, $_REQUEST);
                 $article = new SJB_NewsArticle($articleInfo);
                 $articleEditForm = new SJB_Form($article);
                 $articleEditForm->registerTags($tp);
                 $formSubmitted = SJB_Request::getVar('form_submit', false);
                 if ($formSubmitted && $articleEditForm->isDataValid($errors)) {
                     $article->setSID($itemSID);
                     // if need to change article category
                     $moveToCategory = SJB_Request::getVar('article_category');
                     if (!empty($moveToCategory) && is_numeric($moveToCategory)) {
                         $article->setPropertyValue('category_id', $moveToCategory);
                     }
                     SJB_NewsDBManager::saveNewsArticle($article);
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}&newsSaved=1");
                 } else {
                     $formFields = $articleEditForm->getFormFieldsInfo();
                     $tp->assign('form_fields', $formFields);
                     $tp->assign('article_sid', $itemSID);
                     $metaDataProvider = SJB_ObjectMother::getMetaDataProvider();
                     $tp->assign("METADATA", array("form_fields" => $metaDataProvider->getFormFieldsMetadata($formFields)));
                 }
             }
             $tp->assign('errors', $errors);
             $tp->assign('category', $category);
             $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
             $tp->display('edit_article.tpl');
             break;
         case 'delete':
             $itemSIDs = SJB_Request::getVar('news');
             foreach ($itemSIDs as $sid => $item) {
                 SJB_NewsManager::deleteArticleBySID($sid);
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}&newsDeleted=1");
             break;
         case 'delete_image':
             $articleSid = SJB_Request::getVar('article_sid');
             SJB_NewsManager::deleteArticleImageByArticleSid($articleSid);
             // get category
             $article = SJB_NewsManager::getNewsArticleBySid($articleSid);
             $categoryId = $article->getCategoryId();
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-news/?action=edit&article_sid={$articleSid}&category_sid={$categoryId}");
             break;
         case 'activate':
             $itemSIDs = SJB_Request::getVar('news');
             foreach ($itemSIDs as $sid => $item) {
                 SJB_NewsManager::activateItemBySID($sid);
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}");
             break;
         case 'deactivate':
             $itemSIDs = SJB_Request::getVar('news');
             foreach ($itemSIDs as $sid => $item) {
                 SJB_NewsManager::deactivateItemBySID($sid);
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}");
             break;
         case 'archive':
             $itemSIDs = SJB_Request::getVar('news');
             foreach ($itemSIDs as $sid => $item) {
                 SJB_NewsManager::moveArticleToArchiveBySid($sid);
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/news-categories/?action=edit&category_sid={$categoryId}");
             break;
         default:
             $page = SJB_Request::getVar('page', 1);
             $itemsPerPage = SJB_Request::getVar('items_per_page', 10);
             $totalNewsCount = SJB_NewsManager::getAllNewsCount($categoryId);
             $pages = ceil($totalNewsCount / $itemsPerPage);
             // get news for current page
             $news = SJB_NewsManager::getNewsByPage($page, $itemsPerPage);
             $tp->assign('news', $news);
             $tp->assign('pages', $pages);
             $tp->assign('items_per_page', $itemsPerPage);
             $tp->assign('current_page', $page);
             $tp->display('manage_news.tpl');
             break;
     }
 }
示例#2
0
 public function execute()
 {
     $errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $i18n = SJB_I18N::getInstance();
     $lang = $i18n->getLanguageData($i18n->getCurrentLanguage());
     $langId = $lang['id'];
     // Category SID incoming as part of URL.
     $categoryId = SJB_Request::getVar("category_sid");
     if (isset($_REQUEST['passed_parameters_via_uri'])) {
         $passed_parameters_via_uri = SJB_UrlParamProvider::getParams();
         $categoryId = isset($passed_parameters_via_uri[0]) ? $passed_parameters_via_uri[0] : null;
     }
     if ($categoryId && $categoryId != 'category') {
         $article = false;
         if (is_null($categoryId)) {
             $errors['ITEM_SID_IS_EMPTY'] = 1;
         } else {
             $article = SJB_NewsManager::getActiveItemBySID($categoryId);
         }
         if (!$article) {
             $errors['ARTICLE_NOT_EXISTS'] = 1;
             echo SJB_System::executeFunction('static_content', 'show_static_content', array('pageid' => '404'));
             return;
         }
         $tp->assign('article', $article);
         $template = 'article_details.tpl';
     } else {
         $categoryId = isset($passed_parameters_via_uri[1]) ? $passed_parameters_via_uri[1] : null;
         // other params in query string
         $searchText = SJB_Request::getVar('search_text', false);
         $current_page = SJB_Request::getVar('page', 1);
         $itemsPerPage = 10;
         $action = SJB_Request::getVar('action');
         if ($action == 'search') {
             // COUNT FOR SEARCH ACTION
             $totalNews = SJB_NewsManager::getAllNewsCountBySearchText($searchText, $langId, true);
         } else {
             $totalNews = SJB_NewsManager::getAllNewsCount($categoryId, $langId, true);
         }
         $pages = ceil($totalNews / $itemsPerPage);
         if ($pages == 0) {
             $pages = 1;
         }
         if ($current_page > $pages) {
             $current_page = $pages;
         }
         if ($action == 'search') {
             // GET ARTICLES FOR SEARCH ACTION
             if ($totalNews == 0) {
                 $articles = array();
             } else {
                 $articles = SJB_NewsManager::searchArticles($searchText, $langId, true);
             }
         } else {
             $articles = SJB_NewsManager::getNewsByPage($current_page, $itemsPerPage, $categoryId, $langId, true);
         }
         $tp->assign('searchText', $searchText);
         $tp->assign('current_page', $current_page);
         $tp->assign('pages', $pages);
         $tp->assign('articles', $articles);
         $categories = SJB_NewsManager::getCategories($langId);
         $countOfNotEmptyCategories = 0;
         foreach ($categories as $category) {
             if ($category['count'] > 0) {
                 $countOfNotEmptyCategories++;
             }
         }
         $showCategoriesBlock = false;
         if ($countOfNotEmptyCategories > 1) {
             $showCategoriesBlock = true;
         }
         $tp->assign('show_categories_block', $showCategoriesBlock);
         $tp->assign('categories', $categories);
         $tp->assign('current_category_sid', $categoryId);
         $template = 'articles_list.tpl';
     }
     $tp->display($template);
 }
示例#3
0
 public function execute()
 {
     $errors = array();
     $messages = array();
     $action = SJB_Request::getVar('action', false);
     $tp = SJB_System::getTemplateProcessor();
     $archiveCategory = SJB_NewsManager::getCategoryByName('Archive');
     $tp->assign('archive_category', $archiveCategory);
     /****************** ACTIONS ***************************/
     switch ($action) {
         case 'save_display_setting':
             // save setting 'show_news_on_main_page'
             $settings = SJB_Request::getVar('settings');
             SJB_Settings::updateSettings($settings);
             $messages[] = 'NEWS_SETTINGS_SUCCESSFULLY_SAVED';
             break;
         case 'add':
             $categoryName = SJB_Request::getVar('category_name');
             if (empty($categoryName)) {
                 $errors['Category Name'] = 'EMPTY_VALUE';
                 break;
             }
             $isExists = SJB_NewsManager::checkExistsCategoryName($categoryName);
             if ($isExists) {
                 $errors['Category Name'] = 'NOT_UNIQUE_VALUE';
                 break;
             }
             if (SJB_NewsManager::addCategory($categoryName)) {
                 $messages[] = 'NEWS_CATEGORY_SUCCESSFULLY_ADDED';
             } else {
                 $errors[] = 'NEWS_CATEGORY_NOT_SAVED';
             }
             break;
         case 'edit':
             $categoryId = SJB_Request::getVar('category_sid');
             $formSubmitted = SJB_Request::getVar('submit');
             if ($formSubmitted) {
                 $newCategoryName = SJB_Request::getVar('category_name');
                 if (!empty($newCategoryName)) {
                     $isExists = SJB_NewsManager::checkExistsCategoryName($newCategoryName);
                     if (!$isExists) {
                         if (SJB_NewsManager::updateCategory($categoryId, $newCategoryName)) {
                             $messages[] = 'NEWS_CATEGORY_SUCCESSFULLY_SAVED';
                         } else {
                             $errors[] = 'NEWS_CATEGORY_NOT_SAVED';
                         }
                     } else {
                         $errors['Category Name'] = 'NOT_UNIQUE_VALUE';
                     }
                 } else {
                     $errors['Category Name'] = 'EMPTY_VALUE';
                 }
                 if ($formSubmitted == 'save_category' && empty($errors)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/news-categories/');
                 }
             }
             if (SJB_Request::getVar('newsAdded', false)) {
                 $messages[] = 'NEWS_SUCCESSFULLY_ADDED';
             }
             if (SJB_Request::getVar('newsDeleted', false)) {
                 $messages[] = 'NEWS_SUCCESSFULLY_DELETED';
             }
             if (SJB_Request::getVar('newsSaved', false)) {
                 $messages[] = 'NEWS_SUCCESSFULLY_SAVED';
             }
             $category = SJB_NewsManager::getCategoryBySid($categoryId);
             $paginator = new SJB_NewsPagination($categoryId, $category['name']);
             $paginator->setItemsCount(SJB_NewsManager::getAllNewsCount($categoryId));
             $articles = SJB_NewsManager::getArticlesByCategorySid($categoryId, $paginator->sortingField, $paginator->sortingOrder, $paginator->currentPage, $paginator->itemsPerPage);
             $i18N = SJB_ObjectMother::createI18N();
             $tp->assign('paginationInfo', $paginator->getPaginationInfo());
             $tp->assign('frontendLanguages', $i18N->getActiveFrontendLanguagesData());
             $tp->assign('messages', $messages);
             $tp->assign('errors', $errors);
             $tp->assign('category', $category);
             $tp->assign('articles', $articles);
             $tp->display('edit_category.tpl');
             break;
         case 'delete':
             $categorySID = SJB_Request::getVar('category_sid');
             if (!empty($categorySID)) {
                 if (SJB_NewsManager::deleteCategoryBySid($categorySID)) {
                     $messages[] = 'NEWS_CATEGORY_SUCCESSFULLY_DELETED';
                 } else {
                     $errors[] = 'NEWS_CATEGORY_NOT_DELETED';
                 }
             }
             break;
         case 'move_up':
             $categoryId = SJB_Request::getVar('category_sid');
             SJB_NewsManager::moveUpCategoryBySID($categoryId);
             break;
         case 'move_down':
             $categoryId = SJB_Request::getVar('category_sid');
             SJB_NewsManager::moveDownCategoryBySID($categoryId);
             break;
     }
     if ($action != 'edit') {
         $categories = SJB_NewsManager::getCategories();
         $showNewsOnMainPage = SJB_Settings::getSettingByName('show_news_on_main_page');
         // get number of news for categories
         foreach ($categories as $key => $category) {
             // remove archive from categories list
             if ($category['name'] == 'Archive') {
                 unset($categories[$key]);
                 continue;
             }
             $counter = SJB_NewsManager::getAllNewsCount($category['sid'], null);
             $categories[$key]['count'] = $counter;
         }
         $tp->assign('categories', $categories);
         $tp->assign('messages', $messages);
         $tp->assign('show_news_on_main_page', $showNewsOnMainPage);
         $tp->assign('number_news_on_main_page', SJB_Settings::getSettingByName('number_news_on_main_page'));
         $tp->assign('main_page_news_display_mode', SJB_Settings::getSettingByName('main_page_news_display_mode'));
         $tp->assign('errors', $errors);
         $tp->display('categories_list.tpl');
     }
 }