/** * Returns data to render template * * @param array $options * * @throws WidgetEntityNotFoundException * @throws WidgetParameterException * * @return array */ public function getData($options) { if (!empty($options) && array_key_exists('account', $options) && !empty($options['account'])) { $id = $options['account']; $account = $this->accountRepository->find($id); if (!$account) { throw new WidgetEntityNotFoundException('Entity \'Account\' with id ' . $id . ' not found!', $this->widgetName, $id); } return $this->parseAccount($account); } return null; }
/** * {@inheritdoc} * * @throws WidgetEntityNotFoundException * @throws WidgetParameterException */ public function getData($options) { $data = []; if (!empty($options)) { $ids = $this->getValue($this->keys['ids'], $options, null); $limit = $this->getValue($this->keys['limit'], $options, null); $headline = $this->getValue($this->keys['headline'], $options, null); // set headline if ($headline) { $data['headline'] = $headline; } if ($ids) { // Parse accounts $accountIds = explode(',', $ids); foreach ($accountIds as $index => $id) { // check if limit is exceeded if ($limit && $index >= $limit) { $data['further'] = count($accountIds) - $limit; break; } // fetch and parse account data $account = $this->accountRepository->find($id); if (!$account) { throw new WidgetEntityNotFoundException('Entity \'Account\' with id ' . $id . ' not found!', $this->widgetName, $id); } $data['accounts'][] = $this->parseAccount($account); } } // set emptylabel if (isset($this->keys['emptyLabel'])) { $data['emptyLabel'] = $this->keys['emptyLabel']; } return $data; } }
/** * {@inheritdoc} */ public function findByFilters($filters, $page, $pageSize, $limit, $locale, $options = []) { $entities = $this->accountRepository->findByFilters($filters, $page, $pageSize, $limit, $locale, $options); return array_map(function ($contact) use($locale) { return $this->getApiObject($contact, $locale); }, $entities); }
/** * Returns all accounts. * * @param $locale * @param null $filter * * @return array|null */ public function findAll($locale, $filter = null) { if ($filter) { $accountEntities = $this->accountRepository->findByFilter($filter); } else { $accountEntities = $this->accountRepository->findAll(); } if (!empty($accountEntities)) { $accounts = []; foreach ($accountEntities as $account) { $accounts[] = $this->accountFactory->createApiEntity($account, $locale); } return $accounts; } return; }
/** * @param Contact $contact * @param $data * * @throws EntityNotFoundException */ public function setMainAccount(Contact $contact, $data) { // set account relation if (isset($data['account']) && isset($data['account']['id']) && $data['account']['id'] != 'null') { $accountId = $data['account']['id']; $account = $this->accountRepository->findAccountById($accountId); if (!$account) { throw new EntityNotFoundException($this->accountRepository->getClassName(), $accountId); } // get position $position = null; if (isset($data['position'])) { $position = $this->getPosition($data['position']); } // check if relation between account and contact already exists $mainAccountContact = $this->getMainAccountContact($contact); $accountContact = $this->getAccounContact($account, $contact); // remove previous main accountContact if ($mainAccountContact && $mainAccountContact !== $accountContact) { // if this contact is the main-Contact - set mainContact to null if ($mainAccountContact->getAccount()->getMainContact() === $contact) { $mainAccountContact->getAccount()->setMainContact(null); } $this->em->remove($mainAccountContact); } // if account-contact relation existed set params if ($accountContact) { $accountContact->setMain(true); $accountContact->setPosition($position); } else { // else create new one $this->createMainAccountContact($contact, $account, $position); } } else { // if a main account exists - remove it if ($accountContact = $this->getMainAccountContact($contact)) { // if this contact is the main-Contact - set mainContact to null if ($accountContact->getAccount()->getMainContact() === $contact) { $accountContact->getAccount()->setMainContact(null); } $this->em->remove($accountContact); } } }
/** * Sets the customer account of an order. * * @param array $data * @param Order $order * @param bool $patch * * @throws MissingOrderAttributeException * @throws OrderDependencyNotFoundException * * @return null|object */ private function setCustomerAccount(array $data, Order $order, $patch = false) { $accountData = $this->getProperty($data, 'customerAccount'); if ($accountData) { if (!array_key_exists('id', $accountData)) { throw new MissingOrderAttributeException('account.id'); } $account = $this->accountRepository->find($accountData['id']); if (!$account) { throw new OrderDependencyNotFoundException('Account', $accountData['id']); } $order->setCustomerAccount($account); return $account; } elseif (!$patch) { $order->setCustomerAccount(null); } return null; }