Skip to content

Commit

Permalink
Merge pull request #2346 from chihiro-adachi/dev-ext-sample
Browse files Browse the repository at this point in the history
プラグイン拡張サンプルを追加
  • Loading branch information
kiy0taka authored May 30, 2017
2 parents e275172 + 77e8bcc commit 777914a
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
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

0 comments on commit 777914a

Please sign in to comment.