Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

リポジトリで組み立てているQueryBuilderをカスタマイズする機構を実装 #2285

Merged
merged 1 commit into from
Apr 26, 2017

Conversation

kiy0taka
Copy link
Contributor

概要(Overview・Refs Issue)

  • リポジトリで組み立てているQueryBuilderに対してソート順や検索条件をカスタマイズできる機構を追加

実装例

/**
 * @QueryExtension(ProductRepository::QUERY_KEY_SEARCH_ADMIN)
 */
class AdminProductListCustomizer extends OrderByCustomizer
{
    /**
     * 常に商品IDでソートする。
     *
     * @param array $params
     * @return OrderByClause[]
     */
    protected function createStatements($params)
    {
        return [new OrderByClause('p.id')];
    }
}

方針(Policy)

  • カスタマイズするためのインターフェイスとしては以下を提供
インターフェイス/クラス 概要
QueryCustomizer QueryBuilderを自由に変更
OrderByCustomizer ソート順を変更する
WhereCustomizer 検索条件を追加する
JoinCustomizer 結合するテーブルを追加する

テスト(Test)

  • 管理画面の商品マスターのソート順を商品IDに固定するサンプル
    • Acme\Entity\AdminProductListCustomizer

相談(Discussion)

  • QueryExtensionアノテーションに指定するキーを各リポジトリで定義しておくのか、どこかにまとめて定義したほうがいいのかどうか。

@Yangsin Yangsin added the enhancement 機能追加 label Apr 26, 2017
@Yangsin Yangsin modified the milestones: 3.0.15, 3.1.0 Apr 26, 2017
@Yangsin Yangsin merged commit 624c391 into EC-CUBE:experimental/3.1 Apr 26, 2017
@kiy0taka kiy0taka deleted the feature/query-customize branch April 27, 2017 00:24
@Yangsin Yangsin mentioned this pull request Jul 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants