Skip to content

Commit

Permalink
#3377 - Multicategories: add block with categories to context
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Dec 9, 2021
1 parent 7425355 commit f94739a
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 12 deletions.
4 changes: 2 additions & 2 deletions inc/classes/BxDolCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function add($sModule, $iProfileId, $sValue, $iObject, $bAutoActivation)
return $this->_oDb->add($sModule, $iProfileId, $sValue, $iObject, $bAutoActivation);
}

public function getUrl ($sModule, $sValue)
public function getUrl ($sModule, $sValue, $sAddParams = '')
{
return BX_DOL_URL_ROOT . 'searchKeyword.php?keyword=' . rawurlencode($sValue) . '&cat=multi&section=' . $sModule;
return BX_DOL_URL_ROOT . 'searchKeyword.php?keyword=' . rawurlencode($sValue) . '&cat=multi&section=' . $sModule . $sAddParams;
}
}

Expand Down
23 changes: 21 additions & 2 deletions inc/classes/BxDolCategoriesQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public function getData($aParams = array())
case 'by_module_with_num':
$aMethod['name'] = 'getAll';
$aMethod['params'][1] = array(
'module' => $aParams['module'],

'module' => $aParams['module']
);

$oModule = BxDolModule::getInstance($aParams['module']);
Expand All @@ -79,6 +78,26 @@ public function getData($aParams = array())
$sOrderClause = "`num` DESC";
break;

case 'by_module&context_with_num':
$aMethod['name'] = 'getAll';
$aMethod['params'][1] = array(
'module' => $aParams['module'],
'context_id' => -$aParams['context_id'],
);

$oModule = BxDolModule::getInstance($aParams['module']);
$CNF = $oModule->_oConfig->CNF;

$sSelectClause = "`sc`.`value`, COUNT(`sc`.`id`) as `num`";
$sJoinClause = " INNER JOIN `sys_categories2objects` `soc` ON `sc`.`id` = `soc`.`category_id`";
$sJoinClause .= " INNER JOIN `" . $CNF['TABLE_ENTRIES'] . "` `data` ON `soc`.`object_id` = `data`.`id` AND `data`.`" . $CNF['FIELD_ALLOW_VIEW_TO'] . "` = :context_id";
if (isset($CNF['FIELD_STATUS']))
$sJoinClause .= " AND `data`.`" . $CNF['FIELD_STATUS'] . "` = 'active' ";
$sWhereClause = " AND `sc`.`status` = 'active' AND `soc`.`module` = :module";
$sGroupClause = "`sc`.`id`";
$sOrderClause = "`num` DESC";
break;

case 'by_module_and_object':
$aMethod['name'] = 'getColumn';
$aMethod['params'][1] = array(
Expand Down
5 changes: 3 additions & 2 deletions modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function serviceGetSafeServices()
'EntityLocation' => '',
'EntityComments' => '',
'EntityAttachments' => '',
'CategoriesMultiList' => '',
// menu
'EntityAllActions' => '',
'EntityActions' => '',
Expand Down Expand Up @@ -2138,7 +2139,7 @@ public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact

/**
* @page service Service Calls
* @section bx_base_general Base Text
* @section bx_base_general Base General
* @subsection bx_base_general-page_blocks Page Blocks
* @subsubsection bx_base_general-categories_multi_list categories_multi_list
*
Expand Down Expand Up @@ -2172,7 +2173,7 @@ public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
if (!$aVars['bx_repeat:cats'])
return '';

return $this->_oTemplate->parseHtmlByName('category_list.html', $aVars);
return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
}

/**
Expand Down
49 changes: 48 additions & 1 deletion modules/base/text/classes/BxBaseModTextModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,56 @@ public function serviceGetSafeServices()
'BrowseTop' => '',
'BrowseUpdated' => '',
'BrowseAuthor' => '',
'CategoriesMultiList' => ''
'CategoriesMultiListContext' => ''
));
}

/**
* @page service Service Calls
* @section bx_base_text Base Text
* @subsection bx_base_general-page_blocks Page Blocks
* @subsubsection bx_base_general-categories_multi_list_context categories_multi_list_context
*
* @code bx_srv('bx_posts', 'categories_multi_list_context', [...]); @endcode
*
* Display multi-categorories block with number of posts in each category for current context
* @param $bDisplayEmptyCats display empty categories
*
* @see BxBaseModGeneralModule::serviceCategoriesMultiListContext
*/
/**
* @ref bx_base_general-categories_multi_list_context "categories_multi_list_context"
*/
public function serviceCategoriesMultiListContext($iProfileId = 0, $bDisplayEmptyCats = true)
{
if ($iProfileId == 0)
$iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);

$oCategories = BxDolCategories::getInstance();
$aCats = $oCategories->getData([
'type' => 'by_module&context_with_num',
'module' => $this->getName(),
'context_id' => $iProfileId
]
);
$aVars = array('bx_repeat:cats' => array());
foreach ($aCats as $oCat) {
$sValue = $oCat['value'];
$iNum = $oCat['num'];

$aVars['bx_repeat:cats'][] = array(
'url' => $oCategories->getUrl($this->getName(), $sValue, '&context_id=' . $iProfileId),
'name' => _t($sValue),
'value' => $sValue,
'num' => $iNum,
);
}

if (!$aVars['bx_repeat:cats'])
return '';

return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
}

/**
* @page service Service Calls
Expand Down
8 changes: 8 additions & 0 deletions modules/base/text/classes/BxBaseModTextSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ function __construct($sMode = '', $aParams = array())
}
}

protected function checkRestrictionsForContext($sMode, $aParams, $oProfileAuthor){
if(bx_get('context_id')){
$aParams['context'] = bx_get('context_id');
$oProfileAuthor = null;
$this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor);
}
}

function getAlterOrder()
{
$CNF = &$this->oModule->_oConfig->CNF;
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/forum/classes/BxForumSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function __construct($sMode = '', $aParams = array())
break;

case '': // search results
$this->checkRestrictionsForContext($sMode, $aParams, $oProfileAuthor);
$this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
$this->aCurrent['title'] = _t('_bx_forum');
unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/forum/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@
<string name="_bx_forum_page_block_title_sys_entries_of_author"><![CDATA[Discussions of author]]></string>
<string name="_bx_forum_page_block_title_entries_in_context"><![CDATA[Discussions in <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_forum_page_block_title_sys_entries_in_context"><![CDATA[Discussions in context]]></string>
<string name="_bx_forum_page_block_title_sys_multi_categories_in_context"><![CDATA[Multi categories in context]]></string>
<string name="_bx_forum_page_block_title_multi_categories_in_context"><![CDATA[Categories in <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_forum_page_block_title_entries_actions"><![CDATA[Discussions actions]]></string>
<string name="_bx_forum_page_block_title_sys_entry_context"><![CDATA[Posted in]]></string>
<string name="_bx_forum_page_block_title_entry_context"><![CDATA[Posted in]]></string>
Expand Down
3 changes: 2 additions & 1 deletion modules/boonex/forum/install/sql/enable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module
('bx_forum_context', 'discussions-context', '_bx_forum_page_title_sys_entries_in_context', '_bx_forum_page_title_entries_in_context', 'bx_forum', 5, 2147483647, 1, '', '', '', '', 0, 1, 0, 'BxForumPageAuthor', 'modules/boonex/forum/classes/BxForumPageAuthor.php');

INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
('bx_forum_context', 1, @sName, '_bx_forum_page_block_title_sys_entries_in_context', '_bx_forum_page_block_title_entries_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_forum\";s:6:\"method\";s:14:\"browse_context\";}', 0, 0, 1, 1);
('bx_forum_context', 1, @sName, '_bx_forum_page_block_title_sys_entries_in_context', '_bx_forum_page_block_title_entries_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_forum\";s:6:\"method\";s:14:\"browse_context\";}', 0, 0, 1, 1),
('bx_forum_context', 1, @sName, '_bx_forum_page_block_title_sys_multi_categories_in_context', '_bx_forum_page_block_title_multi_categories_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_forum\";s:6:\"method\";s:29:\"categories_multi_list_context\";}', 0, 0, 0, 2);

-- PAGE: module home
INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module`, `cover`, `cover_image`, `type_id`, `layout_id`, `submenu`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `inj_head`, `inj_footer`, `sticky_columns`, `deletable`, `override_class_name`, `override_class_file`) VALUES
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/posts/classes/BxPostsSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function __construct($sMode = '', $aParams = array())
break;

case '': // search results
$this->checkRestrictionsForContext($sMode, $aParams, $oProfileAuthor);
$this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
$this->aCurrent['title'] = _t('_bx_posts');
unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
Expand Down
4 changes: 3 additions & 1 deletion modules/boonex/posts/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<string name="_bx_posts_acl_action_view_entry"><![CDATA[View Post]]></string>
<string name="_bx_posts_acl_action_set_thumb"><![CDATA[Set Post Header Image]]></string>
<string name="_bx_posts_acl_action_edit_any_entry"><![CDATA[Edit Any Post]]></string>
<string name="_bx_posts_acl_action_delete_any_entry"><![CDATA[Delete Any Account]]></string>
<string name="_bx_posts_page_block_title_sys_entries_in_context"><![CDATA[Delete Any Post]]></string>

<string name="_bx_posts_page_title_sys_create_entry"><![CDATA[New Post]]></string>
<string name="_bx_posts_page_title_create_entry"><![CDATA[New Post]]></string>
Expand Down Expand Up @@ -168,6 +168,8 @@
<string name="_bx_posts_page_block_title_sys_entries_of_author"><![CDATA[Posts of author]]></string>
<string name="_bx_posts_page_block_title_entries_in_context"><![CDATA[Posts in <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_posts_page_block_title_sys_entries_in_context"><![CDATA[Posts in context]]></string>
<string name="_bx_posts_page_block_title_sys_multi_categories_in_context"><![CDATA[Multi categories in context]]></string>
<string name="_bx_posts_page_block_title_multi_categories_in_context"><![CDATA[Categories in <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_posts_page_block_title_entries_actions"><![CDATA[Posts actions]]></string>
<string name="_bx_posts_page_block_title_browse_cmts"><![CDATA[Posts' Comments]]></string>
<string name="_bx_posts_page_title_sys_manage"><![CDATA[Manage Own]]></string>
Expand Down
3 changes: 2 additions & 1 deletion modules/boonex/posts/install/sql/enable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module
('bx_posts_context', 'posts-context', '_bx_posts_page_title_sys_entries_in_context', '_bx_posts_page_title_entries_in_context', 'bx_posts', 5, 2147483647, 1, '', '', '', '', 0, 1, 0, 'BxPostsPageAuthor', 'modules/boonex/posts/classes/BxPostsPageAuthor.php');

INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
('bx_posts_context', 1, 'bx_posts', '_bx_posts_page_block_title_sys_entries_in_context', '_bx_posts_page_block_title_entries_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_posts\";s:6:\"method\";s:14:\"browse_context\";}', 0, 0, 1, 1);
('bx_posts_context', 1, 'bx_posts', '_bx_posts_page_block_title_sys_entries_in_context', '_bx_posts_page_block_title_entries_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_posts\";s:6:\"method\";s:14:\"browse_context\";}', 0, 0, 1, 1),
('bx_posts_context', 1, 'bx_posts', '_bx_posts_page_block_title_sys_multi_categories_in_context', '_bx_posts_page_block_title_multi_categories_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_posts\";s:6:\"method\";s:29:\"categories_multi_list_context\";}', 0, 0, 0, 2);

-- PAGE: module home

Expand Down
1 change: 1 addition & 0 deletions modules/boonex/reviews/classes/BxReviewsSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function __construct($sMode = '', $aParams = array())
break;

case '': // search results
$this->checkRestrictionsForContext($sMode, $aParams, $oProfileAuthor);
$this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
$this->aCurrent['title'] = _t('_bx_reviews');
unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/reviews/install/langs/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
<string name="_bx_reviews_page_block_title_sys_entries_of_author"><![CDATA[Reviews of author]]></string>
<string name="_bx_reviews_page_block_title_entries_in_context"><![CDATA[Reviews in <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_reviews_page_block_title_sys_entries_in_context"><![CDATA[Reviews in context]]></string>
<string name="_bx_reviews_page_block_title_sys_multi_categories_in_context"><![CDATA[Multi categories in context]]></string>
<string name="_bx_reviews_page_block_title_multi_categories_in_context"><![CDATA[Categories in <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_reviews_page_block_title_entries_actions"><![CDATA[Reviews actions]]></string>
<string name="_bx_reviews_page_block_title_browse_cmts"><![CDATA[Reviews' Comments]]></string>
<string name="_bx_reviews_page_title_sys_manage"><![CDATA[Manage Own]]></string>
Expand Down
3 changes: 2 additions & 1 deletion modules/boonex/reviews/install/sql/enable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module
('bx_reviews_context', 'reviews-context', '_bx_reviews_page_title_sys_entries_in_context', '_bx_reviews_page_title_entries_in_context', 'bx_reviews', 5, 2147483647, 1, '', '', '', '', 0, 1, 0, 'BxReviewsPageAuthor', 'modules/boonex/reviews/classes/BxReviewsPageAuthor.php');

INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
('bx_reviews_context', 1, 'bx_reviews', '_bx_reviews_page_block_title_sys_entries_in_context', '_bx_reviews_page_block_title_entries_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:"bx_reviews";s:6:\"method\";s:14:\"browse_context\";}', 0, 0, 1, 1);
('bx_reviews_context', 1, 'bx_reviews', '_bx_reviews_page_block_title_sys_entries_in_context', '_bx_reviews_page_block_title_entries_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:"bx_reviews";s:6:\"method\";s:14:\"browse_context\";}', 0, 0, 1, 1),
('bx_reviews_context', 1, 'bx_reviews', '_bx_reviews_page_block_title_sys_multi_categories_in_context', '_bx_reviews_page_block_title_multi_categories_in_context', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_reviews\";s:6:\"method\";s:29:\"categories_multi_list_context\";}', 0, 0, 0, 2);

-- PAGE: module home

Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/russian/data/langs/bx_forum/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
<string name="_bx_forum_page_block_title_sys_entries_of_author"><![CDATA[Обсуждения автора]]></string>
<string name="_bx_forum_page_block_title_entries_in_context"><![CDATA[Обсуждения в контексте <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_forum_page_block_title_sys_entries_in_context"><![CDATA[Обсуждения в контексте]]></string>
<string name="_bx_forum_page_block_title_sys_multi_categories_in_context"><![CDATA[Категории обсуждений в контексте(Мульти)]]></string>
<string name="_bx_forum_page_block_title_multi_categories_in_context"><![CDATA[Категории в <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_forum_page_block_title_entries_actions"><![CDATA[Обсуждения - Действия]]></string>
<string name="_bx_forum_page_block_title_browse_cmts"><![CDATA[Форум - Комментарии]]></string>
<string name="_bx_forum_page_block_title_sys_entry_context"><![CDATA[Опубликовано в]]></string>
Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/russian/data/langs/bx_posts/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
<string name="_bx_posts_page_title_entries_of_author"><![CDATA[{display_name} - Публикации]]></string>
<string name="_bx_posts_page_title_sys_entries_in_context"><![CDATA[Публикации в контексте]]></string>
<string name="_bx_posts_page_title_entries_in_context"><![CDATA[Публикации в контексте - {display_name}]]></string>
<string name="_bx_posts_page_block_title_sys_multi_categories_in_context"><![CDATA[Категории публикаций в контексте(Мульти)]]></string>
<string name="_bx_posts_page_block_title_multi_categories_in_context"><![CDATA[Категории в <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_posts_page_block_title_favorites_of_author"><![CDATA[<a href="{profile_link}">{display_name}</a> - Избранное]]></string>
<string name="_bx_posts_page_block_title_sys_favorites_of_author"><![CDATA[Избранное автора]]></string>
<string name="_bx_posts_page_block_title_entries_of_author"><![CDATA[<a href="{profile_link}">{display_name}</a> - Публикации]]></string>
Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/russian/data/langs/bx_reviews/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
<string name="_bx_reviews_page_block_title_sys_entries_of_author"><![CDATA[Отзывы автора]]></string>
<string name="_bx_reviews_page_block_title_entries_in_context"><![CDATA[Отзывы в контексте <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_reviews_page_block_title_sys_entries_in_context"><![CDATA[Отзывы в контексте]]></string>
<string name="_bx_reviews_page_block_title_sys_multi_categories_in_context"><![CDATA[Категории отзывов в контексте(Мульти)]]></string>
<string name="_bx_reviews_page_block_title_multi_categories_in_context"><![CDATA[Категории в <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_reviews_page_block_title_entries_actions"><![CDATA[Отзывы - Действия]]></string>
<string name="_bx_reviews_page_block_title_browse_cmts"><![CDATA[Отзывы - Комментарии]]></string>
<string name="_bx_reviews_page_title_sys_manage"><![CDATA[Управление собственными отзывами]]></string>
Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/russian/data/langs/bx_videos/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<string name="_bx_videos_page_block_title_sys_entries_of_author"><![CDATA[Видео автора]]></string>
<string name="_bx_videos_page_block_title_entries_in_context"><![CDATA[Видео в контексте <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_videos_page_block_title_sys_entries_in_context"><![CDATA[Видео в контексте]]></string>
<string name="_bx_videos_page_block_title_sys_multi_categories_in_context"><![CDATA[Категории видео в контексте(Мульти)]]></string>
<string name="_bx_videos_page_block_title_multi_categories_in_context"><![CDATA[Категории в <a href="{profile_link}">{display_name}</a>]]></string>
<string name="_bx_videos_page_block_title_entries_actions"><![CDATA[Видео - Действия]]></string>
<string name="_bx_videos_page_block_title_browse_cmts"><![CDATA[Видео - Комментарии]]></string>
<string name="_bx_videos_page_title_sys_manage"><![CDATA[Управление собственными видео]]></string>
Expand Down
Loading

0 comments on commit f94739a

Please sign in to comment.