当前位置: 首页>>代码示例>>PHP>>正文


PHP ProxyQueryInterface::setSortBy方法代码示例

本文整理汇总了PHP中Sonata\AdminBundle\Datagrid\ProxyQueryInterface::setSortBy方法的典型用法代码示例。如果您正苦于以下问题:PHP ProxyQueryInterface::setSortBy方法的具体用法?PHP ProxyQueryInterface::setSortBy怎么用?PHP ProxyQueryInterface::setSortBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sonata\AdminBundle\Datagrid\ProxyQueryInterface的用法示例。


在下文中一共展示了ProxyQueryInterface::setSortBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildPager

 /**
  * {@inheritdoc}
  */
 public function buildPager()
 {
     if ($this->bound) {
         return;
     }
     foreach ($this->getFilters() as $name => $filter) {
         list($type, $options) = $filter->getRenderSettings();
         $this->formBuilder->add($filter->getFormName(), $type, $options);
     }
     $this->formBuilder->add('_sort_by', 'hidden');
     $this->formBuilder->get('_sort_by')->addViewTransformer(new CallbackTransformer(function ($value) {
         return $value;
     }, function ($value) {
         return $value instanceof FieldDescriptionInterface ? $value->getName() : $value;
     }));
     $this->formBuilder->add('_sort_order', 'hidden');
     $this->formBuilder->add('_page', 'hidden');
     $this->formBuilder->add('_per_page', 'hidden');
     $this->form = $this->formBuilder->getForm();
     $this->form->submit($this->values);
     $data = $this->form->getData();
     foreach ($this->getFilters() as $name => $filter) {
         $this->values[$name] = isset($this->values[$name]) ? $this->values[$name] : null;
         $filter->apply($this->query, $data[$filter->getFormName()]);
     }
     if (isset($this->values['_sort_by'])) {
         if (!$this->values['_sort_by'] instanceof FieldDescriptionInterface) {
             throw new UnexpectedTypeException($this->values['_sort_by'], 'FieldDescriptionInterface');
         }
         if ($this->values['_sort_by']->isSortable()) {
             $this->query->setSortBy($this->values['_sort_by']->getSortParentAssociationMapping(), $this->values['_sort_by']->getSortFieldMapping());
             $this->query->setSortOrder(isset($this->values['_sort_order']) ? $this->values['_sort_order'] : null);
         }
     }
     $maxPerPage = 25;
     if (isset($this->values['_per_page'])) {
         // check for `is_array` can be safely removed if php 5.3 support will be dropped
         if (is_array($this->values['_per_page'])) {
             if (isset($this->values['_per_page']['value'])) {
                 $maxPerPage = $this->values['_per_page']['value'];
             }
         } else {
             $maxPerPage = $this->values['_per_page'];
         }
     }
     $this->pager->setMaxPerPage($maxPerPage);
     $page = 1;
     if (isset($this->values['_page'])) {
         // check for `is_array` can be safely removed if php 5.3 support will be dropped
         if (is_array($this->values['_page'])) {
             if (isset($this->values['_page']['value'])) {
                 $page = $this->values['_page']['value'];
             }
         } else {
             $page = $this->values['_page'];
         }
     }
     $this->pager->setPage($page);
     $this->pager->setQuery($this->query);
     $this->pager->init();
     $this->bound = true;
 }
开发者ID:clavier-souris,项目名称:SonataAdminBundle,代码行数:65,代码来源:Datagrid.php


注:本文中的Sonata\AdminBundle\Datagrid\ProxyQueryInterface::setSortBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。