Skip to content

Commit

Permalink
Moved zophTreeTable::getChildren() to new DB
Browse files Browse the repository at this point in the history
Also
- some whitespace fixes
- added a few missing access modifiers (public, private, protected)

Issue #20
  • Loading branch information
jeroenrnl committed Aug 28, 2015
1 parent cce6edb commit c5abbb4
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions php/classes/zophTreeTable.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class zophTreeTable extends zophTable {
public function delete() {

// simulate overloading
if(func_num_args()>=1) {
if (func_num_args()>=1) {
$extra_tables = func_get_arg(0);
} else {
$extra_tables = null;
Expand Down Expand Up @@ -75,19 +75,23 @@ public function isRoot() {
/*
* Gets the children of this record.
*/
function getChildren($order = null) {
public function getChildren($order = null) {

if ($this->children) { return $this->children; }
if ($this->children) {
return $this->children;
}
$key = static::$primary_keys[0];
$id = (int) $this->getId();
if (!$id) { return; }
if (!$id) {
return;
}

$sql =
"SELECT * FROM " . static::$table_name .
" WHERE parent_ " . $key . "=" . $id;
$qry = new select(static::$table_name);
$qry->where(new clause("parent_" . $key . "=:parent"));
$qry->addParam(new param(":parent", $key, PDO::PARAM_INT));

if ($order) {
$sql .= " ORDER BY $order";
$qry->addOrder($order);
}

$this->children = static::getRecordsFromQuery($sql);
Expand All @@ -98,7 +102,7 @@ function getChildren($order = null) {
/*
* Gets the ancestors of this record.
*/
function get_ancestors($anc = array()) {
public function get_ancestors($anc = array()) {
$key = static::$primary_keys[0];
$pid = $this->get("parent_" . $key);
// root of tree
Expand All @@ -125,15 +129,15 @@ function get_ancestors($anc = array()) {
* @todo refactor the pass by reference out
*/
public function getBranchIdArray(array &$id_array=null) {
if(!is_array($id_array)) {
if (!is_array($id_array)) {
$id_array=array();
}
$id_array[] = (int) $this->getId();

$this->getChildren();

if ($this->children) {
foreach($this->children as $c) {
foreach ($this->children as $c) {
$c->getBranchIdArray($id_array);
}
}
Expand All @@ -145,7 +149,7 @@ public function getBranchIdArray(array &$id_array=null) {
* all of its descendant's ids. Useful to make "record_id in
* (id_list)" clauses.
*/
function getBranchIds() {
protected function getBranchIds() {
$id_array;
$this->getBranchIdArray($id_array);
return implode(",", $id_array);
Expand All @@ -160,7 +164,7 @@ private function getXMLtree(DOMDocument $xml, $search) {

$title=$this->getName();
$titleshort=strtolower(substr($title, 0, strlen($search)));
if($titleshort == strtolower($search)) {
if ($titleshort == strtolower($search)) {
$key=$this->get($idname);

$newchildkey=$xml->createElement("key");
Expand All @@ -173,9 +177,9 @@ private function getXMLtree(DOMDocument $xml, $search) {
}
$order = user::getCurrent()->prefs->get("child_sortorder");
$children=$this->getChildren($order);
if($children) {
if ($children) {
$childset=$xml->createElement($rootname);
foreach($children as $child) {
foreach ($children as $child) {
$newnode=$child->getXMLtree($xml, $search);
if (isset($newnode)) {
$childset->appendChild($newnode);
Expand All @@ -192,11 +196,11 @@ private function getXMLtree(DOMDocument $xml, $search) {
* @param array Don't fetch details, but use the given array
*/
public function getDetailsXML(array $details=null) {
if(!isset($details)) {
if (!isset($details)) {
$details=$this->getDetails();
}
$children=$this->getChildren();
if(is_array($children)) {
if (is_array($children)) {
$details["children"]=count($children);
}
return parent::getDetailsXML($details);
Expand Down

0 comments on commit c5abbb4

Please sign in to comment.