Skip to content
Permalink
Browse files

Add support for siblings

  • Loading branch information...
redaxmedia committed May 28, 2019
1 parent edf2565 commit 09f7b91c40c7b975540d914586ccd08ff80d5008
Showing with 123 additions and 74 deletions.
  1. +6 −10 includes/Model/Article.php
  2. +25 −8 includes/Model/ContentAbstract.php
  3. +36 −21 includes/View/Article.php
  4. +31 −22 includes/View/Comment.php
  5. +25 −13 includes/View/Extra.php
@@ -78,13 +78,11 @@ public function countByCategoryAndLanguage(int $categoryId = null, string $langu
public function getByCategoryAndLanguageAndOrder(int $categoryId = null, string $language = null, string $orderColumn = null) : ?object
{
$categoryModel = new Category();
return $this
->query()
->where(
[
'category' => $categoryId,
'status' => 1
])
->whereIn('category', $categoryModel->getIdArrayBySibling($categoryId))
->where('status', 1)
->whereLanguageIs($language)
->orderBySetting($orderColumn)
->findMany() ? : null;
@@ -105,13 +103,11 @@ public function getByCategoryAndLanguageAndOrder(int $categoryId = null, string
public function getByCategoryAndLanguageAndOrderAndStep(int $categoryId = null, string $language = null, string $orderColumn = null, int $limitStep = null) : ?object
{
$categoryModel = new Category();
return $this
->query()
->where(
[
'category' => $categoryId,
'status' => 1
])
->whereIn('category', $categoryModel->getIdArrayBySibling($categoryId))
->where('status', 1)
->whereLanguageIs($language)
->orderBySetting($orderColumn)
->limitBySetting($limitStep)
@@ -54,30 +54,47 @@ public function getByLanguageAndOrder(string $language = null, string $orderColu
*
* @since 4.0.0
*
* @param int $id
* @param int $contentId
* @param string $language
* @param string $orderColumn name of the column to order
*
* @return object|null
*/
public function getByIdAndLanguageAndOrder(int $id = null, string $language = null, string $orderColumn = null) : ?object
public function getByIdAndLanguageAndOrder(int $contentId = null, string $language = null, string $orderColumn = null) : ?object
{
return $this
->query()
->whereIn('id', $this->getIdArrayBySibling($contentId))
->whereLanguageIs($language)
->where('status', 1)
->orderBySetting($orderColumn)
->findMany() ? : null;
}
/**
* get id array by sibling
*
* @param int $siblingId identifier of the content
*
* @return array|null
*/
public function getIdArrayBySibling(int $siblingId = null) : ?array
{
return $this
->query()
->select('id')
->whereAnyIs(
[
[
'id' => $id
'id' => $siblingId
],
[
'sibling' => $id
'sibling' => $siblingId
]
])
->whereLanguageIs($language)
->where('status', 1)
->orderBySetting($orderColumn)
->findMany() ? : null;
->findFlatArray();
}
/**
@@ -131,19 +131,16 @@ public function render(int $categoryId = null, int $articleId = null) : string
$output = Module\Hook::trigger('articleStart');
$outputFragment = null;
$accessValidator = new Validator\Access();
$settingModel = new Model\Setting();
$articleModel = new Model\Article();
$articles = null;
$contentParser = new Content\Parser($this->_registry, $this->_request, $this->_language, $this->_config);
$byline = new Helper\Byline($this->_registry, $this->_language);
$byline->init();
$adminDock = new Admin\View\Helper\Dock($this->_registry, $this->_language);
$adminDock->init();
$language = $this->_registry->get('language');
$loggedIn = $this->_registry->get('loggedIn');
$token = $this->_registry->get('token');
$firstParameter = $this->_registry->get('firstParameter');
$lastSubParameter = $this->_registry->get('lastSubParameter');
$lastTable = $this->_registry->get('lastTable');
$parameterRoute = $this->_registry->get('parameterRoute');
$myGroups = $this->_registry->get('myGroups');
@@ -164,24 +161,7 @@ public function render(int $categoryId = null, int $articleId = null) : string
[
'class' => $this->_optionArray['className']['box']
]);
/* query articles */
if ($categoryId)
{
if ($settingModel->get('pagination'))
{
$articles = $articleModel->getByCategoryAndLanguageAndOrderAndStep($categoryId, $language, $this->_optionArray['orderColumn'], $lastSubParameter - 1);
}
else
{
$articles = $articleModel->getByCategoryAndLanguageAndOrder($categoryId, $language, $this->_optionArray['orderColumn']);
}
}
else if ($articleId)
{
$articles = $articleModel->getByIdAndLanguageAndOrder($articleId, $language, $this->_optionArray['orderColumn']);
}
$articles = $this->queryArticles($categoryId, $articleId);
/* process articles */
@@ -217,4 +197,39 @@ public function render(int $categoryId = null, int $articleId = null) : string
$output .= Module\Hook::trigger('articleEnd');
return $output;
}
/**
* query the articles
*
* @since 4.0.0
*
* @param int $categoryId identifier of the category
* @param int $articleId identifier of the article
*
* @return object|null
*/
public function queryArticles(int $categoryId = null, int $articleId = null) : ?object
{
$articleModel = new Model\Article();
$settingModel = new Model\Setting();
$lastSubParameter = $this->_registry->get('lastSubParameter');
$language = $this->_registry->get('language');
/* query articles */
if ($categoryId)
{
if ($settingModel->get('pagination'))
{
return $articleModel->getByCategoryAndLanguageAndOrderAndStep($categoryId, $language, $this->_optionArray['orderColumn'], $lastSubParameter - 1);
}
return $articleModel->getByCategoryAndLanguageAndOrder($categoryId, $language, $this->_optionArray['orderColumn']);
}
if ($articleId)
{
return $articleModel->getByIdAndLanguageAndOrder($articleId, $language, $this->_optionArray['orderColumn']);
}
return $articleModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']);
}
}
@@ -85,17 +85,13 @@ public function render(int $articleId = null) : string
}
$output = Module\Hook::trigger('commentStart');
$accessValidator = new Validator\Access();
$settingModel = new Model\Setting();
$commentModel = new Model\Comment();
$byline = new Helper\Byline($this->_registry, $this->_language);
$byline->init();
$adminDock = new Admin\View\Helper\Dock($this->_registry, $this->_language);
$adminDock->init();
$language = $this->_registry->get('language');
$loggedIn = $this->_registry->get('loggedIn');
$token = $this->_registry->get('token');
$firstParameter = $this->_registry->get('firstParameter');
$lastSubParameter = $this->_registry->get('lastSubParameter');
$myGroups = $this->_registry->get('myGroups');
/* html element */
@@ -117,24 +113,7 @@ public function render(int $articleId = null) : string
[
'class' => $this->_optionArray['className']['box']
]);
/* query comments */
if ($articleId)
{
if ($settingModel->get('pagination'))
{
$comments = $commentModel->getByArticleAndLanguageAndOrderAndStep($articleId, $language, $this->_optionArray['orderColumn'], $lastSubParameter - 1);
}
else
{
$comments = $commentModel->getByArticleAndLanguageAndOrder($articleId, $language, $this->_optionArray['orderColumn']);
}
}
else
{
$comments = $commentModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']);
}
$comments = $this->queryComments($articleId);
/* process comments */
@@ -162,4 +141,34 @@ public function render(int $articleId = null) : string
$output .= Module\Hook::trigger('commentEnd');
return $output;
}
/**
* query the comments
*
* @since 4.0.0
*
* @param int $articleId identifier of the article
*
* @return object|null
*/
public function queryComments(int $articleId = null) : ?object
{
$commentModel = new Model\Comment();
$settingModel = new Model\Setting();
$lastSubParameter = $this->_registry->get('lastSubParameter');
$language = $this->_registry->get('language');
/* query comments */
if ($articleId)
{
if ($settingModel->get('pagination'))
{
return $commentModel->getByArticleAndLanguageAndOrderAndStep($articleId, $language, $this->_optionArray['orderColumn'], $lastSubParameter - 1);
}
return $commentModel->getByArticleAndLanguageAndOrder($articleId, $language, $this->_optionArray['orderColumn']);
}
return $commentModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']);
}
}
@@ -124,12 +124,10 @@ public function render(int $extraId = null) : string
}
$output = Module\Hook::trigger('extraStart');
$accessValidator = new Validator\Access();
$extraModel = new Model\Extra();
$extras = null;
$contentParser = new Content\Parser($this->_registry, $this->_request, $this->_language, $this->_config);
$adminDock = new Admin\View\Helper\Dock($this->_registry, $this->_language);
$adminDock->init();
$language = $this->_registry->get('language');
$loggedIn = $this->_registry->get('loggedIn');
$token = $this->_registry->get('token');
$categoryId = $this->_registry->get('categoryId');
@@ -152,17 +150,7 @@ public function render(int $extraId = null) : string
[
'class' => $this->_optionArray['className']['box']
]);
/* query extras */
if ($extraId)
{
$extras = $extraModel->getByIdAndLanguageAndOrder($extraId, $language, $this->_optionArray['orderColumn']);
}
else
{
$extras = $extraModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']);
}
$extras = $this->queryExtras($extraId);
/* process extras */
@@ -193,4 +181,28 @@ public function render(int $extraId = null) : string
$output .= Module\Hook::trigger('extraEnd');
return $output;
}
/**
* query the extras
*
* @since 4.0.0
*
* @param int $extraId identifier of the extra
*
* @return object|null
*/
public function queryExtras(int $extraId = null) : ?object
{
$extraModel = new Model\Extra();
$language = $this->_registry->get('language');
/* query extras */
if ($extraId)
{
return $extraModel->getByIdAndLanguageAndOrder($extraId, $language, $this->_optionArray['orderColumn']);
}
return $extraModel->getByLanguageAndOrder($language, $this->_optionArray['orderColumn']);
}
}

0 comments on commit 09f7b91

Please sign in to comment.
You can’t perform that action at this time.