From 5d784959ec6ab3707e40a863c9b21e4c2db7d9f8 Mon Sep 17 00:00:00 2001 From: dleffler Date: Mon, 9 Mar 2015 20:53:14 -0400 Subject: [PATCH] Converts several new methods in section model from static methods to object methods [#1242] --- framework/core/subsystems/expRouter.php | 10 +-- .../help/controllers/helpController.php | 3 +- .../modules/navigation/models/section.php | 65 +++++++++---------- framework/modules/search/models/search.php | 5 +- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/framework/core/subsystems/expRouter.php b/framework/core/subsystems/expRouter.php index a766fdc2f9..6f49ca0643 100644 --- a/framework/core/subsystems/expRouter.php +++ b/framework/core/subsystems/expRouter.php @@ -763,18 +763,18 @@ public function getSectionObj($section) { global $db; if ($section == "*") { - $controller = expModules::getModuleClassName($this->params['controller']); - $sectionObj = call_user_func($controller."::getSection",$this->params); + $sectionObj = call_user_func(expModules::getModuleClassName($this->params['controller']) . "::getSection", $this->params); } else { - $sectionObj = $db->selectObject('section','id='. intval($section)); +// $sectionObj = $db->selectObject('section','id='. intval($section)); + $sectionObj = new section(intval($section)); } // $sectionObj = $db->selectObject('section','id='. intval($section)); - if (!section::canView($sectionObj)) { + if (!$sectionObj->canView()) { define('AUTHORIZED_SECTION',0); } else { define('AUTHORIZED_SECTION',1); } - if (!section::isPublic($sectionObj)) { + if (!$sectionObj->isPublic()) { define('PUBLIC_SECTION',0); } else { define('PUBLIC_SECTION',1); diff --git a/framework/modules/help/controllers/helpController.php b/framework/modules/help/controllers/helpController.php index ac7e22c3fb..c361b69e75 100755 --- a/framework/modules/help/controllers/helpController.php +++ b/framework/modules/help/controllers/helpController.php @@ -525,7 +525,8 @@ public static function getSection($params) { if (!expSession::get('last_section')) { expSession::set('last_section',$sid); } - $section = $db->selectObject('section','id='. intval($sid)); +// $section = $db->selectObject('section','id='. intval($sid)); + $section = new section(intval($sid)); return $section; } diff --git a/framework/modules/navigation/models/section.php b/framework/modules/navigation/models/section.php index 7ac440dd3f..93062dd737 100644 --- a/framework/modules/navigation/models/section.php +++ b/framework/modules/navigation/models/section.php @@ -155,22 +155,17 @@ public static function levelTemplate($parent, $depth = 0, $parents = array()) { /** * Check for cascading page view permission, esp. if not public */ - public static function canView($section) { - global $db; - - if ($section == null) { - return false; - } - if ($section->public == 0) { + public function canView() { + if ($this->public == 0) { // Not a public section. Check permissions. - return expPermissions::check('view', expCore::makeLocation('navigation', '', $section->id)); + return expPermissions::check('view', expCore::makeLocation('navigation', '', $this->id)); } else { // Is public. check parents. - if ($section->parent <= 0) { + if ($this->parent <= 0) { // Out of parents, and since we are still checking, we haven't hit a private section. return true; } else { - $s = $db->selectObject('section', 'id=' . $section->parent); - return self::canView($s); + $s = new section($this->parent); + return $s->canView(); } } } @@ -178,37 +173,34 @@ public static function canView($section) { /** * Check to see if page is public with cascading */ - public static function isPublic($s) { - if ($s == null) { - return false; + public function isPublic() { + $section = $this; + while ($section->public && $section->parent > 0) { + $section = new section($section->parent); } - while ($s->public && $s->parent > 0) { - $s = new section($s->parent); - } - $lineage = (($s->public) ? 1 : 0); - return $lineage; + return (($section->public) ? 1 : 0); } /** * Check to see if page is top level page */ - public static function isTopLevel($s) { - return $s->parent == 0; + public function isTopLevel() { + return $this->parent == 0; } /** * Check to see if page is standalone */ - public static function isStandalone($s) { - return $s->parent == -1; + public function isStandalone() { + return $this->parent == -1; } /** * return page parent */ - public static function getParent($s) { - if ($s->parent != 0 && $s->parent != -1) { - return $s->parent; + public function getParent() { + if ($this->parent != 0 && $this->parent != -1) { + return new section($this->parent); } else { return false; } @@ -217,22 +209,25 @@ public static function getParent($s) { /** * return page's top level parent */ - public static function getTopParent($s) { - $parent = $s->parent; + public function getTopParent() { + $page = $this; do { - $ret = $parent->parent; - $parent = self::getParent($parent->parent); - } while ($parent !== false); + $ret = $page; + $page = $page->getParent(); + } while ($page !== false); return $ret; } /** * return sibling pages including top level and standalone */ - public static function getSiblings($s) { - global $db; - - $siblings = $db->selectObjects('section', 'parent=' . $s->parent); + public function getSiblings($exclude_self = true) { + if ($exclude_self) { + $exclusion = ' AND id!=' . $this->id; + } else { + $exclusion = ''; + } + $siblings = $this->find('all', 'parent=' . $this->parent . $exclusion); return $siblings; } diff --git a/framework/modules/search/models/search.php b/framework/modules/search/models/search.php index 02a1c2d182..9774ae09bd 100644 --- a/framework/modules/search/models/search.php +++ b/framework/modules/search/models/search.php @@ -81,8 +81,9 @@ public function getSearchResults($terms, $only_best = false, $readonly = 0) { $records[$i]->score = $score; }*/ } else if ($records[$i]->ref_type == 'section') { - $section = $db->selectObject('section', 'id=' . $records[$i]->original_id); - if (empty($section) || !section::canView($section)) { +// $section = $db->selectObject('section', 'id=' . $records[$i]->original_id); + $section = new section($records[$i]->original_id); + if (empty($section) || !$section->canView()) { unset($recs[$i]); // page is not available for viewing //$records[$i]->canview = false; }