searchLoopInterface + use in OrderLoop
This commit is contained in:
@@ -23,12 +23,18 @@
|
||||
|
||||
namespace Thelia\Core\Template\Element;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\Element\Exception\SearchLoopException;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Type\AlphaNumStringListType;
|
||||
use Thelia\Type\EnumListType;
|
||||
use Thelia\Type\EnumType;
|
||||
use Thelia\Type\TypeCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -84,13 +90,43 @@ abstract class BaseLoop
|
||||
*/
|
||||
protected function getDefaultArgs()
|
||||
{
|
||||
return array(
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
|
||||
$defaultArgs = array(
|
||||
Argument::createBooleanTypeArgument('backend_context', false),
|
||||
Argument::createBooleanTypeArgument('force_return', false),
|
||||
);
|
||||
|
||||
if(true === $this->countable) {
|
||||
$defaultArgs = array_merge($defaultArgs, array(
|
||||
Argument::createIntTypeArgument('offset', 0),
|
||||
Argument::createIntTypeArgument('page'),
|
||||
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
|
||||
));
|
||||
}
|
||||
|
||||
if($this instanceof SearchLoopInterface) {
|
||||
$defaultArgs = array_merge($defaultArgs, array(
|
||||
Argument::createAnyTypeArgument('search_term'),
|
||||
new Argument(
|
||||
'search_in',
|
||||
new TypeCollection(
|
||||
new EnumListType($this->getSearchIn())
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'search_mode',
|
||||
new TypeCollection(
|
||||
new EnumType(array(
|
||||
SearchLoopInterface::MODE_ANY_WORD,
|
||||
SearchLoopInterface::MODE_SENTENCE,
|
||||
SearchLoopInterface::MODE_STRICT_SENTENCE,
|
||||
))
|
||||
),
|
||||
SearchLoopInterface::MODE_STRICT_SENTENCE
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
return $defaultArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,6 +241,32 @@ abstract class BaseLoop
|
||||
*/
|
||||
protected function search(ModelCriteria $search, &$pagination = null)
|
||||
{
|
||||
if($this instanceof SearchLoopInterface) {
|
||||
$searchTerm = $this->getSearch_term();
|
||||
$searchIn = $this->getSearch_in();
|
||||
$searchMode = $this->getSearch_mode();
|
||||
if(null !== $searchTerm && null !== $searchIn) {
|
||||
|
||||
switch($searchMode) {
|
||||
case SearchLoopInterface::MODE_ANY_WORD:
|
||||
$searchCriteria = Criteria::IN;
|
||||
$searchTerm = explode(' ', $searchTerm);
|
||||
break;
|
||||
case SearchLoopInterface::MODE_SENTENCE:
|
||||
$searchCriteria = Criteria::EQUAL;
|
||||
$searchTerm = '%' . $searchTerm . '%';
|
||||
break;
|
||||
case SearchLoopInterface::MODE_STRICT_SENTENCE:
|
||||
$searchCriteria = Criteria::EQUAL;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->doSearch($search, $searchTerm, $searchIn, $searchCriteria);
|
||||
|
||||
$in = 'true';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getArgValue('page') !== null) {
|
||||
return $this->searchWithPagination($search, $pagination);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Element\Exception;
|
||||
|
||||
class SearchLoopException extends \RuntimeException
|
||||
{
|
||||
const UNKNOWN_EXCEPTION = 0;
|
||||
|
||||
public function __construct($message, $code = null, $arguments = array(), $previous = null)
|
||||
{
|
||||
if (is_array($arguments)) {
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
if ($code === null) {
|
||||
$code = self::UNKNOWN_EXCEPTION;
|
||||
}
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Core\Template\Element;
|
||||
|
||||
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface SearchLoopInterface
|
||||
{
|
||||
const MODE_ANY_WORD = 1;
|
||||
const MODE_SENTENCE = 2;
|
||||
const MODE_STRICT_SENTENCE = 3;
|
||||
|
||||
/**
|
||||
* @return array of available field to search in
|
||||
*/
|
||||
public function getSearchIn();
|
||||
|
||||
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria);
|
||||
}
|
||||
@@ -28,8 +28,12 @@ use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Element\SearchLoopInterface;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\OrderAddress;
|
||||
use Thelia\Model\OrderAddressQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
@@ -38,8 +42,9 @@ use Thelia\Type;
|
||||
* @package Thelia\Core\Template\Loop
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class Order extends BaseLoop
|
||||
class Order extends BaseLoop implements SearchLoopInterface
|
||||
{
|
||||
public $countable = true;
|
||||
public $timestampable = true;
|
||||
@@ -74,6 +79,59 @@ class Order extends BaseLoop
|
||||
);
|
||||
}
|
||||
|
||||
public function getSearchIn()
|
||||
{
|
||||
return array(
|
||||
"ref",
|
||||
"customer_ref",
|
||||
"customer_firstname",
|
||||
"customer_lastname",
|
||||
"customer_email",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderQuery $search
|
||||
* @param $searchTerm
|
||||
* @param $searchIn
|
||||
* @param $searchCriteria
|
||||
*/
|
||||
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
|
||||
{
|
||||
|
||||
$search->_and();
|
||||
foreach($searchIn as $index => $searchInElement) {
|
||||
if($index > 0) {
|
||||
$search->_or();
|
||||
}
|
||||
switch($searchInElement) {
|
||||
case "ref":
|
||||
$search->filterByRef($searchTerm, $searchCriteria);
|
||||
break;
|
||||
case "customer_ref":
|
||||
$search->filterByCustomer(
|
||||
CustomerQuery::create()->filterByRef($searchTerm, $searchCriteria)->find()
|
||||
);
|
||||
break;
|
||||
case "customer_firstname":
|
||||
$search->filterByOrderAddressRelatedByInvoiceOrderAddressId(
|
||||
OrderAddressQuery::create()->filterByFirstname($searchTerm, $searchCriteria)->find()
|
||||
);
|
||||
break;
|
||||
case "customer_lastname":
|
||||
$search->filterByOrderAddressRelatedByInvoiceOrderAddressId(
|
||||
OrderAddressQuery::create()->filterByLastname($searchTerm, $searchCriteria)->find()
|
||||
);
|
||||
break;
|
||||
case "customer_email":
|
||||
$search->filterByCustomer(
|
||||
CustomerQuery::create()->filterByEmail($searchTerm, $searchCriteria)->find()
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pagination
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Model\Base\OrderQuery as BaseOrderQuery;
|
||||
@@ -52,4 +53,5 @@ class OrderQuery extends BaseOrderQuery
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
} // OrderQuery
|
||||
|
||||
103
templates/admin/default/search.html
Normal file
103
templates/admin/default/search.html
Normal file
@@ -0,0 +1,103 @@
|
||||
{extends file="admin-layout.tpl"}
|
||||
|
||||
{block name="page-title"}{intl l='Modules'}{/block}
|
||||
|
||||
{block name="check-resource"}admin.configuration.search{/block}
|
||||
{block name="check-access"}view{/block}
|
||||
|
||||
{block name="main-content"}
|
||||
<div class="modules">
|
||||
|
||||
<div id="wrapper" class="container">
|
||||
|
||||
<div class="clearfix">
|
||||
<ul class="breadcrumb pull-left">
|
||||
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
|
||||
<li><a href="#">{intl l="Search"}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{module_include location='modules_top'}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
{* order search *}
|
||||
<div class="general-block-decorator">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-condensed table-left-aligned">
|
||||
<caption class="clearfix">
|
||||
{intl l='Orders'}
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l="Order n°"}</th>
|
||||
<th>{intl l="Date & Hour"}</th>
|
||||
<th>{intl l="Company"}</th>
|
||||
<th>{intl l="Name"}</th>
|
||||
<th>{intl l="Amount"}</th>
|
||||
<th>{intl l="Status"}</th>
|
||||
|
||||
<th class="actions">{intl l="Actions"}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{loop type="order" name="order-search" backend_context=1 customer="*" search_term=$smarty.get.search_term search_in="ref,customer_ref,customer_firstname,customer_lastname,customer_email"}
|
||||
{loop type="order_address" name="order-invoice-address" id=$INVOICE_ADDRESS}
|
||||
{assign "orderInvoiceFirstName" $FIRSTNAME}
|
||||
{assign "orderInvoiceLastName" $LASTNAME}
|
||||
{assign "orderInvoiceCompany" $COMPANY}
|
||||
{/loop}
|
||||
|
||||
{loop type="order-status" name="order-status" id=$STATUS}
|
||||
{assign "orderStatus" $TITLE}
|
||||
{assign "orderStatusLabel" "order_$CODE"}
|
||||
{/loop}
|
||||
|
||||
<tr>
|
||||
|
||||
<td><a href="{url path="/admin/order/update/$ID"}">{$REF}</a></td>
|
||||
<td>{format_date date=$CREATE_DATE}</td>
|
||||
<td>{$orderInvoiceCompany}</td>
|
||||
<td><a href="{url path="/admin/customer/update/$CUSTOMER"}">{$orderInvoiceFirstName|ucwords} {$orderInvoiceLastName|upper}</a></td>
|
||||
<td>{$TOTAL_TAXED_AMOUNT}</td>
|
||||
<td><span class="label label-{#$orderStatusLabel#}">{$orderStatus}</span></td>
|
||||
|
||||
{module_include location='orders_table_row'}
|
||||
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
||||
{loop type="auth" name="can_change" role="ADMIN" resource="admin.order" access="UPDATE"}
|
||||
<a class="btn btn-default btn-xs" title="{intl l='Edit this order'}" href="{url path="/admin/order/update/$ID"}"><span class="glyphicon glyphicon-edit"></span></a>
|
||||
{if $STATUS !== 5}
|
||||
<a class="btn btn-default btn-xs order-cancel" title="{intl l='Cancel this order'}" href="#cancel_order_dialog" data-id="{$ID}" data-toggle="modal"><span class="glyphicon glyphicon-remove-sign"></span></a>
|
||||
{/if}
|
||||
{/loop}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/loop}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{* end order search *}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{module_include location='modules_bottom'}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/block}
|
||||
|
||||
{block name="javascript-initialization"}
|
||||
|
||||
|
||||
<script>
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user