From 9e663145b0826db24e5235b8133d7017479965fe Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 26 Jul 2013 10:04:35 +0200 Subject: [PATCH] customer loop --- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Thelia/Core/Template/Loop/Customer.php | 140 ++++++++++++++++++ templates/default/customer.html | 40 +++++ 3 files changed, 181 insertions(+) create mode 100755 core/lib/Thelia/Core/Template/Loop/Customer.php create mode 100755 templates/default/customer.html diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index a8cf23d8a..80a7a4695 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -7,6 +7,7 @@ + diff --git a/core/lib/Thelia/Core/Template/Loop/Customer.php b/core/lib/Thelia/Core/Template/Loop/Customer.php new file mode 100755 index 000000000..31345e2b8 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Loop/Customer.php @@ -0,0 +1,140 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Loop; + +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Core\Template\Element\BaseLoop; +use Thelia\Core\Template\Element\LoopResult; +use Thelia\Core\Template\Element\LoopResultRow; + +use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Log\Tlog; + +use Thelia\Model\CustomerQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Type\TypeCollection; +use Thelia\Type; + +/** + * + * Customer loop + * + * + * Class Customer + * @package Thelia\Core\Template\Loop + * @author Etienne Roudeix + */ +class Customer extends BaseLoop +{ + /** + * @return ArgumentCollection + */ + protected function getArgDefinitions() + { + return new ArgumentCollection( + Argument::createBooleanTypeArgument('current', 1), + Argument::createIntListTypeArgument('id'), + new Argument( + 'ref', + new TypeCollection( + new Type\AlphaNumStringListType() + ) + ), + Argument::createBooleanTypeArgument('reseller'), + Argument::createIntTypeArgument('sponsor') + ); + } + + /** + * @param $pagination + * + * @return \Thelia\Core\Template\Element\LoopResult + */ + public function exec(&$pagination) + { + $search = CustomerQuery::create(); + + $current = $this->getCurrent(); + + if ($current === true) { + $currentCustomer = $this->request->getSession()->getCustomerUser(); + if($currentCustomer === null) { + return new LoopResult(); + } else { + $search->filterById($currentCustomer->getId(), Criteria::EQUAL); + } + } + + $id = $this->getId(); + + if (null !== $id) { + $search->filterById($id, Criteria::IN); + } + + $ref = $this->getRef(); + + if (null !== $ref) { + $search->filterByRef($ref, Criteria::IN); + } + + $reseller = $this->getReseller(); + + if ($reseller === true) { + $search->filterByReseller(1, Criteria::EQUAL); + } else if($reseller === false) { + $search->filterByReseller(0, Criteria::EQUAL); + } + + $sponsor = $this->getSponsor(); + + if ($sponsor !== null) { + $search->filterBySponsor($sponsor, Criteria::EQUAL); + } + + $customers = $this->search($search, $pagination); + + $loopResult = new LoopResult(); + + foreach ($customers as $customer) { + + if ($this->not_empty && $customer->countAllProducts() == 0) continue; + + $loopResultRow = new LoopResultRow(); + $loopResultRow->set("ID", $customer->getId()); + $loopResultRow->set("REF", $customer->getRef()); + $loopResultRow->set("TITLE", $customer->getTitleid()); + $loopResultRow->set("FIRSTNAME", $customer->getFirstname()); + $loopResultRow->set("LASTNAME", $customer->getLastname()); + $loopResultRow->set("EMAIL", $customer->getEmail()); + $loopResultRow->set("RESELLER", $customer->getReseller()); + $loopResultRow->set("SPONSOR", $customer->getSponsor()); + $loopResultRow->set("DISCOUNT", $customer->getDiscount()); + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } +} \ No newline at end of file diff --git a/templates/default/customer.html b/templates/default/customer.html new file mode 100755 index 000000000..4d7a30115 --- /dev/null +++ b/templates/default/customer.html @@ -0,0 +1,40 @@ + + {loop name="customer" type="customer"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {/loop} +
ID#ID
Réference#REF
Title#TITLE
Firstname#FIRSTNAME
Lastname#LASTNAME
Email#EMAIL
Is reseller#RESELLER
Sponsor#SPONSOR
Discount#DISCOUNT %
\ No newline at end of file