public function testFaqItemName() { Mock::generate('DbService'); $dbService = new MockDbService(); $faqService = new FaqService(); $faqService->dbService = $dbService; $faq = new Faq(); $params = array('title' => 'My FAQ entry & _+'); $dbService->setReturnValue('saveObject', $faq); $result = $faqService->saveFaq($faq, $params); $this->assertEqual('my-faq-entry-and', $faq->faqurl); }
public function build_view(HTTPRequestCustom $request) { $authorized_categories = FaqService::get_authorized_categories(Category::ROOT_CATEGORY); $mode = $request->get_getstring('sort', FaqUrlBuilder::DEFAULT_SORT_MODE); $field = $request->get_getstring('field', FaqUrlBuilder::DEFAULT_SORT_FIELD); $sort_mode = $mode == 'asc' ? 'ASC' : 'DESC'; switch ($field) { case 'question': $sort_field = FaqQuestion::SORT_ALPHABETIC; break; default: $sort_field = FaqQuestion::SORT_DATE; break; } $result = PersistenceContext::get_querier()->select('SELECT * FROM ' . FaqSetup::$faq_table . ' faq LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = faq.author_user_id WHERE approved = 0 AND faq.id_category IN :authorized_categories ' . (!FaqAuthorizationsService::check_authorizations()->moderation() ? ' AND faq.author_user_id = :user_id' : '') . ' ORDER BY ' . $sort_field . ' ' . $sort_mode, array('authorized_categories' => $authorized_categories, 'user_id' => AppContext::get_current_user()->get_id())); $this->tpl->put_all(array('C_QUESTIONS' => $result->get_rows_count() > 0, 'C_PENDING' => true, 'C_MORE_THAN_ONE_QUESTION' => $result->get_rows_count() > 1, 'C_DISPLAY_TYPE_ANSWERS_HIDDEN' => FaqConfig::load()->is_display_type_answers_hidden(), 'QUESTIONS_NUMBER' => $result->get_rows_count())); while ($row = $result->fetch()) { $faq_question = new FaqQuestion(); $faq_question->set_properties($row); $this->tpl->assign_block_vars('questions', $faq_question->get_array_tpl_vars()); } $result->dispose(); $this->build_sorting_form($field, $mode); }
private function get_faq_question(HTTPRequestCustom $request) { $id = $request->get_int('id', 0); if (!empty($id)) { try { $this->faq_question = FaqService::get_question('WHERE id=:id', array('id' => $id)); } catch (RowNotFoundException $e) { } } }
private function get_faq_question(HTTPRequestCustom $request) { $id = $request->get_int('id', 0); if (!empty($id)) { try { return FaqService::get_question('WHERE id=:id', array('id' => $id)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } } }
public function get_feed_data_struct($idcat = 0, $name = '') { if (FaqService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) { $querier = PersistenceContext::get_querier(); $category = FaqService::get_categories_manager()->get_categories_cache()->get_category($idcat); $site_name = GeneralConfig::load()->get_site_name(); $site_name = $idcat != Category::ROOT_CATEGORY ? $site_name . ' : ' . $category->get_name() : $site_name; $feed_module_name = LangLoader::get_message('module_title', 'common', 'faq'); $data = new FeedData(); $data->set_title($feed_module_name . ' - ' . $site_name); $data->set_date(new Date()); $data->set_link(SyndicationUrlBuilder::rss('faq', $idcat)); $data->set_host(HOST); $data->set_desc($feed_module_name . ' - ' . $site_name); $data->set_lang(LangLoader::get_message('xml_lang', 'main')); $data->set_auth_bit(Category::READ_AUTHORIZATIONS); $categories = FaqService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true); $ids_categories = array_keys($categories); $results = $querier->select('SELECT faq.id, faq.id_category, faq.question, faq.answer, faq.creation_date, cat.rewrited_name AS rewrited_name_cat FROM ' . FaqSetup::$faq_table . ' faq LEFT JOIN ' . FaqSetup::$faq_cats_table . ' cat ON cat.id = faq.id_category WHERE approved = 1 AND faq.id_category IN :ids_categories ORDER BY faq.creation_date DESC', array('ids_categories' => $ids_categories)); foreach ($results as $row) { $row['rewrited_name_cat'] = !empty($row['id_category']) ? $row['rewrited_name_cat'] : 'root'; $link = FaqUrlBuilder::display($row['id_category'], $row['rewrited_name_cat'], $row['id']); $item = new FeedItem(); $item->set_title($row['question']); $item->set_link($link); $item->set_guid($link); $item->set_desc(FormatingHelper::second_parse($row['answer'])); $item->set_date(new Date($row['creation_date'], Timezone::SERVER_TIMEZONE)); $item->set_auth(FaqService::get_categories_manager()->get_heritated_authorizations($row['id_category'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY)); $data->add_item($item); } $results->dispose(); return $data; } }
public function get_menu_content() { //Create file template $tpl = new FileTemplate('faq/FaqModuleMiniMenu.tpl'); //Assign the lang file to the tpl $tpl->add_lang(LangLoader::get('common', 'faq')); //Load module cache $faq_cache = FaqCache::load(); //Get authorized categories for the current user $authorized_categories = FaqService::get_authorized_categories(Category::ROOT_CATEGORY); $categories = array_intersect($faq_cache->get_categories(), $authorized_categories); if (!empty($categories)) { $id_category = $categories[array_rand($categories)]; $category_questions = $faq_cache->get_category_questions($id_category); $random_question = $category_questions[array_rand($category_questions)]; if (!empty($random_question)) { $category = FaqService::get_categories_manager()->get_categories_cache()->get_category($id_category); $tpl->put_all(array('C_QUESTION' => true, 'QUESTION' => $random_question['question'], 'U_LINK' => FaqUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $random_question['id'])->rel())); } } return $tpl->render(); }
private function is_authorized($bit, $mode = Authorizations::AUTH_CHILD_PRIORITY) { $auth = FaqService::get_categories_manager()->get_heritated_authorizations($this->id_category, $bit, $mode); return AppContext::get_current_user()->check_auth($auth, $bit); }
protected function get_categories_manager() { return FaqService::get_categories_manager(); }
public function get_category() { return FaqService::get_categories_manager()->get_categories_cache()->get_category($this->id_category); }
private function save() { $this->config->set_categories_number_per_page($this->form->get_value('categories_number_per_page')); $this->config->set_columns_number_per_line($this->form->get_value('columns_number_per_line')); $this->config->set_display_type($this->form->get_value('display_type')->get_raw_value()); $this->config->set_root_category_description($this->form->get_value('root_category_description')); $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array()); FaqConfig::save(); FaqService::get_categories_manager()->regenerate_cache(); FaqCache::invalidate(); }
public function get_search_request($args) { $authorized_categories = FaqService::get_authorized_categories(Category::ROOT_CATEGORY); $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1; return "SELECT " . $args['id_search'] . " AS id_search,\n\t\t\tf.id AS id_content,\n\t\t\tf.question AS title,\n\t\t\t( 2 * FT_SEARCH_RELEVANCE(f.question, '" . $args['search'] . "') + FT_SEARCH_RELEVANCE(f.answer, '" . $args['search'] . "' )) / 3 * " . $weight . " AS relevance,\n\t\t\tCONCAT('" . PATH_TO_ROOT . "/faq/index.php?url=/', id_category, '-', IF(id_category != 0, cat.rewrited_name, 'root'), '/#question', f.id) AS link\n\t\t\tFROM " . FaqSetup::$faq_table . " f\n\t\t\tLEFT JOIN " . FaqSetup::$faq_cats_table . " cat ON f.id_category = cat.id\n\t\t\tWHERE ( FT_SEARCH(f.question, '" . $args['search'] . "') OR FT_SEARCH(f.answer, '" . $args['search'] . "') )\n\t\t\tAND approved = 1\n\t\t\tAND id_category IN (" . implode(", ", $authorized_categories) . ")\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT 100 OFFSET 0"; }
public function url_mappings() { $db_querier = PersistenceContext::get_querier(); $phpboost_4_1_release_date = new Date('2014-07-15'); if (GeneralConfig::load()->get_site_install_date()->is_anterior_to($phpboost_4_1_release_date)) { // Articles if (class_exists('ArticlesService')) { $this->urls_mappings[] = new UrlMapping('^articles/articles.php$', '/articles/', 'L,R=301'); $categories = ArticlesService::get_categories_manager()->get_categories_cache()->get_categories(); foreach ($categories as $id => $category) { $this->urls_mappings[] = new UrlMapping('^articles/articles-' . $id . '\\+([^.]*).php$', '/articles/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301'); $this->urls_mappings[] = new UrlMapping('^articles/articles-' . $id . '-([0-9]*)\\+([^.]*).php$', '/articles/' . $id . '-' . $category->get_rewrited_name() . '/$1-$2/', 'L,R=301'); } } // Calendar if (class_exists('CalendarService')) { $this->urls_mappings[] = new UrlMapping('^calendar/calendar$', '/calendar/', 'L,R=301'); $this->urls_mappings[] = new UrlMapping('^calendar/calendar-([0-9]+)-([0-9]+)-([0-9]+)-?([0-9]*).php$', '/calendar/$3-$2-$1/', 'L,R=301'); } // Guestbook if (class_exists('GuestbookService')) { $this->urls_mappings[] = new UrlMapping('^guestbook/guestbook.php$', '/guestbook/', 'L,R=301'); } // News if (class_exists('NewsService')) { $this->urls_mappings[] = new UrlMapping('^news/news.php$', '/news/', 'L,R=301'); $categories = NewsService::get_categories_manager()->get_categories_cache()->get_categories(); foreach ($categories as $id => $category) { $this->urls_mappings[] = new UrlMapping('^news/news-' . $id . '\\+([^.]*).php$', '/news/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301'); $this->urls_mappings[] = new UrlMapping('^news/news-' . $id . '-([0-9]*)\\+([^.]*).php$', '/news/' . $id . '-' . $category->get_rewrited_name() . '/$1-$2/', 'L,R=301'); } } } // Download if (class_exists('DownloadService')) { $this->urls_mappings[] = new UrlMapping('^download/download\\.php$', '/download/', 'L,R=301'); $categories = DownloadService::get_categories_manager()->get_categories_cache()->get_categories(); $result = $db_querier->select_rows(PREFIX . 'download', array('id', 'id_category', 'rewrited_name')); while ($row = $result->fetch()) { $category = $categories[$row['id_category']]; if (!empty($category)) { $this->urls_mappings[] = new UrlMapping('^download/download-' . $row['id'] . '(-?[^.]*)\\.php$', '/download/' . $category->get_id() . '-' . $category->get_rewrited_name() . '/' . $row['id'] . '-' . $row['rewrited_name'], 'L,R=301'); $this->urls_mappings[] = new UrlMapping('^download/file-' . $row['id'] . '(-?[^.]*)\\.php$', '/download/' . $category->get_id() . '-' . $category->get_rewrited_name() . '/' . $row['id'] . '-' . $row['rewrited_name'], 'L,R=301'); } } $result->dispose(); foreach ($categories as $id => $category) { $this->urls_mappings[] = new UrlMapping('^download/category-' . $id . '(-?[^.]*)\\.php$', '/download/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301'); } } // FAQ if (class_exists('FaqService')) { $this->urls_mappings[] = new UrlMapping('^faq/faq\\.php$', '/faq/', 'L,R=301'); $categories = FaqService::get_categories_manager()->get_categories_cache()->get_categories(); foreach ($categories as $id => $category) { $this->urls_mappings[] = new UrlMapping('^faq/faq-' . $category->get_id() . '(\\+?[^.]*)\\.php$', '/faq/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301'); } } // Shoutbox if (class_exists('ShoutboxService')) { $this->urls_mappings[] = new UrlMapping('^shoutbox/shoutbox\\.php$', '/shoutbox/', 'L,R=301'); } // Web if (class_exists('WebService')) { $this->urls_mappings[] = new UrlMapping('^web/web\\.php$', '/web/', 'L,R=301'); $categories = WebService::get_categories_manager()->get_categories_cache()->get_categories(); $result = $db_querier->select_rows(PREFIX . 'web', array('id', 'id_category', 'rewrited_name')); while ($row = $result->fetch()) { $category = $categories[$row['id_category']]; if (!empty($category)) { $this->urls_mappings[] = new UrlMapping('^web/web-' . $category->get_id() . '-' . $row['id'] . '([^.]*)\\.php$', '/web/' . $category->get_id() . '-' . $category->get_rewrited_name() . '/' . $row['id'] . '-' . $row['rewrited_name'], 'L,R=301'); } } $result->dispose(); foreach ($categories as $id => $category) { $this->urls_mappings[] = new UrlMapping('^web/web-' . $category->get_id() . '(-?[^.]*)\\.php$', '/web/' . $id . '-' . $category->get_rewrited_name() . '/', 'L,R=301'); } } return new UrlMappings($this->urls_mappings); }
/** * @desc Return the categories manager. */ public static function get_categories_manager() { if (self::$categories_manager === null) { $categories_items_parameters = new CategoriesItemsParameters(); $categories_items_parameters->set_table_name_contains_items(FaqSetup::$faq_table); self::$categories_manager = new CategoriesManager(FaqCategoriesCache::load(), $categories_items_parameters); } return self::$categories_manager; }
private function generate_response() { $response = new SiteDisplayResponse($this->tpl); $graphical_environment = $response->get_graphical_environment(); $graphical_environment->set_page_title($this->get_category()->get_name(), $this->lang['module_title']); $graphical_environment->get_seo_meta_data()->set_description($this->get_category()->get_description()); $graphical_environment->get_seo_meta_data()->set_canonical_url(FaqUrlBuilder::display_category($this->get_category()->get_id(), $this->get_category()->get_rewrited_name(), AppContext::get_request()->get_getint('page', 1))); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['module_title'], FaqUrlBuilder::home()); $categories = array_reverse(FaqService::get_categories_manager()->get_parents($this->get_category()->get_id(), true)); foreach ($categories as $id => $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $breadcrumb->add($category->get_name(), FaqUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())); } } return $response; }
private function generate_response(View $tpl) { $faq_question = $this->get_faq_question(); $response = new SiteDisplayResponse($tpl); $graphical_environment = $response->get_graphical_environment(); $breadcrumb = $graphical_environment->get_breadcrumb(); $breadcrumb->add($this->lang['module_title'], FaqUrlBuilder::home()); if ($faq_question->get_id() === null) { $graphical_environment->set_page_title($this->lang['faq.add'], $this->lang['module_title']); $breadcrumb->add($this->lang['faq.add'], FaqUrlBuilder::add($faq_question->get_id_category())); $graphical_environment->get_seo_meta_data()->set_description($this->lang['faq.add']); $graphical_environment->get_seo_meta_data()->set_canonical_url(FaqUrlBuilder::add($faq_question->get_id_category())); } else { $graphical_environment->set_page_title($this->lang['faq.edit'], $this->lang['module_title']); $graphical_environment->get_seo_meta_data()->set_description($this->lang['faq.edit']); $graphical_environment->get_seo_meta_data()->set_canonical_url(FaqUrlBuilder::edit($faq_question->get_id())); $categories = array_reverse(FaqService::get_categories_manager()->get_parents($faq_question->get_id_category(), true)); foreach ($categories as $id => $category) { if ($category->get_id() != Category::ROOT_CATEGORY) { $breadcrumb->add($category->get_name(), FaqUrlBuilder::display_category($category->get_id(), $category->get_rewrited_name())); } } $category = $faq_question->get_category(); $breadcrumb->add($faq_question->get_question(), FaqUrlBuilder::display($category->get_id(), $category->get_rewrited_name(), $faq_question->get_id())); $breadcrumb->add($this->lang['faq.edit'], FaqUrlBuilder::edit($faq_question->get_id())); } return $response; }
public function __construct() { parent::__construct(FaqService::get_categories_manager()); }