/** * @param User $sender * @param array $usersByRestrictions * @return array */ private function prepareRecipients(User $sender, array $usersByRestrictions) { if (empty($usersByRestrictions)) { return []; } unset($usersByRestrictions['suspendedUsers'][$sender->getId()], $usersByRestrictions['activeUsers'][$sender->getId()]); if (!$this->authorizator->isAllowed($sender, 'message', 'send_to_restricted_recipients')) { $recipients = array_diff_key($usersByRestrictions['activeUsers'], $usersByRestrictions['suspendedUsers'], $usersByRestrictions['usersBlockedByMe'], $usersByRestrictions['usersBlockingMe']); } else { $recipients = $usersByRestrictions['activeUsers'] + $usersByRestrictions['usersBlockedByMe'] + $usersByRestrictions['usersBlockingMe']; } return Arrays::associate($recipients, 'id=username'); }
/** * @return ArrayHash|null */ public function loadOptions() { $options = $this->cache->load(Option::getCacheKey(), function () use(&$dependencies) { $options = $this->em->createQuery('SELECT o FROM ' . Option::class . ' o')->getArrayResult(); if (empty($options)) { return null; } $options = ArrayHash::from(Arrays::associate($options, 'name=value')); $dependencies = [Cache::TAGS => Option::getCacheKey()]; return $options; }); return $options; }
public function generate($year, User $user, array $settings = []) { $listings = $this->listingsReader->getAnnualListingsForPDFGeneration($year, $user); $listings = Arrays::associate($listings, 'l_id'); $items = $this->listingItemsReader->findListingsItems(array_keys($listings)); $pdfFiles = []; $listingItemsCollection = []; /** * @var int $listingId * @var IListingPdfSource $pdfSource */ foreach ($listings as $listingId => $listing) { foreach ($items as $key => $item) { if ($item->getListing()->getId() == $listingId) { $listingItemsCollection[] = $item; unset($items[$key]); } } $pdfFiles[] = $this->listingPdfGenerator->generate($listing, $listingItemsCollection, $settings); $listingItemsCollection = []; } $zipStorageFilePath = $this->storagePath . '/' . $user->getId() . '/' . $year . "/vycetky-{$year}.zip"; return $this->zipFiles($pdfFiles, $zipStorageFilePath); }
/** * @inheritDoc */ public function fetchAssoc($path) { $rows = array_map('iterator_to_array', $this->fetchAll()); return Nette\Utils\Arrays::associate($rows, $path); }
/** * @inheritDoc */ public function fetchAssoc($path) { return Nette\Utils\Arrays::associate($this->fetchAll(), $path); }
/** * Finds users that are blocked by or blocking given user * * @param User $user * @return array * @throws UserNotFoundException */ public function findRestrictedUsers(User $user) { $result = $this->usersReader->getUserWithRestrictedRelationships($user); if (empty($result)) { return $result; } $resultArray = ['usersBlockedByMe' => Arrays::associate($result[0]['usersBlockedByMe'], 'id'), 'usersBlockingMe' => Arrays::associate($result[0]['usersBlockingMe'], 'id')]; return $resultArray; }
/** * @param User|null $user * @return array */ public function getListingsYears(User $user = null) { return Arrays::associate($this->listingsReader->getListingsYears($user), 'year'); }
public function render() { $template = $this->getTemplate(); $template->setFile(__DIR__ . '/template.latte'); $paginator = $this['paginator']->getPaginator(); if (empty($this->users)) { $usersResultSet = $this->usersFacade->fetchUsers($this->usersQuery); $usersResultSet->applyPaginator($paginator, 15); $this->users = Arrays::associate($usersResultSet->toArray(AbstractQuery::HYDRATE_ARRAY), 'id'); unset($this->users[$this->userEntity->getId()]); } $template->users = $this->users; if (empty($this->alreadyBlockedUsers)) { $alreadyBlockedUsers = Arrays::associate($this->usersFacade->fetchUsers((new UsersOverviewQuery())->onlyWithFields(['id'])->findUsersBlockedBy($this->userEntity))->toArray(AbstractQuery::HYDRATE_ARRAY), 'id'); $this->alreadyBlockedUsers = $alreadyBlockedUsers; } if ($this->userEntity->isInRole('admin') and empty($this->usersWithClosedAccount)) { $uwca = Arrays::associate($this->usersFacade->fetchUsers((new UsersOverviewQuery())->onlyWithFields(['id'])->findUsersWithClosedAccount())->toArray(AbstractQuery::HYDRATE_ARRAY), 'id'); $this->usersWithClosedAccount = $uwca; } $template->areRelationshipsRestrictionsVisible = $this->areRelationshipsRestrictionsVisible; $template->isHintBoxVisible = $this->isHintBoxVisible; $template->render(); }