/** * @see Editor_Models_ConceptValidator::validate($concept) */ public function isValid(Editor_Models_Concept $concept, $extraData) { $this->_setField('narrower'); $isValid = true; $allNarrowers = $concept->getRelationsByField('narrower', null, array($concept, 'getAllRelations')); foreach ($allNarrowers as $narrower) { $narrower = new Editor_Models_Concept($narrower); if ($narrower->hasRelationInDepth('narrower', $concept)) { $isValid = false; $this->_addConflictedConcept($narrower); } } if (!$isValid) { $this->_setErrorMessage(_('One or more of the narrower relations create a cycle')); } return $isValid; }
/** * @see Editor_Models_ConceptValidator::validate($concept) */ public function isValid(Editor_Models_Concept $concept, $extraData) { $this->_setField('broader'); $isValid = true; $allNarrowers = $concept->getRelationsByField('narrower', null, array($concept, 'getAllRelations')); foreach ($allNarrowers as $narrower) { $narrower = new Editor_Models_Concept($narrower); if ($concept->hasRelationInDepth('narrower', $narrower, false)) { $isValid = false; $this->_addConflictedConcept($narrower); } } if (!$isValid) { $this->_setErrorMessage(_('One or more of narrower relations have also a relation via an intermediate concepts')); } return $isValid; }
/** * Searches for relation with the $searchConcept - direct or via intermidate concepts. * * @param string $type broader, narrower or related. * @param Editor_Models_Concept $searchConcept * @param bool $checkFirstLevel Searches only for relation with intermidiate concept. */ public function hasRelationInDepth($type, Editor_Models_Concept $searchConcept, $checkFirstLevel = true) { $relations = $this->getRelationsByField($type, null, array($this, 'getAllRelations')); foreach ($relations as $relation) { if ($relation['uuid'] == $searchConcept['uuid']) { if ($checkFirstLevel) { return true; } } else { $relation = new Editor_Models_Concept($relation); if ($relation->hasRelationInDepth($type, $searchConcept)) { return true; } } } return false; }