Skip to content

Commit

Permalink
CS-5754 - Problem with topics
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed May 13, 2015
1 parent dc5c933 commit 716a2ae
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions newscoop/template_engine/classes/SubtopicsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
class SubtopicsList extends ListObject
{
private static $s_orderFields = array('default',
'bynumber',
'byname',
);
private static $s_orderFields = array(
'default',
'bynumber',
'byname',
);

/**
* Creates the list of objects. Sets the parameter $p_hasNextElements to
Expand All @@ -30,6 +31,7 @@ protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &
$rootTopicId = $p_parameters['topic_identifier'];
$start = null;
$limit = null;
$order = array();
if ($p_start > 0) {
$start = $p_start;
}
Expand All @@ -38,6 +40,14 @@ protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &
$limit = $p_limit;
}

if (!isset($p_parameters['direct'])) {
$p_parameters['direct'] = true;
}

if (!empty($this->m_order)) {
$order = $this->m_order[0];
}

$em = \Zend_Registry::get('container')->getService('em');
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$topicService = \Zend_Registry::get('container')->getService('newscoop_newscoop.topic_service');
Expand All @@ -56,9 +66,9 @@ protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &
$subtopics = $repository->childrenWithTranslations(
$topic,
$language ? $language->getCode() : null,
false,
null,
isset($p_parameters['order']) ? $p_parameters['order'] : null,
$p_parameters['direct'],
isset($order['field']) ? $order['field'] : null,
isset($order['dir']) ? $order['dir'] : null,
$start,
$limit
)->getArrayResult();
Expand Down Expand Up @@ -101,13 +111,18 @@ protected function ProcessOrder(array $p_order)
{
$order = array();
$state = 1;
$aliases = array(
'byname' => 'title',
'bynumber' => 'id',
);

foreach ($p_order as $word) {
switch ($state) {
case 1: // reading the order field
if (array_search(strtolower($word), SubtopicsList::$s_orderFields) === false) {
CampTemplate::singleton()->trigger_error("invalid order field $word in list_subtopics, order parameter");
} else {
$orderField = $word;
$orderField = $aliases[$word];
$state = 2;
}
break;
Expand Down Expand Up @@ -156,6 +171,9 @@ protected function ProcessParameters(array $p_parameters)
$parameters[$parameter] = $value;
}
break;
case 'direct':
$parameters[$parameter] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
break;
default:
CampTemplate::singleton()->trigger_error("invalid parameter $parameter in list_subtopics", $p_smarty);
}
Expand Down

0 comments on commit 716a2ae

Please sign in to comment.