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

プラグイン拡張サンプルを追加 #2346

Merged
merged 3 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/Plugin/EntityEvent/Entity/BaseInfoListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Plugin\EntityEvent\Entity;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Eccube\Annotation\PreUpdate;
use Eccube\Entity\Event\EntityEventListener;

/**
* @PreUpdate("Eccube\Entity\BaseInfo")
*/
class BaseInfoListener implements EntityEventListener
{
/**
* BaseInfoが更新されたタイミングで、更新前/更新後の値をerror_logで出力するサンプルです.
*
* @param LifecycleEventArgs $eventArgs
*/
public function execute(LifecycleEventArgs $eventArgs)
{
/** @var PreUpdateEventArgs $eventArgs */
if ($eventArgs->hasChangedField('company_name')) {
$new = $eventArgs->getNewValue('company_name');
$old = $eventArgs->getOldValue('company_name');

error_log($new);
error_log($old);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Plugin\EntityEvent\ServiceProvider;

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Plugin\EntityEvent\Entity\BaseInfoListener;
use Silex\Api\BootableProviderInterface;
use Silex\Application;

class EntityEventServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Container $app)
{
$app['plugin.entity_event.base_info_listener'] = function (Container $container) {
return new BaseInfoListener();
};
}

public function boot(Application $app)
{
$app['eccube.entity.event.dispatcher']
->addEventListener($app['plugin.entity_event.base_info_listener']);
}
}
5 changes: 5 additions & 0 deletions app/Plugin/EntityEvent/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Entityイベント拡張のサンプル
code: EntityEvent
version: 1.0.0
service:
- EntityEventServiceProvider
30 changes: 30 additions & 0 deletions app/Plugin/QueryCustomize/Entity/AdminCustomerCustomizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Plugin\QueryCustomize\Entity;

use Eccube\Annotation\QueryExtension;
use Eccube\Doctrine\Query\WhereClause;
use Eccube\Doctrine\Query\WhereCustomizer;
use Eccube\Repository\QueryKey;

/**
* @QueryExtension(QueryKey::CUSTOMER_SEARCH)
*/
class AdminCustomerCustomizer extends WhereCustomizer
{
/**
* 1回以上購入している会員を抽出
*
* @param array $params
* @param $queryKey
* @return WhereClause[]
*/
protected function createStatements($params, $queryKey)
{
// travis-ciのテストが通らないため、コメントアウト
// 試してみるにはコメントアウトを解除してください.
//return [WhereClause::gte('c.buy_times', ':buy_times', ['buy_times' => 1])];

return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Plugin\QueryCustomize\ServiceProvider;

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Plugin\QueryCustomize\Entity\AdminCustomerCustomizer;
use Silex\Api\BootableProviderInterface;
use Silex\Application;

class QueryCustomizeServiceProvider implements ServiceProviderInterface, BootableProviderInterface
{
public function register(Container $app)
{
$app['plugin.query_customize.customer_search'] = function (Container $container) {
return new AdminCustomerCustomizer();
};
}

public function boot(Application $app)
{
$app['eccube.queries']
->addCustomizer($app['plugin.query_customize.customer_search']);
}
}
5 changes: 5 additions & 0 deletions app/Plugin/QueryCustomize/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: クエリビルダ拡張のサンプル
code: QueryCustomize
version: 1.0.0
service:
- QueryCustomizeServiceProvider