/**
  * @param Command\BranchCommand $command
  * @param Branch $branch
  */
 protected function handleTagging(Command\BranchCommand $command, Branch $branch)
 {
     $tags = $command->getTags();
     $tags['owner'] = $tags['all'];
     $branch->setTags($tags);
 }
 /**
  * @Route(
  *      "/update/{id}",
  *      name="diamante_branch_update",
  *      requirements={"id"="\d+"}
  * )
  * @Template("DiamanteDeskBundle:Branch:update.html.twig")
  *
  * @param int $id
  * @return array
  */
 public function updateAction($id)
 {
     $branch = $this->get('diamante.branch.service')->getBranch($id);
     $command = BranchCommand::fromBranch($branch);
     if ($this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id) !== null) {
         $branchEmailConfiguration = $this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id);
         $branchEmailConfigurationCommand = BranchEmailConfigurationCommand::fromBranchEmailConfiguration($branchEmailConfiguration);
         $command->setBranchEmailConfiguration($branchEmailConfigurationCommand);
     }
     try {
         $form = $this->createForm('diamante_update_branch_form', $command);
         $result = $this->edit($command, $form, function ($command) use($branch) {
             $branchId = $this->get('diamante.branch.service')->updateBranch($command);
             $this->updateBranchEmailConfiguration($command, $branchId);
             return $branchId;
         });
     } catch (MethodNotAllowedException $e) {
         return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id)));
     } catch (\Exception $e) {
         $this->handleException($e);
         return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id)));
     }
     return $result;
 }
 /**
  * @Route(
  *      "/update/{id}",
  *      name="diamante_branch_update",
  *      requirements={"id"="\d+"}
  * )
  * @Template("DiamanteDeskBundle:Branch:update.html.twig")
  *
  * @param int $id
  * @return array
  */
 public function updateAction($id)
 {
     $branch = $this->get('diamante.branch.service')->getBranch($id);
     $command = BranchCommand::fromBranch($branch);
     if ($this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id)) {
         $branchEmailConfiguration = $this->get('diamante.branch_email_configuration.service')->getConfigurationByBranchId($id);
         $branchEmailConfigurationCommand = BranchEmailConfigurationCommand::fromBranchEmailConfiguration($branchEmailConfiguration);
         $command->setBranchEmailConfiguration($branchEmailConfigurationCommand);
     }
     try {
         $form = $this->createForm(new UpdateBranchType(), $command);
         $result = $this->edit($command, $form, function ($command) use($branch) {
             $branchId = $this->get('diamante.branch.service')->updateBranch($command);
             $this->updateBranchEmailConfiguration($command, $branchId);
             return $branchId;
         }, $branch);
     } catch (MethodNotAllowedException $e) {
         return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id)));
     } catch (\Exception $e) {
         $this->container->get('monolog.logger.diamante')->error(sprintf('Branch update failed: %s', $e->getMessage()));
         $this->addErrorMessage('diamante.desk.branch.messages.save.error');
         return $this->redirect($this->generateUrl('diamante_branch_view', array('id' => $id)));
     }
     return $result;
 }
 /**
  * Update Branch
  *
  * @param Command\BranchCommand $branchCommand
  * @return int
  */
 public function updateBranch(Command\BranchCommand $branchCommand)
 {
     $this->isGranted('EDIT', 'Entity:DiamanteDeskBundle:Branch');
     /**
      * @var $branch \Diamante\DeskBundle\Model\Branch\Branch
      */
     $branch = $this->branchRepository->get($branchCommand->id);
     if ($branchCommand->defaultAssignee) {
         $assignee = $this->userService->getByUser(new User($branchCommand->defaultAssignee, User::TYPE_ORO));
     } else {
         $assignee = null;
     }
     /** @var \Symfony\Component\HttpFoundation\File\File $file */
     $file = null;
     if ($branchCommand->isRemoveLogo()) {
         $this->branchLogoHandler->remove($branch->getLogo());
         $file = new Logo();
     } elseif ($branchCommand->logoFile) {
         if ($branch->getLogo()) {
             $this->branchLogoHandler->remove($branch->getLogo());
         }
         $logo = $this->handleLogoUpload($branchCommand->logoFile);
         $file = new Logo($logo->getFilename(), $branchCommand->logoFile->getClientOriginalName());
     }
     $branch->update($branchCommand->name, $branchCommand->description, $assignee, $file);
     $this->branchRepository->store($branch);
     //TODO: Refactor tag manipulations.
     $this->tagManager->deleteTaggingByParams($branch->getTags(), get_class($branch), $branch->getId());
     $tags = $branchCommand->tags;
     $tags['owner'] = $tags['all'];
     $branch->setTags($tags);
     $this->tagManager->saveTagging($branch);
     return $branch->getId();
 }