Пример #1
0
 /**
  * Creates a link between an activity and an ability or a competency.
  * If the link already exists, the method returns false. Otherwise, it
  * returns an array representation of the ability/competency.
  *
  * @param Activity              $activity
  * @param Ability|Competency    $target
  * @return array|bool
  * @throws \InvalidArgumentException if the target isn't an instance of Ability or Competency
  */
 public function createLink(Activity $activity, $target)
 {
     if (!$target instanceof Ability && !$target instanceof Competency) {
         throw new \InvalidArgumentException('Second argument must be a Competency or an Ability instance');
     }
     if ($target->isLinkedToActivity($activity)) {
         return false;
     }
     $target->linkActivity($activity);
     $this->om->flush();
     $loadMethod = $target instanceof Competency ? 'loadCompetency' : 'loadAbility';
     return $this->{$loadMethod}($target);
 }