Skip to content

Commit 1fdf4e1

Browse files
authored
Merge pull request #198 from studycloud/bugfix_tree_resource_duplication
clean up code and comments for tree relates stuff
2 parents 698f82b + 6405625 commit 1fdf4e1

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

app/Helpers/NodesAndConnections.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public static function separatedTree($repository, ...$args)
8181
/**
8282
* some data won't have pivot objects, but conversion function depends on their existence
8383
* let's format an $node into the "nodes with pivot" format
84-
* @param array $node the data that needs to be converted; the node must have a 'parent_id' attribute
85-
* @param string $name the name of the type of object (ex: "topic" or "class")
86-
* @param int|null $other_id the id of the pivot's parent_id, if not the parent_id itself
87-
* @return array the reformated data as a collection with a pivot attribute
84+
* @param array $node the data that needs to be converted; the node must have a 'parent_id' attribute
85+
* @param string $name the name of the type of object (ex: "topic" or "class")
86+
* @param int|null $replace_child the id of the pivot's parent_id, if not the parent_id itself
87+
* @return array the reformated data as a collection with a pivot attribute
8888
* added and the 'parent_id' attribute removed
8989
*/
9090
public static function addPivot($node, $name, $replace_child=null)

app/Repositories/ClassRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function descendants(Academic_Class $class = null, int $levels = null, $r
5656
);
5757
$tree = $tree->merge(
5858
// RECURSION!
59-
$this->descendants($child, $levels - 1, $root)
59+
$this->descendants($child, is_null($levels) ? null : $levels - 1, $root)
6060
);
6161
}
6262
}
@@ -105,7 +105,7 @@ public function ancestors(Academic_Class $class = null, int $levels = null, $roo
105105
);
106106
$tree = $tree->merge(
107107
// RECURSION!
108-
$this->ancestors($parent, $levels - 1, $root)
108+
$this->ancestors($parent, is_null($levels) ? null : $levels - 1, $root)
109109
);
110110
}
111111
}
@@ -191,7 +191,7 @@ function ($class) use ($descendant_class_id, $connections)
191191
/**
192192
* given a portion of the tree, check to see whether $ancestor_class_id is an ancestor of $class_id
193193
* @param int $class_id the descendant class
194-
* @param int|array $ancestor_class_id the ancestor to search for
194+
* @param int|array $ancestor_class_id the ancestor(s) to search for
195195
* @param Collection $connections a portion of the tree to traverse, in the connections or separated connections format
196196
* @return boolean|array whether $ancestor_class_id is an ancestor of $class; if $ancestor_class_id is an array, return the elements in it that are ancestors
197197
*/

app/Repositories/TopicRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function descendants(Topic $topic = null, int $levels = null, $root = nul
6666
$tree->push(collect($child));
6767
$tree = $tree->merge(
6868
// RECURSION!
69-
$this->descendants($child, $levels - 1, $root)
69+
$this->descendants($child, is_null($levels) ? null : $levels - 1, $root)
7070
);
7171
}
7272
}
@@ -114,7 +114,7 @@ public function ancestors(Topic $topic = null, int $levels = null, $root = null)
114114
$tree->push(collect($parent));
115115
$tree = $tree->merge(
116116
// RECURSION!
117-
$this->ancestors($parent, $levels - 1, $root)
117+
$this->ancestors($parent, is_null($levels) ? null : $levels - 1, $root)
118118
);
119119
}
120120
}

app/Rules/ValidClassParentAttachment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function __construct(Academic_Class $class=null, Collection $tree=null)
4545
{
4646
$this->class = $class;
4747
$this->class_is_root = is_null($this->class) || $this->class->id == 0;
48+
// check if class is root, if not, set tree to be an instance of NodesAndConnections else null
4849
$this->tree = (is_null($tree) and !$this->class_is_root) ? $this->getTree() : $tree;
4950
}
5051

0 commit comments

Comments
 (0)