Skip to content

Commit

Permalink
Converts several new methods in section model from static methods to…
Browse files Browse the repository at this point in the history
… object methods [#1242]
  • Loading branch information
dleffler committed Mar 10, 2015
1 parent 09030bc commit 5d78495
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
10 changes: 5 additions & 5 deletions framework/core/subsystems/expRouter.php
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion framework/modules/help/controllers/helpController.php
Expand Up @@ -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;
}

Expand Down
65 changes: 30 additions & 35 deletions framework/modules/navigation/models/section.php
Expand Up @@ -155,60 +155,52 @@ 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();
}
}
}

/**
* 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;
}
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions framework/modules/search/models/search.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5d78495

Please sign in to comment.