public function execute() { $tp = SJB_System::getTemplateProcessor(); $i18n = SJB_I18N::getInstance(); $lang = $i18n->getLanguageData($i18n->getCurrentLanguage()); $langId = $lang['id']; // params $count = SJB_Settings::getSettingByName('number_news_on_main_page'); $result = SJB_NewsManager::getLatestNews($count, $langId, SJB_Settings::getSettingByName('main_page_news_display_mode')); $articles = array(); foreach ($result as $article) { $articles[] = SJB_NewsManager::createTemplateStructureForNewsArticle($article); } // clear unnecessary data unset($result); $tp->assign('count', $count); $tp->assign('articles_count', count($articles)); $tp->assign('articles', $articles); $tp->display('news.tpl'); }
/** * Create structure for templates * * @param SJB_NewsArticle $article * @return array: */ public static function createTemplateStructureForNewsArticle($article) { $articleInfo = parent::getObjectInfo($article); if (is_null(self::$uploadFileManager)) { self::$uploadFileManager = new SJB_UploadFileManager(); } foreach ($article->getProperties() as $property) { if ($property->isComplex()) { $isPropertyEmpty = true; $properties = $property->type->complex->getProperties(); $properties = is_array($properties) ? $properties : array(); foreach ($properties as $subProperty) { if (!empty($articleInfo['user_defined'][$property->getID()][$subProperty->getID()]) && is_array($articleInfo['user_defined'][$property->getID()][$subProperty->getID()])) { foreach ($articleInfo['user_defined'][$property->getID()][$subProperty->getID()] as $subValue) { if (!empty($subValue)) { $isPropertyEmpty = false; } } } } if ($isPropertyEmpty) { $articleInfo['user_defined'][$property->getID()] = ''; } } } $structure = array('sid' => $articleInfo['system']['id'], 'id' => $articleInfo['system']['id'], 'date' => $articleInfo['system']['date'], 'expiration_date' => $articleInfo['system']['expiration_date'], 'active' => $articleInfo['system']['active'], 'image_link' => self::$uploadFileManager->getUploadedFileLink($articleInfo['system']['image'])); if (!empty($articleInfo['system']['subuser_sid'])) { $structure['subuser'] = SJB_UserManager::getUserInfoBySID($articleInfo['system']['subuser_sid']); } $structure['METADATA'] = array('date' => array('type' => 'date'), 'expiration_date' => array('type' => 'date')); $structure = array_merge($structure, $articleInfo['user_defined']); $structure['METADATA'] = array_merge($structure['METADATA'], parent::getObjectMetaData($article)); return array_merge($structure, $articleInfo['user_defined']); }
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); }
private function runTaskScheduler() { // Deactivate Expired Listings & Send Notifications $listingsExpiredID = SJB_ListingManager::getExpiredListingsSID(); foreach ($listingsExpiredID as $listingExpiredID) { SJB_ListingManager::deactivateListingBySID($listingExpiredID, true); $listing = SJB_ListingManager::getObjectBySID($listingExpiredID); $listingInfo = SJB_ListingManager::createTemplateStructureForListing($listing); if (SJB_UserNotificationsManager::isUserNotifiedOnListingExpiration($listing->getUserSID())) { SJB_Notifications::sendUserListingExpiredLetter($listingInfo); } // notify admin SJB_AdminNotifications::sendAdminListingExpiredLetter($listingInfo); } $listingsDeactivatedID = array(); if (SJB_Settings::getSettingByName('automatically_delete_expired_listings')) { $listingsDeactivatedID = SJB_ListingManager::getDeactivatedListingsSID(); foreach ($listingsDeactivatedID as $listingID) { SJB_ListingManager::deleteListingBySID($listingID); } } SJB_ListingManager::unFeaturedListings(); SJB_ListingManager::unPriorityListings(); SJB_Cache::getInstance()->clean('matchingAnyTag', array(SJB_Cache::TAG_LISTINGS)); /////////////////////////// Send remind notifications about expiration of LISTINGS // 1. get user sids and days count of 'remind listing notification' setting = 1 from user_notifications table // 2. foreach user: // - get listings with that expiration remind date // - check every listing sid in DB table of sended. If sended - remove from send list // - send notification with listings to user // - write listings sid in DB table of sended notifications $notificationData = SJB_UserNotificationsManager::getUsersAndDaysOnListingExpirationRemind(); foreach ($notificationData as $elem) { $userSID = $elem['user_sid']; $days = $elem['days']; $listingSIDs = SJB_ListingManager::getListingsIDByDaysLeftToExpired($userSID, $days); if (empty($listingSIDs)) { continue; } $listingsInfo = array(); // check listings remind sended foreach ($listingSIDs as $key => $sid) { if (SJB_ListingManager::isListingNotificationSended($sid)) { unset($listingSIDs[$key]); continue; } $info = SJB_ListingManager::getListingInfoBySID($sid); $listingsInfo[$sid] = $info; } if (!empty($listingsInfo)) { // now only unsended listings we have in array // send listing notification foreach ($listingSIDs as $sid) { SJB_Notifications::sendRemindListingExpirationLetter($userSID, $sid, $days); } // write listing id in DB table of sended notifications SJB_ListingManager::saveListingIDAsSendedNotificationsTable($listingSIDs); } } // Send Notifications for Expired Contracts $contractsExpiredID = SJB_ContractManager::getExpiredContractsID(); foreach ($contractsExpiredID as $contractExpiredID) { $contractInfo = SJB_ContractManager::getInfo($contractExpiredID); $productInfo = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']); $userInfo = SJB_UserManager::getUserInfoBySID($contractInfo['user_sid']); $serializedExtraInfo = unserialize($contractInfo['serialized_extra_info']); if (!empty($serializedExtraInfo['featured_profile']) && !empty($userInfo['featured'])) { $contracts = SJB_ContractManager::getAllContractsInfoByUserSID($userInfo['sid']); $isFeatured = 0; foreach ($contracts as $contract) { if ($contract['id'] != $contractExpiredID) { $serializedExtraInfo = unserialize($contract['serialized_extra_info']); if (!empty($serializedExtraInfo['featured'])) { $isFeatured = 1; } } } if (!$isFeatured) { SJB_UserManager::removeFromFeaturedBySID($userInfo['sid']); } } if (SJB_UserNotificationsManager::isUserNotifiedOnContractExpiration($contractInfo['user_sid'])) { SJB_Notifications::sendUserContractExpiredLetter($userInfo, $contractInfo, $productInfo); } // notify admin SJB_AdminNotifications::sendAdminUserContractExpiredLetter($userInfo['sid'], $contractInfo, $productInfo); SJB_ContractManager::deleteContract($contractExpiredID, $contractInfo['user_sid']); } //////////////////////// Send remind notifications about expiration of contracts // 1. get user sids and days count of 'remind subscription notification' setting = 1 from user_notifications table // 2. foreach user: // - get contracts with that expiration remind date // - check every contract sid in DB table of sended. If sended - remove from send list // - send notification with contracts to user // - write contract sid in DB table of sended contract notifications $notificationData = SJB_UserNotificationsManager::getUsersAndDaysOnSubscriptionExpirationRemind(); foreach ($notificationData as $elem) { $userSID = $elem['user_sid']; $days = $elem['days']; $contractSIDs = SJB_ContractManager::getContractsIDByDaysLeftToExpired($userSID, $days); if (empty($contractSIDs)) { continue; } $contractsInfo = array(); // check contracts sended foreach ($contractSIDs as $key => $sid) { if (SJB_ContractManager::isContractNotificationSended($sid)) { unset($contractSIDs[$key]); continue; } $info = SJB_ContractManager::getInfo($sid); $info['extra_info'] = !empty($info['serialized_extra_info']) ? unserialize($info['serialized_extra_info']) : ''; $contractsInfo[$sid] = $info; } if (!empty($contractsInfo)) { // now only unsended contracts we have in array // send contract notification foreach ($contractSIDs as $sid) { SJB_Notifications::sendRemindSubscriptionExpirationLetter($userSID, $contractsInfo[$sid], $days); } // write contract id in DB table of sended contract notifications SJB_ContractManager::saveContractIDAsSendedNotificationsTable($contractSIDs); } } // delete applications with no employer and job seeker $emptyApplications = SJB_DB::query('SELECT `id` FROM `applications` WHERE `show_js` = 0 AND `show_emp` = 0'); foreach ($emptyApplications as $application) { SJB_Applications::remove($application['id']); } // NEWS $expiredNews = SJB_NewsManager::getExpiredNews(); foreach ($expiredNews as $article) { SJB_NewsManager::deactivateItemBySID($article['sid']); } // LISTING XML IMPORT SJB_XmlImport::runImport(); // UPDATE PAGES WITH FUNCTION EQUAL BROWSE(e.g. /browse-by-city/) SJB_BrowseDBManager::rebuildBrowses(); //-------------------sitemap generator--------------------// SJB_System::executeFunction('miscellaneous', 'sitemap_generator'); // CLEAR `error_log` TABLE $errorLogLifetime = SJB_System::getSettingByName('error_log_lifetime'); $lifeTime = strtotime("-{$errorLogLifetime} days"); if ($lifeTime > 0) { SJB_DB::query('DELETE FROM `error_log` WHERE `date` < ?t', $lifeTime); } SJB_Settings::updateSetting('task_scheduler_last_executed_date', $this->currentDate); $this->tp->assign('expired_listings_id', $listingsExpiredID); $this->tp->assign('deactivated_listings_id', $listingsDeactivatedID); $this->tp->assign('expired_contracts_id', $contractsExpiredID); $this->tp->assign('notified_saved_searches_id', $this->notifiedSavedSearchesSID); $schedulerLog = $this->tp->fetch('task_scheduler_log.tpl'); SJB_HelperFunctions::writeCronLogFile('task_scheduler.log', $schedulerLog); SJB_DB::query('INSERT INTO `task_scheduler_log` (`last_executed_date`, `notifieds_sent`, `expired_listings`, `expired_contracts`, `log_text`) VALUES ( NOW(), ?n, ?n, ?n, ?s)', count($this->notifiedSavedSearchesSID), count($listingsExpiredID), count($contractsExpiredID), $schedulerLog); SJB_System::getModuleManager()->executeFunction('social', 'linkedin'); SJB_System::getModuleManager()->executeFunction('social', 'facebook'); SJB_System::getModuleManager()->executeFunction('classifieds', 'linkedin'); SJB_System::getModuleManager()->executeFunction('classifieds', 'facebook'); SJB_System::getModuleManager()->executeFunction('classifieds', 'twitter'); SJB_Event::dispatch('task_scheduler_run'); }
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; } }
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'); } }