private function _fetchPaginationQueryBuilder($params, $queryBuilder) { $queryBuilder->setFirstResult($params['iDisplayStart'])->setMaxResults($params['iDisplayLength']); if (isset($params['order'])) { foreach ($params['order'] as $order) { $queryBuilder->addOrderBy($order['sort'], $order['order']); } } $query = $queryBuilder->getQuery()->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new Doctrine\ORM\Tools\Pagination\Paginator($query); $result['data'] = $paginator->getIterator(); $result['total'] = $paginator->count(); return $result; }
public function getList($q) { $this->checkPrivilege('read'); if (empty($q)) { throw new ApiException\ParameterMissingException(); } $query = Shopware()->Models()->createQuery($q); $query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //total count of result rows $totalResult = $paginator->count(); //item data as array $items = $paginator->getIterator()->getArrayCopy(); return array('data' => $items, 'total' => $totalResult); }
/** * @param int $offset * @param int $limit * @param array $criteria * @param array $orderBy * @return array */ public function getList($offset = 0, $limit = 25, array $criteria = array(), array $orderBy = array()) { $this->checkPrivilege('read'); $builder = $this->getRepository()->createQueryBuilder('Country'); $builder->addFilter($criteria); $builder->addOrderBy($orderBy); $builder->setFirstResult($offset)->setMaxResults($limit); $query = $builder->getQuery(); $query->setHydrationMode($this->getResultMode()); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $totalResult = $paginator->count(); //returns the User data $users = $paginator->getIterator()->getArrayCopy(); return array('data' => $users, 'total' => $totalResult); }
/** * List all entities. * * @param Request $request The request object. * @param ParamFetcherInterface $paramFetcher Param fetcher service. * @param string $fullMode Serialization mode for managers. * @param string $standardMode Default serialization mode. * * @return View */ protected function getAllItems(Request $request, ParamFetcherInterface $paramFetcher, $fullMode = null, $standardMode = null) { $this->checkUserAccess('get_all'); $offset = $paramFetcher->get('offset'); $offset = is_null($offset) ? 0 : intval($offset); $limit = $paramFetcher->get('limit'); $orderBy = $paramFetcher->get('orderBy'); $filterBy = $paramFetcher->get('filterBy'); $dbAdapter = $this->container->getParameter('nami_core.database_adapter'); $query = $this->getRepository()->getItems($this->getLoggedUser(), $offset, $limit, $orderBy, $filterBy); if ($dbAdapter === 'odm') { $count = $query->count(); $elements = $query->getQuery()->execute(); } else { $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); $count = $paginator->count(); $elements = $paginator->getIterator(); } $collection = new PaginatedCollection($elements, $offset, $limit, $count, $request->get('_route')); return $this->restView($collection, null, $fullMode, $standardMode); }
public function getKeyWords($parent, $orderInfos, $paging = array()) { $qb = $this->createQueryBuilder('kw'); $qb->andParentIs($parent); /* order */ if (is_array($orderInfos)) { if (array_key_exists('field', $orderInfos) && array_key_exists('dir', $orderInfos)) { $qb->orderBy('kw.' . $orderInfos['field'], $orderInfos['dir']); } } /* paging */ if (is_array($paging) && !empty($paging)) { if (array_key_exists('start', $paging) && array_key_exists('limit', $paging)) { $qb->setFirstResult($paging['start'])->setMaxResults($paging['limit']); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($qb); $result = iterator_to_array($paginator->getIterator()); } } else { $result = $qb->getQuery()->getResult(); } return $result; }
/** * @param int $offset * @param int $limit * @param array $criteria * @param array $orderBy * @return array */ public function getList($offset = 0, $limit = 100, array $criteria = array(), array $orderBy = array()) { $this->checkPrivilege('read'); $filter = array(); foreach ($criteria as $key => $value) { if (strpos($key, 'price.') === false) { $key = "price.{$key}"; } $filter[$key] = $value; } $builder = $this->queryBuilder(); $builder->addFilter($filter); $builder->addOrderBy($orderBy); $builder->setFirstResult($offset)->setMaxResults($limit); $query = $builder->getQuery(); $query->setHydrationMode($this->getResultMode()); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $totalResult = $paginator->count(); //returns the Price data $results = $paginator->getIterator()->getArrayCopy(); return array('data' => $results, 'offset' => $offset, 'limit' => $limit, 'total' => $totalResult); }
/** * Index action method */ public function indexAction() { $categoryId = (int)$this->Request()->getQuery('sCategory'); $sPage = !empty($this->Request()->sPage) ? (int)$this->Request()->sPage : 1; $sFilterDate = urldecode($this->Request()->sFilterDate); $sFilterAuthor = urldecode($this->Request()->sFilterAuthor); $sFilterTags = urldecode($this->Request()->sFilterTags); // PerPage if (!empty($this->Request()->sPerPage)) { Shopware()->Session()->sPerPage = (int)$this->Request()->sPerPage; } $sPerPage = Shopware()->Session()->sPerPage; if (empty($sPerPage)) { $sPerPage = (int)Shopware()->Config()->get('sARTICLESPERPAGE'); } $filter = $this->createFilter($sFilterDate, $sFilterAuthor, $sFilterTags); // Start for Limit $sLimitStart = ($sPage - 1) * $sPerPage; $sLimitEnd = $sPerPage; //get all blog articles $query = $this->getCategoryRepository()->getBlogCategoriesByParentQuery($categoryId); $blogCategories = $query->getArrayResult(); $blogCategoryIds = $this->getBlogCategoryListIds($blogCategories); $blogCategoryIds[] = $categoryId; $blogArticlesQuery = $this->getRepository()->getListQuery($blogCategoryIds, $sLimitStart, $sLimitEnd, $filter); $blogArticlesQuery->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($blogArticlesQuery); //returns the total count of the query $totalResult = $paginator->count(); //returns the blog article data $blogArticles = $paginator->getIterator()->getArrayCopy(); foreach ($blogArticles as $key => $blogArticle) { //adding number of comments to the blog article $blogArticles[$key]["numberOfComments"] = count($blogArticle["comments"]); //adding tags and tag filter links to the blog article $tagsQuery = $this->repository->getTagsByBlogId($blogArticle["id"]); $tagsData = $tagsQuery->getArrayResult(); $blogArticles[$key]["tags"] = $this->addLinksToFilter($tagsData, "sFilterTags", "name", false); //adding average vote data to the blog article $avgVoteQuery = $this->repository->getAverageVoteQuery($blogArticle["id"]); $blogArticles[$key]["sVoteAverage"] = $avgVoteQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_SINGLE_SCALAR); //adding thumbnails to the blog article if (!empty($blogArticle["media"][0]['mediaId'])) { /**@var $mediaModel \Shopware\Models\Media\Media*/ $mediaModel = Shopware()->Models()->find('Shopware\Models\Media\Media', $blogArticle["media"][0]['mediaId']); if ($mediaModel != null) { $blogArticles[$key]["preview"]["thumbNails"] = array_values($mediaModel->getThumbnails()); } } } //RSS and ATOM Feed part if ($this->Request()->getParam('sRss') || $this->Request()->getParam('sAtom')) { $this->Response()->setHeader('Content-Type', 'text/xml'); $type = $this->Request()->getParam('sRss') ? 'rss' : 'atom'; $this->View()->loadTemplate('frontend/blog/' . $type . '.tpl'); } $categoryContent = Shopware()->Modules()->Categories()->sGetCategoryContent($categoryId); $assigningData = array( 'sBanner' => Shopware()->Modules()->Marketing()->sBanner($categoryId), 'sBreadcrumb' => $this->getCategoryBreadcrumb($categoryId), 'sCategoryContent' => $categoryContent, 'sNumberArticles' => $totalResult, 'sPage' => $sPage, 'sFilterDate' => $this->getDateFilterData($blogCategoryIds, $filter), 'sFilterAuthor' => $this->getAuthorFilterData($blogCategoryIds, $filter), 'sFilterTags' => $this->getTagsFilterData($blogCategoryIds, $filter), 'sCategoryInfo' => $categoryContent, 'sBlogArticles' => $blogArticles ); $this->View()->assign(array_merge($assigningData, $this->getPagerData($totalResult, $sLimitEnd, $sPage, $categoryId))); }
/** * Retorna array com os objetos encontrados. * * @return array */ public function getResult() { return $this->result->getIterator(); }
/** * @param int $offset * @param int $limit * @param array $criteria * @param array $orderBy * @return array */ public function getList($offset = 0, $limit = 25, array $criteria = array(), array $orderBy = array()) { $this->checkPrivilege('read'); $builder = $this->getRepository()->createQueryBuilder('orders'); $builder->addFilter($criteria); $builder->addOrderBy($orderBy); $builder->setFirstResult($offset) ->setMaxResults($limit); $query = $builder->getQuery(); $query->setHydrationMode($this->getResultMode()); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $totalResult = $paginator->count(); //returns the order data $orders = $paginator->getIterator()->getArrayCopy(); foreach ($orders as &$order) { if (is_array($order)) { $order['paymentStatusId'] = $order['cleared']; $order['orderStatusId'] = $order['status']; unset($order['cleared']); unset($order['status']); } } return array('data' => $orders, 'total' => $totalResult); }
/** * Export articles as XML file */ protected function exportArticleXml() { $exportVariants = (bool) $this->Request()->getParam('exportVariants', false); $limit = $this->Request()->getParam('limit', 500000); if (!is_numeric($limit)) { $limit = 500000; } $offset = $this->Request()->getParam('offset', 0); if (!is_numeric($offset)) { $offset = 0; } $builder = $this->getArticleRepository()->createQueryBuilder('article'); $builder->select(array( 'article', 'mainDetail', 'mainDetailAttribute', 'mainDetailPrices', 'PARTIAL categories.{id}', 'PARTIAL similar.{id}', 'PARTIAL accessories.{id}', 'images', 'links', 'downloads', 'tax', 'customerGroups', 'propertyValues', )) ->leftJoin('article.mainDetail', 'mainDetail') ->leftJoin('mainDetail.attribute', 'mainDetailAttribute') ->leftJoin('mainDetail.prices', 'mainDetailPrices') ->leftJoin('article.tax', 'tax') ->leftJoin('article.categories', 'categories') ->leftJoin('article.links', 'links') ->leftJoin('article.images', 'images') ->leftJoin('article.downloads', 'downloads') ->leftJoin('article.related', 'accessories') ->leftJoin('article.propertyValues', 'propertyValues') ->leftJoin('article.similar', 'similar') ->leftJoin('article.customerGroups', 'customerGroups') ->where('images.parentId IS NULL'); if ($exportVariants) { $builder->addSelect(array( 'details', 'detailsAttribute', 'detailsPrices', )); $builder->leftJoin('article.details', 'details', 'WITH', 'details.kind = 2') ->leftJoin('details.prices', 'detailsPrices') ->leftJoin('details.attribute', 'detailsAttribute'); } $builder->setFirstResult($offset); $builder->setMaxResults($limit); $query = $builder->getQuery(); $query = $query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); $result = $paginator->getIterator()->getArrayCopy(); foreach ($result as $key => &$article) { foreach ($result[$key]['details'] as &$variant) { $variant['prices'] = $this->prepareXmlArray($variant['prices'], 'price'); } $article['variants'] = $this->prepareXmlArray($article['details'], 'variant'); unset($article['details']); $article['categories'] = $this->prepareXmlArray($article['categories'], 'category'); $article['related'] = $this->prepareXmlArray($article['related'], 'related'); $article['similar'] = $this->prepareXmlArray($article['similar'], 'similar'); $article['propertyValues'] = $this->prepareXmlArray($article['propertyValues'], 'propertyValue'); $article['mainDetail']['prices'] = $this->prepareXmlArray($article['mainDetail']['prices'], 'price'); } array_walk_recursive($result, function (&$value) { if ($value instanceof DateTime) { $value = $value->format('Y-m-d H:i:s'); } }); $this->Response()->setHeader('Content-Type', 'text/xml;charset=utf-8'); $this->Response()->setHeader('Content-Disposition', 'attachment; filename="export.articles.'.date("Y.m.d").'.xml"'); $this->Response()->setHeader('Content-Transfer-Encoding', 'binary'); $convert = new Shopware_Components_Convert_Xml(); $xmlmap = array("shopware" => array("articles" => array("article" => $result))); echo $convert->encode($xmlmap); return; }
/** * @param int $offset * @param int $limit * @param array $criteria * @param array $orderBy * @return array */ public function getList($offset = 0, $limit = 25, array $criteria = array(), array $orderBy = array()) { $this->checkPrivilege('read'); $query = $this->getRepository()->getListQuery($criteria, $orderBy, $limit, $offset); $query->setHydrationMode($this->resultMode); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $totalResult = $paginator->count(); //returns the category data $categories = $paginator->getIterator()->getArrayCopy(); return array('data' => $categories, 'total' => $totalResult); }
/** * Event listener function of the article backend module. * Will be fired when the user clicks the edit esd-button. */ public function getSerialsAction() { $esdId = $this->Request()->getParam('esdId'); $filter = $this->Request()->getParam('filter'); $sort = $this->Request()->getParam('sort'); $start = $this->Request()->getParam('start', 0); $limit = $this->Request()->getParam('limit', 20); $query = $this->getRepository()->getSerialsByEsdQuery($esdId, $filter, $start, $limit, $sort); $query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $totalResult = $paginator->count(); //returns the customer data $result = $paginator->getIterator()->getArrayCopy(); $this->View()->assign(array( 'data' => $result, 'total' => $totalResult, 'success' => true )); }
/** * The getPlugins function returns an array with the shop plugins. */ private function getPlugins($category = null, $offset = null, $limit = null, $orderBy = null, $filters = null) { $builder = Shopware()->Models()->createQueryBuilder(); $builder->select(array('plugins', 'licenses')) ->from('Shopware\Models\Plugin\Plugin', 'plugins') ->leftJoin('plugins.licenses', 'licenses') ->andWhere('plugins.capabilityEnable = 1'); if ($offset !== null && $limit !== null) { $builder->setFirstResult($offset) ->setMaxResults($limit); } if (!empty($orderBy)) { foreach($orderBy as $order) { if (empty($order) || empty($order['property'])) { continue; } $builder->addOrderBy('plugins.' . $order['property'], $order['direction']); } } if (!empty($category)) { $builder->andWhere('plugins.source = :source') ->setParameter('source', $category); } if (!empty($filters)) { foreach($filters as $filter) { if ($filter['property'] === 'free') { $builder->andWhere( $builder->expr()->orX( 'plugins.name LIKE :free', 'plugins.label LIKE :free', 'plugins.namespace LIKE :free', 'plugins.description LIKE :free', 'plugins.added LIKE :free', 'plugins.installed LIKE :free', 'plugins.updated LIKE :free', 'plugins.author LIKE :free' ) ); $builder->setParameter('free', '%' . $filter['value'] . '%'); } else { $builder->addFilter($filter); } } } $query = $builder->getQuery(); $query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $total = $paginator->count(); //returns the customer data $plugins = $paginator->getIterator()->getArrayCopy(); $plugins = $this->setPluginIcons($plugins); return array( 'plugins' => $plugins, 'total' => $total ); }
/** * Get a list of existing newslettes */ public function listNewslettersAction() { $filter = $this->Request()->getParam('filter', null); $sort = $this->Request()->getParam('sort', array(array('property' => 'mailing.date', 'direction' => 'DESC'))); $limit = $this->Request()->getParam('limit', 10); $offset = $this->Request()->getParam('start', 0); // Delete old previews $results = $this->getPreviewNewslettersQuery()->getResult(); foreach($results as $model) { Shopware()->Models()->remove($model); } Shopware()->Models()->flush(); // Get the revenue for the newsletters $sql = "SELECT partnerID, ROUND(SUM((o.invoice_amount_net-o.invoice_shipping_net)/currencyFactor),2) AS `revenue` FROM `s_order` as o WHERE o.status != 4 AND o.status != -1 AND o.partnerID <> '' GROUP BY o.partnerID"; $revenues = Shopware()->Db()->fetchAssoc($sql); //get newsletters $query = $this->getCampaignsRepository()->getListNewslettersQuery($filter, $sort, $limit, $offset); $query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); //returns the total count of the query $totalResult = $paginator->count(); //returns the customer data $result = $paginator->getIterator()->getArrayCopy(); // join newsletters and corrsponding revenues foreach($result as $key => $value){ // Groups are stored serialized in the database. // Here they will be unserialized and flattened in order to match the ExJS RecipientGroup store $result[$key]['groups'] = $this->unserializeGroup($result[$key]['groups']); $revenue = $revenues['sCampaign'. $value['id']]['revenue']; if($revenue !== null) { $result[$key]['revenue'] = $revenue; } } $this->View()->assign(array( 'success' => true, 'data' => $result, 'total' => $totalResult, )); }
/** * CRUD function of the document store. The function creates the order document with the passed * request parameters. */ public function createDocumentAction() { try { $orderId = $this->Request()->getParam('orderId', null); $documentType = $this->Request()->getParam('documentType', null); if (!empty($orderId) && !empty($documentType)) { $this->createDocument($orderId, $documentType); } $query = $this->getRepository()->getOrdersQuery(array(array('property' => 'orders.id', 'value' => $orderId)), null, 0, 1); $query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query); $order = $paginator->getIterator()->getArrayCopy(); $this->View()->assign(array( 'success' => true, 'data' => $order )); } catch (Exception $e) { $this->View()->assign(array( 'success' => false, 'data' => $this->Request()->getParams(), 'message' => $e->getMessage() )); } }