Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b387a7
start creating move class function. should it sync children or add them?
aryarm Mar 2, 2019
6551469
start creating class attachment validation function
aryarm Mar 3, 2019
b248935
remove sync parameter. it doesn't make sense for the class tree
aryarm Mar 9, 2019
960b82b
fix some comments
aryarm Mar 10, 2019
c157772
when seeding classes, prevent the creation of stick trees and provide…
aryarm Mar 10, 2019
ddbd1ce
create class attachment validation function. still untested but shoul…
aryarm Mar 10, 2019
da314c3
allow class seeding to create sticks if desired
aryarm Mar 10, 2019
c6f0852
redo isAncestor in ClassRepository to take advantage of the structure…
aryarm Mar 18, 2019
dfbc3c2
implement array input in the ClassRepository's isDescendant() and isA…
aryarm Mar 18, 2019
bb429d3
enable ClassRepository's isAncestor() and isDescendant() to optionall…
aryarm Mar 18, 2019
b33025b
finish up issue #140
aryarm Mar 18, 2019
d1d0851
create helper functions for separated connections format. see issue #140
aryarm Mar 18, 2019
473b592
use separated connections in ClassRepository
aryarm Mar 19, 2019
5a23bcc
create readable array helper function
aryarm Mar 19, 2019
1a2995c
handle the root case in class attachment validation
aryarm Mar 19, 2019
1fc8521
create custom validation rule, but it may need to be split according …
aryarm Mar 19, 2019
29ba5e9
create split validation rules for class attachment
aryarm Mar 19, 2019
8569451
split class attachment validation rules
aryarm Mar 19, 2019
e333c58
integrate the class validation rules into the ClassController's attac…
aryarm Mar 19, 2019
7ce5cd5
start testing class attachment (see #136)
aryarm Mar 20, 2019
9e7e1e3
use old classes http test to verify class attachment still works
aryarm Mar 20, 2019
3f627aa
scaffold class attachment http test. still need to write the actual t…
aryarm Mar 20, 2019
d399cb0
fix some bugs with class attachment
aryarm Mar 20, 2019
c894325
finish testing class attachment validation
aryarm Mar 20, 2019
61b0d7a
improve comments in the class attachment http test
aryarm Mar 21, 2019
821b67a
remove class attachment tests in classes http test, since we already …
aryarm Mar 21, 2019
663c7ba
reduce queries in ClassController's attach() function
aryarm Mar 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle the root case in class attachment validation
  • Loading branch information
aryarm committed Mar 19, 2019
commit 1a2995c50f5bf7674922c612954c6d6c8fffc10b
52 changes: 34 additions & 18 deletions app/Repositories/ClassRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static function validateClassAttach($class=null, $parent=null, $children=
if (is_null($tree))
{
$get_tree = true;
$tree = NodesAndConnections::treeAsSeparatedConnections((new ClassRepository)->descendants($class), collect());
$tree = NodesAndConnections::treeAsSeparatedConnections(collect(), (new ClassRepository)->descendants($class));
}
// return failure if the new parent is a descendant of $class
// make sure to include the new children when you check
Expand All @@ -286,10 +286,15 @@ public static function validateClassAttach($class=null, $parent=null, $children=
// check if we need to retrieve the new ancestors
if (!is_null($parent))
{
// get the ancestors of the new parent
$tree['ancestors'] = NodesAndConnections::treeAsConnections(
(new ClassRepository)->ancestors($parent)
);
if ($parent !== 0)
{
// get the ancestors of the new parent
$tree['ancestors'] = NodesAndConnections::treeAsConnections(
(new ClassRepository)->ancestors(
Academic_Class::find($parent), null, Academic_Class::getRoot()
)
);
}
// add the connection between the current parent and the new parent
$tree['ancestors']->prepend(
collect([
Expand All @@ -301,26 +306,37 @@ public static function validateClassAttach($class=null, $parent=null, $children=
else // retrieve the current ancestors
{
$tree['ancestors'] = NodesAndConnections::treeAsConnections(
(new ClassRepository)->ancestors($class)
(new ClassRepository)->ancestors(
$class, null, Academic_Class::getRoot()
)
);
}
}
// return failure if the children we want to add are ancestors of $class
foreach ($children as $child)
// find all new children that are ancestors of $class
$bad_children = self::isAncestor($class->id, $children, $tree);
if (count($bad_children) > 1)
{
if (self::isAncestor($class->id, $child, $tree))
if (is_null($parent))
{
// this will stop on first failure but maybe we want it to find all bad children?
if (is_null($parent))
{
return "Class ".$child." is an ancestor of class ".$class->id.". It cannot be added as its child.";
}
else
{
return "Class ".$child." will be an ancestor of class ".$class->id.". It cannot be added as its child.";
}
return "Classes ".readable_array($bad_children)." are ancestors of class ".$class->id.". They cannot be added as its children.";
}
else
{
return "By making class ".$parent." the parent of class ".$class->id.", classes ".readable_array($bad_children)." will become ancestors of class ".$class->id.". They cannot be added as its children.";
}
}
elseif (count($bad_children) == 1)
{
if (is_null($parent))
{
return "Class ".$bad_children[0]." is an ancestor of class ".$class->id.". It cannot be added as its child.";
}
else
{
return "By making class ".$parent." the parent of class ".$class->id.", class ".$bad_children[0]." will become an ancestor of class ".$class->id.". It cannot be added as its child.";
}
}
return null;
}

public static function printAsciiDescendants($class)
Expand Down