Skip to content

Commit

Permalink
#4 Bugfix: empty groups and views on institution save
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaechler committed Mar 27, 2014
1 parent b5e1939 commit dac8cc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions module/Libadmin/src/Libadmin/Model/InstitutionRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public function equals(InstitutionRelation $relation) {



/**
* @return String
*/
public function getPrimaryKey() {
return $this->getIdView() . '-' . $this->getIdGroup() . '-' . $this->getIdInstitution();
}



public function getListLabel()
{
return 'Link info here';
Expand Down
16 changes: 9 additions & 7 deletions module/Libadmin/src/Libadmin/Table/InstitutionTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,18 @@ private function relationsChanged(array $oldRelations, array $newRelations) {
$filteredNewRelations = array();

//Filter the views that are not checked
foreach ($newRelations as $newRelation) {
if ( !($newRelation instanceof InstitutionRelation) ) return false;
if ( $newRelation->hasView() ) $filteredNewRelations[] = $newRelation;
foreach ( $newRelations as $newRelation ) {
if ( $newRelation->hasView() ) $filteredNewRelations[$newRelation->getPrimaryKey()] = $newRelation;
}

if (count($oldRelations) !== count($filteredNewRelations)) return true;
//Check if the numbers of relations match
if ( count($oldRelations) !== count($filteredNewRelations) ) return true;

for ($i=0; $i < count($oldRelations); $i++) {
if ( !($oldRelations[$i] instanceof InstitutionRelation) ) return false;
if ( !$oldRelations[$i]->equals($filteredNewRelations[$i]) ) return true;
//Check the relations for equality
foreach ( $oldRelations as $oldRelation ) {
$newRelation = $filteredNewRelations[$oldRelation->getPrimaryKey()];

if ( !$oldRelation->equals($newRelation) ) return true;
}

return false;
Expand Down

0 comments on commit dac8cc9

Please sign in to comment.