/**
  * 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();
 }
 /**
  * @param User $item
  * @return array
  */
 protected function convertItemFromObject(User $item)
 {
     $converted = array();
     $obj = $this->userService->fetchUserDetails($item);
     $converted[self::ID_FIELD_NAME] = $obj->getId();
     foreach ($this->properties as $property) {
         $converted[$property] = $this->getPropertyValue($property, $obj);
     }
     if (empty($converted['fullName']) || $converted['fullName'] === ' ') {
         $converted['fullName'] = $converted['email'];
     }
     if ($item->isDiamanteUser()) {
         $realUserObj = $this->userService->getByUser($item);
         $converted['isDeleted'] = $realUserObj->isDeleted();
     } else {
         $converted['isDeleted'] = false;
     }
     $converted['type'] = $item->getType();
     if ($item->getType() === User::TYPE_DIAMANTE) {
         $converted['type_label'] = 'customer';
     } else {
         $converted['type_label'] = 'admin';
     }
     return $converted;
 }
 /**
  * @param int $id
  * @return $this
  */
 public function setAssigneeId($id)
 {
     if (!empty($id)) {
         $assignee = $this->userService->getByUser(new User((int) $id, User::TYPE_ORO));
         $this->assignee = $assignee;
     }
     return $this;
 }
 /**
  * @param Notification $notification
  *
  * @return string
  */
 private function getFormattedUserName(Notification $notification)
 {
     $user = $notification->getAuthor();
     $userId = $this->userService->verifyDiamanteUserExists($user->getEmail());
     $user = empty($userId) ? $user : new User($userId, User::TYPE_DIAMANTE);
     $user = $this->userService->getByUser($user);
     $format = $this->nameFormatter->getNameFormat();
     $name = str_replace(array('%first_name%', '%last_name%', '%prefix%', '%middle_name%', '%suffix%'), array($user->getFirstName(), $user->getLastName(), '', '', ''), $format);
     return trim($name);
 }
 /**
  * @param $user
  * @return \Diamante\UserBundle\Entity\DiamanteUser|\Oro\Bundle\UserBundle\Entity\User
  */
 private function getUserDependingOnType($user)
 {
     if ($user instanceof OroUser) {
         return $user;
     }
     if ($user instanceof ApiUser) {
         $userId = $this->userService->verifyDiamanteUserExists($user->getEmail());
         $user = empty($userId) ? $user : new User($userId, User::TYPE_DIAMANTE);
     }
     $result = $this->userService->getByUser($user);
     return $result;
 }
 /**
  * @param int|OroUser $identity
  * @return $this
  */
 public function setAssignee($identity)
 {
     if ($identity instanceof OroUser) {
         $this->assignee = $identity;
         return $this;
     }
     if (!empty($identity)) {
         $assignee = $this->userService->getByUser(new User((int) $identity, User::TYPE_ORO));
         $this->assignee = $assignee;
     }
     return $this;
 }
 /**
  * Assign Ticket to specified User
  * @param AssigneeTicketCommand $command
  * @throws \RuntimeException if unable to load required ticket, assignee
  */
 public function assignTicket(AssigneeTicketCommand $command)
 {
     $ticket = $this->loadTicketById($command->id);
     $this->isAssigneeGranted($ticket);
     if ($command->assignee) {
         $assignee = $this->userService->getByUser(new User($command->assignee, User::TYPE_ORO));
         if (is_null($assignee)) {
             throw new \RuntimeException('Assignee loading failed, assignee not found.');
         }
         $ticket->assign($assignee);
     } else {
         $ticket->unAssign();
     }
     $this->ticketRepository->store($ticket);
     $this->dispatchEvents($ticket);
 }
 /**
  * @test
  * @expectedException \RuntimeException
  * @expectedExceptionMessage User loading failed. User not found
  */
 public function testThrowsExceptionIfUserNotFound()
 {
     $userValueObject = new User(1, User::TYPE_DIAMANTE);
     $this->diamanteUserRepository->expects($this->once())->method('get')->with($this->equalTo($userValueObject->getId()))->will($this->returnValue(null));
     $this->diamanteUserService->getByUser($userValueObject);
 }