fromholdio/silverstripe-sortable
Composer 安装命令:
composer require fromholdio/silverstripe-sortable
包简介
Adds an extension to make any SilverStripe DataObject sortable.
README 文档
README
Adds an extension to make any SilverStripe DataObject sortable.
That is, it does the basic lifting of:
- Adding a
Sortfield of typeDBIntto your object - Removing the scaffolded field from CMS fields
- Sets the
$default_sortof your object to'Sort' - Manages setting a
Sortvalue of the maximum + 1 upon first write, within a scope you define
Versioning
Through a bit of bungling, v1.1.1 and v2.1.1 are equal. For clarity, moving forward only 2.x will receive any necessary patches/fixes.
Return types have been added, and a new major version track has been established as v3.x. As such this will require PHP >=7.0, is now the primary track, and will receive any enhancements/features in future.
Requirements
SilverStripe 4 or 5
Installation
composer require fromholdio/silverstripe-sortable
Details
It's all plug-n-play once you apply the extension to your data object - with one exception.
To allow the extension to auto-generate a default value, based on maximum + 1, you need to tell the extension what the scope of the group you're getting that maximum value from is.
So, on the object you are extending/applying Sortable to, you can add a getSortableScope() method. This method should return a DataList on which sortable will run ->max('Sort') on.
In the absence of a getSortableScope() method, as a fallback the extension will get all objects of this type, excluding the current object, and run ->max('Sort') on this list.
See below for example.
Usage example
We are applying Sortable to a Widget data object:
class Widget extends DataObject { // or apply via config.yml private static $extensions = [ Sortable::class ]; public function getSortableScope() { # this is the default behaviour return self::get()->exclude('ID', $this->ID); } }
That's it! And it assumes that Widgets will be sorted amongst each other globally.
If Widgets had a one-many relationship with pages, and we want to sort them -per page- then we could do the following instead:
class Widget extends DataObject { private static $has_one = [ 'Page' => \Page::class // (assuming a has_many on Page for Widgets) ]; // or apply via config.yml private static $extensions = [ Sortable::class ]; public function getSortableScope() { return self::get() ->filter('PageID', $this->PageID) ->exclude('ID', $this->ID); } }
Depending on your data model structures, the ability to pass a scope DataList can be pretty useful. Have fun!
fromholdio/silverstripe-sortable 适用场景与选型建议
fromholdio/silverstripe-sortable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.56k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sortable」 「sort」 「silverstripe」 「dataobject」 「orderable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fromholdio/silverstripe-sortable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fromholdio/silverstripe-sortable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fromholdio/silverstripe-sortable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.
Syntactic sugar for PHP's sorting
Easily provide front-end sorting controls for SilverStripe lists
Plug-ins for DataTables
Symfony DataGridBundle
统计信息
- 总下载量: 1.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-02-18