【问题标题】:Sort Childobjects by specific value按特定值对子对象进行排序
【发布时间】:2020-09-21 12:29:15
【问题描述】:

我目前正在尝试按有效时间对我可以获得的所有 Childobjects 进行排序。

我当前的代码没有对任何东西进行排序:

$children = $this->productRepository->findByParent($product->getNumber());
        
        
foreach ($children as $child) {
    //debug::debug($child->getvalidityPeriod());
    $product->addChild($child);
}

正如在调试中已经看到的那样,$child->getvalidityPeriod() 可以将所需的信息作为整数获取。我想,一定有办法通过它们的validityPeriod对这个对象数组进行排序,但是我该如何管理呢?我需要创建一个新方法并在那里过滤它还是我可以在 ForEach 循环之前使用一些东西?

伪类:

$children = $this->productRepository->findByParent($product->getNumber());
ObjectSortFunction($children, 'getvalidityPeriod');

...and then for each...

如果有人能帮助我,那就太棒了!

【问题讨论】:

    标签: typo3 extbase typo3-extensions


    【解决方案1】:

    好的,经过几次尝试,我有一个解决方法,也可以用作答案;)

    我在我的 repo 中写了这个方法:

    public function findByParentSorted($parentId)
        {
            $query = $this->createQuery();
            $query->matching($query->equals('parent', $parentId));
            $query->setOrderings(
                [
                    'validity_period' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
                ]
            );
    
            return $query->execute();
        }
    

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多