在其页面的字段中对VirtualPages列表进行排序(Sorting list of VirtualPages on a field from its Page)

编程入门 行业动态 更新时间:2024-10-25 17:16:29
在其页面的字段中对VirtualPages列表进行排序(Sorting list of VirtualPages on a field from its Page)

我有$many_many VirtualPage s的$many_many :

class AreaPage extends Page {

    /**
     * @var array
     */
    private static $many_many = [
        'RelatedVirtualPages'  => 'VirtualPage'
    ];

    // ...

}
 

RelatedVirtualPages正在从ContentPage复制内容:

class ContentPage extends Page {

    /**
     * @var array
     */
    private static $db = [
        'Highlighted' => 'Boolean'
    ];

    // ...

}
 

在其正在复制的ContentPage的Highlighted数据库字段上排序RelatedVirtualPages的最佳方法是什么?

I have an AreaPage with $many_many VirtualPages:

class AreaPage extends Page {

    /**
     * @var array
     */
    private static $many_many = [
        'RelatedVirtualPages'  => 'VirtualPage'
    ];

    // ...

}
 

The RelatedVirtualPages are copying content from ContentPages:

class ContentPage extends Page {

    /**
     * @var array
     */
    private static $db = [
        'Highlighted' => 'Boolean'
    ];

    // ...

}
 

What's the best way to sort RelatedVirtualPages on the Highlighted db field of the ContentPage that it's copying?

最满意答案

虚拟页面可以指向不同类型的页面,并且没有强制规定所有这些页面都是ContentPages ,或者至少具有Hightlighted db字段的页面。 您可以在创建SiteTree时手动确保这SiteTree ,但用户可能会过来并将其搞砸,因此请记住这一点。

这里有一些伪码可以帮助你入门。 它假定所有虚拟页面都是ContentPages 。 如果您将有一个AreaPage引用的多种类型的VirtualPages ,那么这可能还不够。

$virtualPages = $myAreaPage->RelatedVirtualPages(); $contentSourcePages = ContentPage::get()->byIDs($virtualPage->column('CopyContentFromID')); $sortedSourcePages = $contentSourcePages->sort('Highlighted','ASC');

您可能也可以使用innerJoin ,但是您必须处理_Live表和可能的多个页表(如果不仅仅使用ContentPage作为VirtualPage ),这可能会导致一些复杂的情况。

更新

因此,总而言之,您需要一个VirtualContentPages列表,该列表链接到每个VirtualContentPage链接到的ContentPage的Highlighted字段中排序的特定AreaPage 。 如果这个摘要是准确的,这会工作:

$sortedVirtualPages = $myAreaPage->RelatedVirtualPages() ->innerJoin('ContentPage', '"ContentPage"."ID" = "VirtualContentPage"."CopyContentFromID"') ->sort('Highlighted DESC');

Virtual Pages could be pointed at pages of different types and there is no enforcement that all of those pages are ContentPages, or at least pages that have a Hightlighted db field. You can ensure this manually when you create your SiteTree, but users could come along and screw it up so keep this in mind.

Here is some psuedo-code that might help you get started. It assumes that all virtual pages are ContentPages. If you will have multiple types of VirtualPages referenced by an AreaPage then this is probably not sufficient.

$virtualPages = $myAreaPage->RelatedVirtualPages(); $contentSourcePages = ContentPage::get()->byIDs($virtualPage->column('CopyContentFromID')); $sortedSourcePages = $contentSourcePages->sort('Highlighted','ASC');

You possibly could also use an innerJoin, but then you have to deal with _Live tables and possibly multiple page tables (again if not just using ContentPage as VirtualPage) which could lead to some complicated scenarios.

Update

So, to summarize in my own words, you need a list of the VirtualContentPages linked to a specific AreaPage sorted on the Highlighted field from the ContentPage that each VirtualContentPage links to. If this summary is accurate, would this work:

$sortedVirtualPages = $myAreaPage->RelatedVirtualPages() ->innerJoin('ContentPage', '"ContentPage"."ID" = "VirtualContentPage"."CopyContentFromID"') ->sort('Highlighted DESC');

更多推荐

本文发布于:2023-07-22 19:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   中对   页面   列表   field

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!