/** * Remove a tag from all applicants and add a new tag in its place * @param $tagId */ public function actionEdit($tagId) { if ($tag = $this->_em->getRepository('Jazzee\\Entity\\Tag')->find($tagId)) { $applicants = $this->_em->getRepository('Jazzee\\Entity\\Applicant')->findTaggedByApplication($this->_application, $tag); $form = new \Foundation\Form(); $form->setCSRFToken($this->getCSRFToken()); $form->setAction($this->path("setup/tags/edit/{$tagId}")); $field = $form->newField(); $field->setLegend('Change "' . $tag->getTitle() . '" Tag for ' . count($applicants) . ' applicants'); $element = $field->newElement('TextInput', 'title'); $element->setLabel('New Tag'); $element->setValue($tag->getTitle()); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $applications = $this->_em->getRepository('\\Jazzee\\Entity\\Application')->findByProgram($this->_program); $form->newButton('submit', 'Change Tag'); if ($input = $form->processInput($this->post)) { $newTag = $this->_em->getRepository('\\Jazzee\\Entity\\Tag')->findOneBy(array('title' => $input->get('title'))); if (!$newTag) { $newTag = new \Jazzee\Entity\Tag(); $newTag->setTitle($input->get('title')); $this->_em->persist($newTag); } foreach ($applicants as $applicant) { $applicant->removeTag($tag); $applicant->addTag($newTag); $this->_em->persist($applicant); } $this->addMessage('success', 'Changed tag for ' . count($applicants) . ' applicants'); $this->redirectPath('setup/tags'); } $this->setVar('form', $form); } }
/** * Tag an applicant * @param integer $applicantID */ public function actionAddTag($applicantId) { $applicant = $this->getApplicantById($applicantId); $tag = $this->_em->getRepository('\\Jazzee\\Entity\\Tag')->findOneBy(array('title' => $this->post['tagTitle'])); if (!$tag) { $tag = new \Jazzee\Entity\Tag(); $tag->setTitle($this->post['tagTitle']); $this->_em->persist($tag); } $applicant->addTag($tag); $this->_em->persist($applicant); $this->_em->flush(); //flush here so the tag ID will be available $this->setVar('result', array('tags' => $this->getTags($applicant))); $this->loadView($this->controllerName . '/result'); }