Merge pull request #509 from lovenunu/export

Exports and Imports
This commit is contained in:
Julien
2014-08-04 19:15:06 +02:00
163 changed files with 36150 additions and 116 deletions

View File

@@ -10,6 +10,7 @@
- Update SwiftMailer
- Fix bugs on customer change password form and module "order by title"
- Add the ability to place a firewall on forms. To use this in a module, extend Thelia\Form\FirewallForm instead of BaseForm
- Add Exports and Imports management
#2.0.2
- Coupon UI has been redesigned.

View File

@@ -0,0 +1,88 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Action;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Cache\CacheEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\ExportCategoryQuery;
use Thelia\Model\ExportQuery;
/**
* Class Export
* @package Thelia\Action
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class Export extends BaseAction implements EventSubscriberInterface
{
protected $environment;
public function __construct($environment)
{
$this->environment = $environment;
}
public function changeCategoryPosition(UpdatePositionEvent $event)
{
$this->genericUpdatePosition(new ExportCategoryQuery(), $event);
$this->cacheClear($event->getDispatcher());
}
public function changeExportPosition(UpdatePositionEvent $event)
{
$this->genericUpdatePosition(new ExportQuery(), $event);
$this->cacheClear($event->getDispatcher());
}
protected function cacheClear(EventDispatcherInterface $dispatcher)
{
$cacheEvent = new CacheEvent(
$this->environment
);
$dispatcher->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent);
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::EXPORT_CATEGORY_CHANGE_POSITION => array("changeCategoryPosition", 128),
TheliaEvents::EXPORT_CHANGE_POSITION => array("changeExportPosition", 128),
);
}
}

View File

@@ -0,0 +1,88 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Action;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Cache\CacheEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Model\ImportCategoryQuery;
use Thelia\Model\ImportQuery;
/**
* Class Import
* @package Thelia\Action
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class Import extends BaseAction implements EventSubscriberInterface
{
protected $environment;
public function __construct($environment)
{
$this->environment = $environment;
}
public function changeCategoryPosition(UpdatePositionEvent $event)
{
$this->genericUpdatePosition(new ImportCategoryQuery(), $event);
$this->cacheClear($event->getDispatcher());
}
public function changeImportPosition(UpdatePositionEvent $event)
{
$this->genericUpdatePosition(new ImportQuery(), $event);
$this->cacheClear($event->getDispatcher());
}
protected function cacheClear(EventDispatcherInterface $dispatcher)
{
$cacheEvent = new CacheEvent(
$this->environment
);
$dispatcher->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent);
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::IMPORT_CATEGORY_CHANGE_POSITION => array("changeCategoryPosition", 128),
TheliaEvents::IMPORT_CHANGE_POSITION => array("changeImportPosition", 128),
);
}
}

View File

@@ -27,4 +27,16 @@
</services>
-->
<!--
<exports>
</exports>
-->
<!--
<imports>
</imports>
-->
</config>

View File

@@ -163,6 +163,16 @@
<service id="thelia.action.lang" class="Thelia\Action\Lang">
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.export.change_position" class="Thelia\Action\Export">
<argument>%kernel.cache_dir%</argument>
<tag name="kernel.event_subscriber" />
</service>
<service id="thelia.import.change_position" class="Thelia\Action\Import">
<argument>%kernel.cache_dir%</argument>
<tag name="kernel.event_subscriber" />
</service>
</services>
</config>

View File

@@ -34,6 +34,8 @@
<parameter key="image.brand">Thelia\Model\BrandImage</parameter>
</parameter>
<parameter key="import.base_url">/admin/import</parameter>
<parameter key="export.base_url">/admin/export</parameter>
</parameters>
@@ -135,6 +137,47 @@
<service id="session.listener" class="Thelia\Core\EventListener\SessionListener">
<tag name="kernel.event_subscriber"/>
</service>
</services>
<!-- Archive builders -->
<service id="thelia.manager.archive_builder_manager" class="Thelia\Core\FileFormat\Archive\ArchiveBuilderManager">
<argument>%kernel.environment%</argument>
</service>
<!-- zip -->
<service id="thelia.archive_builder.zip" class="Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveBuilder">
<tag name="thelia.archive_builder" />
</service>
<!-- tar -->
<service id="thelia.archive_builder.tar" class="Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder">
<tag name="thelia.archive_builder" />
</service>
<!-- tar.gz -->
<service id="thelia.archive_builder.tar_gz" class="Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder">
<tag name="thelia.archive_builder" />
</service>
<!-- tar.bz2 -->
<service id="thelia.archive_builder.tar_bz2" class="Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder">
<tag name="thelia.archive_builder" />
</service>
<!-- Formatters -->
<service id="thelia.manager.formatter_manager" class="Thelia\Core\FileFormat\Formatting\FormatterManager" />
<service id="thelia.formatter.xml_formatter" class="Thelia\Core\FileFormat\Formatting\Formatter\XMLFormatter">
<tag name="thelia.formatter" />
</service>
<service id="thelia.formatter.json_formatter" class="Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter">
<tag name="thelia.formatter" />
</service>
<service id="thelia.formatter.csv_formatter" class="Thelia\Core\FileFormat\Formatting\Formatter\CSVFormatter">
<tag name="thelia.formatter" />
</service>
</services>
</config>

View File

@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<export_categories>
<export_category id="thelia.export.customer">
<title locale="en_US">Customers</title>
<title locale="fr_FR">Clients</title>
</export_category>
<export_category id="thelia.export.products">
<title locale="en_US">Products</title>
<title locale="fr_FR">Produits</title>
</export_category>
<export_category id="thelia.export.content">
<title locale="en_US">Content</title>
<title locale="fr_FR">Contenu</title>
</export_category>
<export_category id="thelia.export.orders">
<title locale="en_US">Orders</title>
<title locale="fr_FR">Commandes</title>
</export_category>
</export_categories>
<exports>
<export id="thelia.export.mailing" category_id="thelia.export.customer" class="Thelia\ImportExport\Export\Type\MailingExport">
<export_descriptive locale="fr_FR">
<title>Mailing</title>
<description>Exporter le nom, prénom et adresse mail des clients inscrits et des abonnées à la newsletter</description>
</export_descriptive>
<export_descriptive locale="en_US">
<title>Mailing</title>
<description>Export the last name, first name and email address of the customers and the newsletter subscribers</description>
</export_descriptive>
</export>
<export id="thelia.export.complete" category_id="thelia.export.customer" class="Thelia\ImportExport\Export\Type\CustomerExport">
<export_descriptive locale="fr_FR">
<title>Clients</title>
<description>Exporter toutes les informations à propos de vos clients</description>
</export_descriptive>
<export_descriptive locale="en_US">
<title>Customers</title>
<description>Export all the information about your customers</description>
</export_descriptive>
</export>
<export id="thelia.export.prices" class="Thelia\ImportExport\Export\Type\ProductPricesExport" category_id="thelia.export.products">
<export_descriptive locale="fr_FR">
<title>Prix des produits Hors-Taxes</title>
<description>Expotez le prix hors taxes de vos produits</description>
</export_descriptive>
<export_descriptive locale="en_US">
<title>Product prices excluding taxes</title>
<description>Export the prices of the products excluding taxes</description>
</export_descriptive>
</export>
<export id="thelia.export.taxed_prices" class="Thelia\ImportExport\Export\Type\ProductTaxedPricesExport" category_id="thelia.export.products">
<export_descriptive locale="fr_FR">
<title>Prix des produits TTC</title>
<description>Expotez le prix TTC de vos produits</description>
</export_descriptive>
<export_descriptive locale="en_US">
<title>Product prices including taxes</title>
<description>Export the prices of the products including taxes</description>
</export_descriptive>
</export>
<export id="thelia.export.product_seo" class="Thelia\ImportExport\Export\Type\ProductSEOExport" category_id="thelia.export.products">
<export_descriptive locale="en_US">
<title>Product SEO information</title>
<description>
Export the SEO information ( rewritten url, meta description and keywords, page title ) of your products
</description>
</export_descriptive>
<export_descriptive locale="fr_FR">
<title>Informations SEO des produits</title>
<description>
Exportez les informations SEO de vos produits
( url réécrites, meta description et mots clés, titre ) de vos produits
</description>
</export_descriptive>
</export>
<export id="thelia.export.content" class="Thelia\ImportExport\Export\Type\ContentExport" category_id="thelia.export.content">
<export_descriptive locale="en_US">
<title>Contents and folder</title>
<description>
Export your contents and their related folders
</description>
</export_descriptive>
<export_descriptive locale="fr_FR">
<title>Contenus et dossiers</title>
<description>
Exportez vos contenus et les dossiers associés
</description>
</export_descriptive>
</export>
<export id="thelia.export.orders" class="Thelia\ImportExport\Export\Type\OrderExport" category_id="thelia.export.orders">
<export_descriptive locale="en_US">
<title>Full orders</title>
<description>
Export your orders.
</description>
</export_descriptive>
<export_descriptive locale="fr_FR">
<title>Commandes complètes</title>
<description>
Exportez vos commandes
</description>
</export_descriptive>
</export>
</exports>
</config>

View File

@@ -133,6 +133,9 @@
<form name="thelia.assets.flush" class="Thelia\Form\Cache\AssetsFlushForm"/>
<form name="thelia.images-and-documents-cache.flush" class="Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm"/>
<form name="thelia.export" class="Thelia\Form\ExportForm" />
<form name="thelia.import" class="Thelia\Form\ImportForm" />
</forms>
</config>

View File

@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<import_categories>
<import_category id="thelia.import.products">
<title locale="fr_FR">Produits</title>
<title locale="en_US">Products</title>
</import_category>
</import_categories>
<imports>
<import id="thelia.import.stock" class="Thelia\ImportExport\Import\Type\ProductStockImport" category_id="thelia.import.products">
<import_descriptive locale="fr_FR">
<title>Importez votre stock</title>
<description>
<![CDATA[
Your file must have the following columns to work:
<ul>
<li>ref: The reference of your product Attribute Combinations </li>
<li>stock: The quantity of product you have </li>
</ul>
]]>
</description>
</import_descriptive>
<import_descriptive locale="en_US">
<title>Import your stock</title>
<description>
<![CDATA[
Your file must have the following columns to work:
<ul>
<li>ref: The reference of your product attribute combinations </li>
<li>stock: The quantity of product you have </li>
</ul>
It can have the column "ean" that defines the product's EAN code.
]]>
</description>
</import_descriptive>
</import>
<import id="thelia.import.price" class="Thelia\ImportExport\Import\Type\ProductPricesImport" category_id="thelia.import.products">
<import_descriptive locale="fr_FR">
<title>Importez vos prix Hors-Taxes</title>
<description>
<![CDATA[
Votre fichier doit avoir les colonnes suivantes:
<ul>
<li>ref: La reférénce de votre déclinaison de combinaison de produit</li>
<li>price: Le prix Hors-Taxes de votre déclinaison de combinaison de produit</li>
</ul>
Il peut aussi optionnellement avoir ces colonnes:
<ul>
<li>currency: Le code de la monnaie (exemple: EUR, USD)</li>
<li>promo_price: Le prix promotionnel Hors-Taxes de votre déclinaison de combinaison de produit</li>
<li>promo: Si cette valeur est a 0, désactive la promotion, si elle est a 1, l'active</li>
</ul>
]]>
</description>
</import_descriptive>
<import_descriptive locale="en_US">
<title>Import your prices excluding taxes</title>
<description>
<![CDATA[
Your file must have the following columns:
<ul>
<li>ref: The reference of the product attribute combinations</li>
<li>price: The price excluding taxes of the product attribute combinations</li>
</ul>
It may also optionally have those columns:
<ul>
<li>currency: the currency code (example: EUR, USD)</li>
<li>promo_price: the promo price excluding taxes of the product attribute combinations</li>
<li>promo: If this value is 0, set the product not in promo, if 1, it sets the product in promo</li>
</ul>
]]>
</description>
</import_descriptive>
</import>
</imports>
</config>

View File

@@ -55,6 +55,12 @@
<loop class="Thelia\Core\Template\Loop\Tax" name="tax"/>
<loop class="Thelia\Core\Template\Loop\TaxRule" name="tax-rule"/>
<loop class="Thelia\Core\Template\Loop\TaxRuleCountry" name="tax-rule-country"/>
<loop class="Thelia\Core\Template\Loop\Formatter" name="formatter" />
<loop class="Thelia\Core\Template\Loop\ArchiveBuilder" name="archive-builder" />
<loop class="Thelia\Core\Template\Loop\ImportCategory" name="import-category" />
<loop class="Thelia\Core\Template\Loop\ExportCategory" name="export-category" />
<loop class="Thelia\Core\Template\Loop\Import" name="import" />
<loop class="Thelia\Core\Template\Loop\Export" name="export" />
</loops>

View File

@@ -1158,17 +1158,6 @@
<default key="_controller">Thelia\Controller\Admin\TranslationsController::updateAction</default>
</route>
<!-- export management -->
<route id="export.main" path="/admin/export">
<default key="_controller">Thelia\Controller\Admin\ExportController::indexAction</default>
</route>
<route id="export.customer.newsletter" path="/admin/export/customer/newsletter">
<default key="_controller">Thelia\Controller\Admin\CustomerExportController::newsletterExportAction</default>
</route>
<!-- Routes to the Brands controller -->
<route id="admin.brand.default" path="/admin/brand">
@@ -1205,6 +1194,54 @@
<default key="_controller">Thelia\Controller\Admin\BrandController::deleteAction</default>
</route>
<!-- export management -->
<route id="export.list" path="/admin/export">
<default key="_controller">Thelia\Controller\Admin\ExportController::indexAction</default>
</route>
<route id="export.position" path="/admin/export/position">
<default key="_controller">Thelia\Controller\Admin\ExportController::changePosition</default>
</route>
<route id="export.category.position" path="/admin/export/position/category">
<default key="_controller">Thelia\Controller\Admin\ExportController::changeCategoryPosition</default>
</route>
<route id="export.mode" path="/admin/export/{id}" methods="post">
<default key="_controller">Thelia\Controller\Admin\ExportController::export</default>
<requirement key="id">\d+</requirement>
</route>
<route id="export.view" path="/admin/export/{id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\ExportController::exportView</default>
<requirement key="id">\d+</requirement>
</route>
<!-- import management -->
<route id="import.list" path="/admin/import">
<default key="_controller">Thelia\Controller\Admin\ImportController::indexAction</default>
</route>
<route id="import.position" path="/admin/import/position">
<default key="_controller">Thelia\Controller\Admin\ImportController::changePosition</default>
</route>
<route id="import.category.position" path="/admin/import/position/category">
<default key="_controller">Thelia\Controller\Admin\ImportController::changeCategoryPosition</default>
</route>
<route id="import.mode" path="/admin/import/{id}" methods="post">
<default key="_controller">Thelia\Controller\Admin\ImportController::import</default>
<requirement key="id">\d+</requirement>
</route>
<route id="import.view" path="/admin/import/{id}" methods="get">
<default key="_controller">Thelia\Controller\Admin\ImportController::importView</default>
<requirement key="id">\d+</requirement>
</route>
<!-- The default route, to display a template -->
<route id="admin.processTemplate" path="/admin/{template}">

View File

@@ -1,66 +0,0 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Model\NewsletterQuery;
/**
* Class CustomerExportController
* @package Thelia\Controller\Admin
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class CustomerExportController extends BaseAdminController
{
public function newsletterExportAction()
{
if (null !== $response = $this->checkAuth([AdminResources::EXPORT_CUSTOMER_NEWSLETTER], [], [AccessManager::VIEW])) {
return $response;
}
$data = NewsletterQuery::create()
->select([
'email',
'firstname',
'lastname',
'locale'
])
->find();
$handle = fopen('php://memory', 'r+');
fputcsv($handle, ['email','firstname','lastname','locale'], ';', '"');
foreach ($data->toArray() as $customer) {
fputcsv($handle, $customer, ';', '"');
}
rewind($handle);
$content = stream_get_contents($handle);
fclose($handle);
return Response::create(
$content,
200,
array(
"Content-Type"=>"application/csv-tab-delimited-table",
"Content-disposition"=>"filename=export_customer_newsletter.csv"
)
);
}
}

View File

@@ -12,8 +12,27 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManagerTrait;
use Thelia\Core\FileFormat\Formatting\FormatterManagerTrait;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Loop\Export as ExportLoop;
use Thelia\Core\Event\ImportExport as ImportExportEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Form\ExportForm;
use Thelia\ImportExport\Export\DocumentsExportInterface;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\ImportExport\Export\ImagesExportInterface;
use Thelia\Model\ExportCategoryQuery;
use Thelia\Model\ExportQuery;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
/**
* Class ExportController
@@ -22,6 +41,8 @@ use Thelia\Core\Security\Resource\AdminResources;
*/
class ExportController extends BaseAdminController
{
use ArchiveBuilderManagerTrait;
use FormatterManagerTrait;
public function indexAction()
{
@@ -29,6 +50,394 @@ class ExportController extends BaseAdminController
return $response;
}
$this->setOrders();
return $this->render('export');
}
/**
* @param integer $id
* @return Response
*
* This method is called when the route /admin/export/{id}
* is called with a POST request.
*/
public function export($id)
{
if (null === $export = $this->getExport($id)) {
return $this->render("404");
}
/**
* Get needed services
*/
$archiveBuilderManager = $this->getArchiveBuilderManager($this->container);
$formatterManager = $this->getFormatterManager($this->container);
/**
* Get the archive builders
*/
$archiveBuilders = [];
foreach ($archiveBuilderManager->getNames() as $archiveBuilder) {
$archiveBuilders[$archiveBuilder] = $archiveBuilder;
}
/**
* Define and validate the form
*/
$form = new ExportForm($this->getRequest());
$errorMessage = null;
try {
$boundForm = $this->validateForm($form);
$lang = LangQuery::create()->findPk(
$boundForm->get("language")->getData()
);
$archiveBuilder = null;
/**
* Get the formatter and the archive builder if we have to compress the file(s)
*/
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
$formatter = $formatterManager->get(
$boundForm->get("formatter")->getData()
);
if ($boundForm->get("do_compress")->getData()) {
/** @var \Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface $archiveBuilder */
$archiveBuilder = $archiveBuilderManager->get(
$boundForm->get("archive_builder")->getData()
);
}
/**
* Return the generated Response
*/
return $this->processExport(
$formatter,
$export->getHandleClassInstance($this->container),
$archiveBuilder,
$lang,
$boundForm->get("images")->getData(),
$boundForm->get("documents")->getData()
);
} catch (FormValidationException $e) {
$errorMessage = $this->createStandardFormValidationErrorMessage($e);
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
}
/**
* If has an error, display it
*/
if (null !== $errorMessage) {
$form->setErrorMessage($errorMessage);
$this->getParserContext()
->addForm($form)
->setGeneralError($errorMessage)
;
}
return $this->exportView($id);
}
/**
* @param AbstractFormatter $formatter
* @param ExportHandler $handler
* @param AbstractArchiveBuilder $archiveBuilder
* @param bool $includeImages
* @param bool $includeDocuments
* @return Response
*
* Processes an export by returning a response with the export's content.
*/
protected function processExport(
AbstractFormatter $formatter,
ExportHandler $handler,
AbstractArchiveBuilder $archiveBuilder = null,
Lang $lang,
$includeImages = false,
$includeDocuments = false
) {
/**
* Build an event containing the formatter and the handler.
* Used for specific configuration (e.g: XML node names)
*/
$event = new ImportExportEvent($formatter, $handler);
$filename = $formatter::FILENAME . "." . $formatter->getExtension();
if ($archiveBuilder === null) {
$data = $handler->buildData($lang);
$event->setData($data);
$this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
$formattedContent = $formatter
->setOrder($handler->getOrder())
->encode($data)
;
$this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
return new Response(
$event->getContent(),
200,
[
"Content-Type" => $formatter->getMimeType(),
"Content-Disposition" =>
"attachment; filename=\"" . $filename . "\"",
]
);
} else {
$event->setArchiveBuilder($archiveBuilder);
if ($includeImages && $handler instanceof ImagesExportInterface) {
$this->processExportImages($handler, $archiveBuilder);
$handler->setImageExport(true);
}
if ($includeDocuments && $handler instanceof DocumentsExportInterface) {
$this->processExportDocuments($handler, $archiveBuilder);
$handler->setDocumentExport(true);
}
$data = $handler
->buildData($lang)
->setLang($lang)
;
$this->dispatch(TheliaEvents::EXPORT_BEFORE_ENCODE, $event);
$formattedContent = $formatter
->setOrder($handler->getOrder())
->encode($data)
;
$this->dispatch(TheliaEvents::EXPORT_AFTER_ENCODE, $event->setContent($formattedContent));
$archiveBuilder->addFileFromString(
$event->getContent(), $filename
);
return $archiveBuilder->buildArchiveResponse($formatter::FILENAME);
}
}
/**
* @param ImagesExportInterface $handler
* @param AbstractArchiveBuilder $archiveBuilder
*
* Procedure that add images in the export's archive
*/
protected function processExportImages(ImagesExportInterface $handler, AbstractArchiveBuilder $archiveBuilder)
{
foreach ($handler->getImagesPaths() as $name => $documentPath) {
$archiveBuilder->addFile(
$documentPath,
$handler::IMAGES_DIRECTORY,
is_integer($name) ? null : $name
);
}
}
/**
* @param DocumentsExportInterface $handler
* @param AbstractArchiveBuilder $archiveBuilder
*
* Procedure that add documents in the export's archive
*/
protected function processExportDocuments(DocumentsExportInterface $handler, AbstractArchiveBuilder $archiveBuilder)
{
foreach ($handler->getDocumentsPaths() as $name => $documentPath) {
$archiveBuilder->addFile(
$documentPath,
$handler::DOCUMENTS_DIRECTORY,
is_integer($name) ? null : $name
);
}
}
/**
* @param integer $id
* @return Response
*
* This method is called when the route /admin/export/{id}
* is called with a GET request.
*
* It returns a modal view if the request is an AJAX one,
* otherwise it generates a "normal" back-office page
*/
public function exportView($id)
{
if (null === $export = $this->getExport($id)) {
return $this->render("404");
}
/**
* Use the loop to inject the same vars in Smarty
*/
$loop = new ExportLoop($this->container);
$loop->initializeArgs([
"id" => $export->getId()
]);
$query = $loop->buildModelCriteria();
$result= $query->find();
$results = $loop->parseResults(
new LoopResult($result)
);
$parserContext = $this->getParserContext();
/** @var \Thelia\Core\Template\Element\LoopResultRow $row */
foreach ($results as $row) {
foreach ($row->getVarVal() as $name=>$value) {
$parserContext->set($name, $value);
}
}
/**
* Inject conditions in smarty,
* It is used to display or not the checkboxes "Include images"
* and "Include documents"
*/
$this->getParserContext()
->set("HAS_IMAGES", $export->hasImages($this->container))
->set("HAS_DOCUMENTS", $export->hasDocuments($this->container))
->set("CURRENT_LANG_ID", $this->getSession()->getLang()->getId())
;
/** Then render the form */
if ($this->getRequest()->isXmlHttpRequest()) {
return $this->render("ajax/export-modal");
} else {
return $this->render("export-page");
}
}
public function changePosition()
{
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) {
return $response;
}
$query = $this->getRequest()->query;
$mode = $query->get("mode");
$id = $query->get("id");
$value = $query->get("value");
$this->getExport($id);
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
$this->dispatch(TheliaEvents::EXPORT_CHANGE_POSITION, $event);
$this->setOrders(null, "manual");
return $this->render('export');
}
public function changeCategoryPosition()
{
if (null !== $response = $this->checkAuth([AdminResources::EXPORT], [], [AccessManager::UPDATE])) {
return $response;
}
$query = $this->getRequest()->query;
$mode = $query->get("mode");
$id = $query->get("id");
$value = $query->get("value");
$this->getCategory($id);
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
$this->dispatch(TheliaEvents::EXPORT_CATEGORY_CHANGE_POSITION, $event);
$this->setOrders("manual");
return $this->render('export');
}
public function getMode($action)
{
if ($action === "up") {
$mode = UpdatePositionEvent::POSITION_UP;
} elseif ($action === "down") {
$mode = UpdatePositionEvent::POSITION_DOWN;
} else {
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
}
return $mode;
}
protected function setOrders($category = null, $export = null)
{
if ($category === null) {
$category = $this->getRequest()->query->get("category_order", "manual");
}
if ($export === null) {
$export = $this->getRequest()->query->get("export_order", "manual");
}
$this->getParserContext()
->set("category_order", $category)
;
$this->getParserContext()
->set("export_order", $export)
;
}
protected function getExport($id)
{
$export = ExportQuery::create()->findPk($id);
if (null === $export) {
throw new \ErrorException(
$this->getTranslator()->trans(
"There is no id \"%id\" in the exports",
[
"%id" => $id
]
)
);
}
return $export;
}
protected function getCategory($id)
{
$category = ExportCategoryQuery::create()->findPk($id);
if (null === $category) {
throw new \ErrorException(
$this->getTranslator()->trans(
"There is no id \"%id\" in the export categories",
[
"%id" => $id
]
)
);
}
return $category;
}
}

View File

@@ -0,0 +1,519 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\ImportExport as ImportExportEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManager;
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManagerTrait;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterManager;
use Thelia\Core\FileFormat\Formatting\FormatterManagerTrait;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Loop\Import as ImportLoop;
use Thelia\Exception\FileNotFoundException;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Form\ImportForm;
use Thelia\ImportExport\Import\ImportHandler;
use Thelia\Model\ImportCategoryQuery;
use Thelia\Model\ImportQuery;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
/**
* Class ImportController
* @package Thelia\Controller\Admin
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ImportController extends BaseAdminController
{
use FormatterManagerTrait;
use ArchiveBuilderManagerTrait;
public function indexAction()
{
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::VIEW])) {
return $response;
}
$this->setOrders();
return $this->render('import');
}
/**
* @param integer $id
* @return Response
*
* This method is called when the route /admin/import/{id}
* is called with a POST request.
*/
public function import($id)
{
if (null === $import = $this->getImport($id)) {
return $this->render("404");
}
$archiveBuilderManager = $this->getArchiveBuilderManager($this->container);
$formatterManager = $this->getFormatterManager($this->container);
$handler = $import->getHandleClassInstance($this->container);
/**
* Get needed services
*/
$form = new ImportForm($this->getRequest());
$errorMessage = null;
$successMessage = null;
try {
$boundForm = $this->validateForm($form);
$lang = LangQuery::create()->findPk(
$boundForm->get("language")->getData()
);
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
$file = $boundForm->get("file_upload")->getData();
/**
* We have to check the extension manually because of composed file formats as tar.gz or tar.bz2
*/
$name = $file->getClientOriginalName();
$tools = $this->retrieveFormatTools(
$name,
$handler,
$formatterManager,
$archiveBuilderManager
);
/** @var AbstractArchiveBuilder $archiveBuilder */
$archiveBuilder = $tools["archive_builder"];
/** @var AbstractFormatter $formatter */
$formatter = $tools["formatter"];
if ($archiveBuilder !== null) {
/**
* If the file is an archive, load it and try to find the file.
*/
$archiveBuilder = $archiveBuilder->loadArchive($file->getPathname());
$contentAndFormat = $this->getFileContentInArchive(
$archiveBuilder,
$formatterManager,
$tools["types"]
);
$formatter = $contentAndFormat["formatter"];
$content = $contentAndFormat["content"];
} elseif ($formatter !== null) {
/**
* If the file isn't an archive
*/
$content = file_get_contents($file->getPathname());
} else {
throw new \ErrorException(
$this->getTranslator()->trans(
"There's a problem, the extension \"%ext\" has been found, ".
"but has no formatters nor archive builder",
[
"%ext" => $tools["extension"],
]
)
);
}
/**
* Process the import: dispatch events, format the file content and let the handler do it's job.
*/
$successMessage = $this->processImport(
$content,
$handler,
$formatter,
$archiveBuilder,
$lang
);
} catch (FormValidationException $e) {
$errorMessage = $this->createStandardFormValidationErrorMessage($e);
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
}
if ($successMessage !== null) {
$this->getParserContext()->set("success_message", $successMessage);
}
if ($errorMessage !== null) {
$form->setErrorMessage($errorMessage);
$this->getParserContext()
->addForm($form)
->setGeneralError($errorMessage)
;
}
return $this->importView($id);
}
public function getFileContentInArchive(
AbstractArchiveBuilder $archiveBuilder,
FormatterManager $formatterManager,
array $types
) {
$content = null;
/**
* Check expected file names for each formatter
*/
$fileNames = [];
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
foreach ($formatterManager->getFormattersByTypes($types) as $formatter) {
$fileName = $formatter::FILENAME . "." . $formatter->getExtension();
$fileNames[] = $fileName;
if ($archiveBuilder->hasFile($fileName)) {
$content = $archiveBuilder->getFileContent($fileName);
break;
}
}
if ($content === null) {
throw new FileNotFoundException(
$this->getTranslator()->trans(
"Your archive must contain one of these file and doesn't: %files",
[
"%files" => implode(", ", $fileNames),
]
)
);
}
return array(
"formatter" => $formatter,
"content" => $content,
);
}
public function retrieveFormatTools(
$fileName,
ImportHandler $handler,
FormatterManager $formatterManager,
ArchiveBuilderManager $archiveBuilderManager
) {
$nameLength = strlen($fileName);
$types = $handler->getHandledTypes();
$formats =
$formatterManager->getExtensionsByTypes($types, true) +
$archiveBuilderManager->getExtensions(true)
;
$uploadFormat = null;
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
$formatter = null;
/** @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder $archiveBuilder */
$archiveBuilder = null;
foreach ($formats as $objectName => $format) {
$formatLength = strlen($format);
$formatExtension = substr($fileName, -$formatLength);
if ($nameLength >= $formatLength && $formatExtension === $format) {
$uploadFormat = $format;
try {
$formatter = $formatterManager->get($objectName);
} catch (\OutOfBoundsException $e) {}
try {
$archiveBuilder = $archiveBuilderManager->get($objectName);
} catch (\OutOfBoundsException $e) {}
break;
}
}
$this->checkFileExtension($fileName, $uploadFormat);
return array(
"formatter" => $formatter,
"archive_builder" => $archiveBuilder,
"extension" => $uploadFormat,
"types" => $types,
);
}
public function checkFileExtension($fileName, $uploadFormat)
{
if ($uploadFormat === null) {
$splitName = explode(".", $fileName);
$ext = "";
if (1 < $limit = count($splitName)) {
$ext = "." . $splitName[$limit-1];
}
throw new FormValidationException(
$this->getTranslator()->trans(
"The extension \"%ext\" is not allowed",
[
"%ext" => $ext
]
)
);
}
}
public function processImport(
$content,
ImportHandler $handler,
AbstractFormatter $formatter = null,
AbstractArchiveBuilder $archiveBuilder = null,
Lang $lang = null
) {
$event = new ImportExportEvent($formatter, $handler, null, $archiveBuilder);
$event->setContent($content);
$this->dispatch(TheliaEvents::IMPORT_AFTER_DECODE, $event);
$data = $formatter
->decode($event->getContent())
->setLang($lang)
;
$event->setContent(null)->setData($data);
$this->dispatch(TheliaEvents::IMPORT_AFTER_DECODE, $event);
$errors = $handler->retrieveFromFormatterData($data);
if (!empty($errors)) {
throw new \Exception(
$this->getTranslator()->trans(
"Errors occurred while importing the file: %errors",
[
"%errors" => implode(", ", $errors),
]
)
);
}
return $this->getTranslator()->trans(
"Import successfully done, %numb row(s) have been changed",
[
"%numb" => $handler->getImportedRows(),
]
);
}
/**
* @param integer $id
* @return Response
*
* This method is called when the route /admin/import/{id}
* is called with a GET request.
*
* It returns a modal view if the request is an AJAX one,
* otherwise it generates a "normal" back-office page
*/
public function importView($id)
{
if (null === $import = $this->getImport($id)) {
return $this->render("404");
}
/**
* Use the loop to inject the same vars in Smarty
*/
$loop = new ImportLoop($this->container);
$loop->initializeArgs([
"id" => $id
]);
$query = $loop->buildModelCriteria();
$result= $query->find();
$results = $loop->parseResults(
new LoopResult($result)
);
$parserContext = $this->getParserContext();
/** @var \Thelia\Core\Template\Element\LoopResultRow $row */
foreach ($results as $row) {
foreach ($row->getVarVal() as $name=>$value) {
$parserContext->set($name, $value);
}
}
/**
* Get allowed formats
*/
/** @var \Thelia\ImportExport\AbstractHandler $handler */
$handler = $import->getHandleClassInstance($this->container);
$types = $handler->getHandledTypes();
$formatterManager = $this->getFormatterManager($this->container);
$archiveBuilderManager = $this->getArchiveBuilderManager($this->container);
$formats =
$formatterManager->getExtensionsByTypes($types, true) +
$archiveBuilderManager->getExtensions(true)
;
/**
* Get allowed mime types (used for the "Search a file" window
*/
$mimeTypes =
$formatterManager->getMimeTypesByTypes($types) +
$archiveBuilderManager->getMimeTypes()
;
/**
* Inject them in smarty
*/
$parserContext
->set("ALLOWED_MIME_TYPES", implode(",", $mimeTypes))
->set("ALLOWED_EXTENSIONS", implode(", ", $formats))
->set("CURRENT_LANG_ID", $this->getSession()->getLang()->getId())
;
/** Then render the form */
if ($this->getRequest()->isXmlHttpRequest()) {
return $this->render("ajax/import-modal");
} else {
return $this->render("import-page");
}
}
protected function setOrders($category = null, $import = null)
{
if ($category === null) {
$category = $this->getRequest()->query->get("category_order", "manual");
}
if ($import === null) {
$import = $this->getRequest()->query->get("import_order", "manual");
}
$this->getParserContext()
->set("category_order", $category)
;
$this->getParserContext()
->set("import_order", $import)
;
}
public function changePosition()
{
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::UPDATE])) {
return $response;
}
$query = $this->getRequest()->query;
$mode = $query->get("mode");
$id = $query->get("id");
$value = $query->get("value");
$this->getImport($id);
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
$this->dispatch(TheliaEvents::IMPORT_CHANGE_POSITION, $event);
}
public function changeCategoryPosition()
{
if (null !== $response = $this->checkAuth([AdminResources::IMPORT], [], [AccessManager::UPDATE])) {
return $response;
}
$query = $this->getRequest()->query;
$mode = $query->get("mode");
$id = $query->get("id");
$value = $query->get("value");
$this->getCategory($id);
$event = new UpdatePositionEvent($id, $this->getMode($mode), $value);
$this->dispatch(TheliaEvents::IMPORT_CATEGORY_CHANGE_POSITION, $event);
$this->setOrders("manual");
return $this->render('import');
}
public function getMode($action)
{
if ($action === "up") {
$mode = UpdatePositionEvent::POSITION_UP;
} elseif ($action === "down") {
$mode = UpdatePositionEvent::POSITION_DOWN;
} else {
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
}
return $mode;
}
protected function getImport($id)
{
$import = ImportQuery::create()->findPk($id);
if (null === $import) {
throw new \ErrorException(
$this->getTranslator()->trans(
"There is no id \"%id\" in the imports",
[
"%id" => $id
]
)
);
}
return $import;
}
protected function getCategory($id)
{
$category = ImportCategoryQuery::create()->findPk($id);
if (null === $category) {
throw new \ErrorException(
$this->getTranslator()->trans(
"There is no id \"%id\" in the import categories",
[
"%id" => $id
]
)
);
}
return $category;
}
}

View File

@@ -17,7 +17,9 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Scope;
use Thelia\Core\DependencyInjection\Compiler\RegisterArchiveBuilderPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterCouponPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterFormatterPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
@@ -57,6 +59,8 @@ class TheliaBundle extends Bundle
->addCompilerPass(new RegisterRouterPass())
->addCompilerPass(new RegisterCouponPass())
->addCompilerPass(new RegisterCouponConditionPass())
->addCompilerPass(new RegisterArchiveBuilderPass())
->addCompilerPass(new RegisterFormatterPass())
;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Class RegisterArchiveBuilderPass
* @package Thelia\Core\DependencyInjection\Compiler
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class RegisterArchiveBuilderPass implements CompilerPassInterface
{
const MANAGER_DEFINITION = "thelia.manager.archive_builder_manager";
const SERVICE_TAG = "thelia.archive_builder";
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container Container
*
* @api
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(static::MANAGER_DEFINITION)) {
return;
}
$manager = $container->getDefinition(static::MANAGER_DEFINITION);
$services = $container->findTaggedServiceIds(static::SERVICE_TAG);
foreach ($services as $id => $condition) {
$manager->addMethodCall(
'add',
array(
new Reference($id)
)
);
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Class RegisterFormatterPass
* @package Thelia\Core\DependencyInjection\Compiler
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class RegisterFormatterPass implements CompilerPassInterface
{
const MANAGER_DEFINITION = "thelia.manager.formatter_manager";
const SERVICE_TAG = "thelia.formatter";
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container Container
*
* @api
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition(static::MANAGER_DEFINITION)) {
return;
}
$manager = $container->getDefinition(static::MANAGER_DEFINITION);
$services = $container->findTaggedServiceIds(static::SERVICE_TAG);
foreach ($services as $id => $condition) {
$manager->addMethodCall(
'add',
array(
new Reference($id)
)
);
}
}
}

View File

@@ -12,6 +12,7 @@
namespace Thelia\Core\DependencyInjection\Loader;
use Propel\Runtime\Propel;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
@@ -24,6 +25,18 @@ use Symfony\Component\DependencyInjection\SimpleXMLElement;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Loader\FileLoader;
use Thelia\Model\Export;
use Thelia\Model\ExportCategory;
use Thelia\Model\ExportCategoryQuery;
use Thelia\Model\ExportQuery;
use Thelia\Model\Import;
use Thelia\Model\ImportCategory;
use Thelia\Model\ImportCategoryQuery;
use Thelia\Model\ImportQuery;
use Thelia\Model\Map\ExportCategoryTableMap;
use Thelia\Model\Map\ExportTableMap;
use Thelia\Model\Map\ImportCategoryTableMap;
use Thelia\Model\Map\ImportTableMap;
/**
*
@@ -35,6 +48,7 @@ use Symfony\Component\DependencyInjection\Loader\FileLoader;
*/
class XmlFileLoader extends FileLoader
{
/**
* Loads an XML file.
*
@@ -63,6 +77,44 @@ class XmlFileLoader extends FileLoader
$this->parseForms($xml);
$this->parseDefinitions($xml, $path);
$this->propelOnlyRun(
[$this, "parseExportCategories"],
$xml,
ExportCategoryTableMap::DATABASE_NAME
);
$this->propelOnlyRun(
[$this, "parseExports"],
$xml,
ExportTableMap::DATABASE_NAME
);
$this->propelOnlyRun(
[$this, "parseExportCategories"],
$xml,
ImportCategoryTableMap::DATABASE_NAME
);
$this->propelOnlyRun(
[$this, "parseExports"],
$xml,
ImportTableMap::DATABASE_NAME
);
}
public function propelOnlyRun(callable $method, $arg, $name)
{
$doRun = false;
try {
Propel::getConnection($name);
$doRun = true;
} catch (\ErrorException $e) {}
if ($doRun) {
call_user_func($method, $arg);
}
}
protected function parseCommands(SimpleXMLElement $xml)
@@ -276,6 +328,259 @@ class XmlFileLoader extends FileLoader
$this->container->setDefinition($id, $definition);
}
protected function parseExportCategories(SimpleXMLElement $xml)
{
if (false === $exportCategories = $xml->xpath('//config:export_categories/config:export_category')) {
return;
}
$con = Propel::getWriteConnection(ExportCategoryTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
/** @var SimpleXMLElement $exportCategory */
foreach ($exportCategories as $exportCategory) {
$id = (string) $exportCategory->getAttributeAsPhp("id");
$exportCategoryModel = ExportCategoryQuery::create()->findOneByRef($id);
if ($exportCategoryModel === null) {
$exportCategoryModel = new ExportCategory();
$exportCategoryModel
->setRef($id)
->save($con)
;
}
/** @var SimpleXMLElement $child */
foreach ($exportCategory->children() as $child) {
$locale = (string) $child->getAttributeAsPhp("locale");
$value = (string) $child;
$exportCategoryModel
->setLocale($locale)
->setTitle($value)
->save($con);
;
}
}
$con->commit();
} catch (\Exception $e) {
$con->rollBack();
throw $e;
}
}
protected function parseExports(SimpleXMLElement $xml)
{
if (false === $exports = $xml->xpath('//config:exports/config:export')) {
return;
}
$con = Propel::getWriteConnection(ExportTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
/** @var SimpleXMLElement $export */
foreach ($exports as $export) {
$id = (string) $export->getAttributeAsPhp("id");
$class = (string) $export->getAttributeAsPhp("class");
$categoryRef = (string) $export->getAttributeAsPhp("category_id");
if (!class_exists($class)) {
throw new \ErrorException(
"The class \"$class\" doesn't exist"
);
}
$category = ExportCategoryQuery::create()->findOneByRef($categoryRef);
if (null === $category) {
throw new \ErrorException(
"The export category \"$categoryRef\" doesn't exist"
);
}
$exportModel = ExportQuery::create()->findOneByRef($id);
if (null === $exportModel) {
$exportModel = new Export();
$exportModel
->setRef($id)
;
}
$exportModel
->setExportCategory($category)
->setHandleClass($class)
->save($con)
;
/** @var SimpleXMLElement $descriptive */
foreach ($export->children() as $descriptive) {
$locale = $descriptive->getAttributeAsPhp("locale");
$title = null;
$description = null;
/** @var SimpleXMLElement $row */
foreach ($descriptive->children() as $row) {
switch ($row->getName()) {
case "title":
$title = (string) $row;
break;
case "description":
$description = (string) $row;
break;
}
}
$exportModel
->setLocale($locale)
->setTitle($title)
->setDescription($description)
->save($con)
;
}
}
$con->commit();
} catch (\Exception $e) {
$con->rollBack();
throw $e;
}
}
protected function parseImportCategories(SimpleXMLElement $xml)
{
if (false === $importCategories = $xml->xpath('//config:import_categories/config:import_category')) {
return;
}
$con = Propel::getWriteConnection(ImportCategoryTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
/** @var SimpleXMLElement $importCategory */
foreach ($importCategories as $importCategory) {
$id = (string) $importCategory->getAttributeAsPhp("id");
$importCategoryModel = ImportCategoryQuery::create()->findOneByRef($id);
if ($importCategoryModel === null) {
$importCategoryModel = new ImportCategory();
$importCategoryModel
->setRef($id)
->save($con)
;
}
/** @var SimpleXMLElement $child */
foreach ($importCategory->children() as $child) {
$locale = (string) $child->getAttributeAsPhp("locale");
$value = (string) $child;
$importCategoryModel
->setLocale($locale)
->setTitle($value)
->save($con);
;
}
}
$con->commit();
} catch (\Exception $e) {
$con->rollBack();
throw $e;
}
}
protected function parseImports(SimpleXMLElement $xml)
{
if (false === $imports = $xml->xpath('//config:imports/config:import')) {
return;
}
$con = Propel::getWriteConnection(ImportTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
/** @var SimpleXMLElement $import */
foreach ($imports as $import) {
$id = (string) $import->getAttributeAsPhp("id");
$class = (string) $import->getAttributeAsPhp("class");
$categoryRef = (string) $import->getAttributeAsPhp("category_id");
if (!class_exists($class)) {
throw new \ErrorException(
"The class \"$class\" doesn't exist"
);
}
$category = ImportCategoryQuery::create()->findOneByRef($categoryRef);
if (null === $category) {
throw new \ErrorException(
"The import category \"$categoryRef\" doesn't exist"
);
}
$importModel = ImportQuery::create()->findOneByRef($id);
if (null === $importModel) {
$importModel = new Import();
$importModel
->setRef($id)
;
}
$importModel
->setImportCategory($category)
->setHandleClass($class)
->save($con)
;
/** @var SimpleXMLElement $descriptive */
foreach ($import->children() as $descriptive) {
$locale = $descriptive->getAttributeAsPhp("locale");
$title = null;
$description = null;
/** @var SimpleXMLElement $row */
foreach ($descriptive->children() as $row) {
switch ($row->getName()) {
case "title":
$title = (string) $row;
break;
case "description":
$description = (string) $row;
break;
}
}
$importModel
->setLocale($locale)
->setTitle($title)
->setDescription($description)
->save($con)
;
}
}
$con->commit();
} catch (\Exception $e) {
$con->rollBack();
throw $e;
}
}
/**
* Parses a XML file.
*

View File

@@ -17,6 +17,10 @@
<xsd:element name="commands" type="commands"/>
<xsd:element name="forms" type="forms" />
<xsd:element name="routing" type="routing" />
<xsd:element name="export_categories" type="export_categories" />
<xsd:element name="exports" type="exports" />
<xsd:element name="import_categories" type="import_categories" />
<xsd:element name="imports" type="imports" />
</xsd:choice>
</xsd:complexType>
@@ -212,4 +216,98 @@
<xsd:attribute name="function" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="export_categories">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="export_category" type="export_category"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="export_category">
<xsd:choice maxOccurs="unbounded" minOccurs="1">
<xsd:element name="title" type="export_category_title" />
</xsd:choice>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="export_category_title">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="locale" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="exports">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="export" type="export"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="export">
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="export_descriptive" type="export_descriptive" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:string" use="required"/>
<xsd:attribute name="class" type="xsd:string" use="required"/>
<xsd:attribute name="category_id" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="export_descriptive">
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="title" type="xsd:string" />
<xsd:element minOccurs="0" maxOccurs="1" name="description" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="locale" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="import_categories">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="import_category" type="import_category"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="import_category">
<xsd:choice maxOccurs="unbounded" minOccurs="1">
<xsd:element name="title" type="import_category_title" />
</xsd:choice>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="import_category_title">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="locale" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="imports">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="import" type="import"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="import">
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="import_descriptive" type="import_descriptive" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:string" use="required"/>
<xsd:attribute name="class" type="xsd:string" use="required"/>
<xsd:attribute name="category_id" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="import_descriptive">
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="title" type="xsd:string" />
<xsd:element minOccurs="0" maxOccurs="1" name="description" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="locale" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,153 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\ImportExport\AbstractHandler;
use Thelia\ImportExport\Export\ExportHandler;
/**
* Class Export
* @package Thelia\Core\Event\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ImportExport extends ActionEvent
{
/** @var \Thelia\ImportExport\AbstractHandler */
protected $handler;
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter */
protected $formatter;
/** @var FormatterData */
protected $data;
/** @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder */
protected $archiveBuilder;
/** @var mixed */
protected $content;
public function __construct(
AbstractFormatter $formatter = null,
AbstractHandler $handler = null,
FormatterData $data = null,
AbstractArchiveBuilder $archiveBuilder = null
) {
$this->archiveBuilder = $archiveBuilder;
$this->formatter = $formatter;
$this->handler = $handler;
$this->data = $data;
}
/**
* @param AbstractArchiveBuilder $archiveBuilder
* @return $this
*/
public function setArchiveBuilder(AbstractArchiveBuilder $archiveBuilder)
{
$this->archiveBuilder = $archiveBuilder;
return $this;
}
/**
* @return \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder
*/
public function getArchiveBuilder()
{
return $this->archiveBuilder;
}
/**
* @param AbstractFormatter $formatter
* @return $this
*/
public function setFormatter(AbstractFormatter $formatter)
{
$this->formatter = $formatter;
return $this;
}
/**
* @return \Thelia\Core\FileFormat\Formatting\AbstractFormatter
*/
public function getFormatter()
{
return $this->formatter;
}
/**
* @param \Thelia\ImportExport\Export\ExportHandler $handler
* @return $this
*/
public function setHandler(ExportHandler $handler)
{
$this->handler = $handler;
return $this;
}
/**
* @return \Thelia\ImportExport\Export\ExportHandler
*/
public function getHandler()
{
return $this->handler;
}
/**
* @param FormatterData $data
* @return $this
*/
public function setData(FormatterData $data)
{
$this->data = $data;
return $this;
}
/**
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
*/
public function getData()
{
return $this->data;
}
/**
* @param $content
* @return $this
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* @return mixed
*/
public function getContent()
{
return $this->content;
}
public function isArchive()
{
return $this->archiveBuilder !== null;
}
}

View File

@@ -766,4 +766,18 @@ final class TheliaEvents
const BEFORE_UPDATEBRAND = "action.before_updateBrand";
const AFTER_UPDATEBRAND = "action.after_updateBrand";
// -- Export ----------------------------------------------
const EXPORT_BEFORE_ENCODE = "Thelia.export.encode.before";
const EXPORT_AFTER_ENCODE = "Thelia.export.encode.after";
const EXPORT_CATEGORY_CHANGE_POSITION = "Thelia.export.change_category_position";
const EXPORT_CHANGE_POSITION = "Thelia.export.change_position";
const IMPORT_BEFORE_DECODE = "Thelia.import.decode.before";
const IMPORT_AFTER_DECODE = "Thelia.import.decode.after";
const IMPORT_CATEGORY_CHANGE_POSITION = "Thelia.import.change_category_position";
const IMPORT_CHANGE_POSITION = "Thelia.import.change_position";
}

View File

@@ -0,0 +1,214 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive;
use Thelia\Core\FileFormat\FormatInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\FileNotFoundException;
use Thelia\Exception\FileNotReadableException;
use Thelia\Log\Tlog;
use Thelia\Tools\FileDownload\FileDownloaderAwareTrait;
/**
* Class AbstractArchiveBuilder
* @package Thelia\Core\FileFormat\Archive
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class AbstractArchiveBuilder implements FormatInterface, ArchiveBuilderInterface
{
use FileDownloaderAwareTrait;
const TEMP_DIRECTORY_NAME = "archive_builder";
/** @var string */
protected $cacheFile;
/** @var \Thelia\Core\Translation\Translator */
protected $translator;
/** @var \Thelia\Log\Tlog */
protected $logger;
/** @var string */
protected $cacheDir;
/** @var string */
protected $environment;
public function __construct()
{
$this->translator = Translator::getInstance();
$this->logger = Tlog::getNewInstance();
}
public function getArchiveBuilderCacheDirectory($environment)
{
$theliaCacheDir = THELIA_CACHE_DIR . $environment . DS;
if (!is_writable($theliaCacheDir)) {
throw new \ErrorException(
$this->translator->trans(
"The cache directory \"%env\" is not writable",
[
"%env" => $environment
]
)
);
}
$archiveBuilderCacheDir = $this->cacheDir = $theliaCacheDir . static::TEMP_DIRECTORY_NAME;
if (!is_dir($archiveBuilderCacheDir) && !mkdir($archiveBuilderCacheDir, 0755)) {
throw new \ErrorException(
$this->translator->trans(
"Error while creating the directory \"%directory\"",
[
"%directory" => static::TEMP_DIRECTORY_NAME
]
)
);
}
return $archiveBuilderCacheDir;
}
/**
* @param $pathToFile
* @param $destination
* @param $isOnline
* @return $this
* @throws \ErrorException
*/
public function copyFile($pathToFile, $destination, $isOnline)
{
if ($isOnline) {
/**
* It's an online file
*/
$this->getFileDownloader()
->download($pathToFile, $destination)
;
} else {
/**
* It's a local file
*/
if (!is_file($pathToFile)) {
$this->throwFileNotFound($pathToFile);
} elseif (!is_readable($pathToFile)) {
throw new FileNotReadableException(
$this->translator
->trans(
"The file %file is not readable",
[
"%file" => $pathToFile,
]
)
);
}
if (!copy($pathToFile, $destination)) {
$translatedErrorMessage = $this->translator->trans(
"An error happend while copying %prev to %dest",
[
"%prev" => $pathToFile,
"%dest" => $destination,
]
);
$this->logger
->error($translatedErrorMessage)
;
throw new \ErrorException($translatedErrorMessage);
}
}
return $this;
}
/**
* @return string
*/
public function generateCacheFile($environment)
{
$cacheFileName = md5(uniqid());
$cacheFile = $this->getArchiveBuilderCacheDirectory($environment) . DS;
$cacheFile .= $cacheFileName . "." . $this->getExtension();
return $cacheFile;
}
public function throwFileNotFound($file)
{
throw new FileNotFoundException(
$this->translator
->trans(
"The file %file is missing or is not readable",
[
"%file" => $file,
]
)
);
}
/**
* @param $path
* @return $this
*/
public function setCacheFile($path)
{
$this->cacheFile = $path;
return $this;
}
public function getCacheDir()
{
return $this->cacheDir;
}
/**
* @return Tlog
*/
public function getLogger()
{
return $this->logger;
}
/**
* @return Translator
*/
public function getTranslator()
{
return $this->translator;
}
public function getCacheFile()
{
return $this->cacheFile;
}
/**
* @param string $environment
* @return $this
*
* Sets the execution environment of the Kernel,
* used to know which cache is used.
*/
public function setEnvironment($environment)
{
$this->environment = $environment;
}
}

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception;
/**
* Class TarArchiveException
* @package Thelia\Core\FileFormat\Archive\ArchiveBuilder
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class TarArchiveException extends \Exception
{
}

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception;
/**
* Class ZipArchiveException
* @package Thelia\Core\FileFormat\Archive\ArchiveBuilder
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ZipArchiveException extends \ErrorException
{
}

View File

@@ -0,0 +1,506 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\TarArchiveException;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Thelia;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\FileNotReadableException;
use Thelia\Log\Tlog;
use Thelia\Tools\FileDownload\FileDownloaderInterface;
/**
* Class TarArchiveBuilder
* @package Thelia\Core\FileFormat\Archive\ArchiveBuilder
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class TarArchiveBuilder extends AbstractArchiveBuilder
{
const PHAR_FORMAT = \Phar::TAR;
/** @var string */
protected $environment;
/** @var null|string */
protected $compression;
/** @var string */
protected $tarCacheFile;
/** @var \PharData */
protected $tar;
/** @var \Thelia\Core\Translation\Translator */
protected $translator;
/** @var \Thelia\Log\Tlog */
protected $logger;
public function __destruct()
{
if ($this->tar instanceof \PharData) {
if (file_exists($this->cacheFile)) {
unlink($this->cacheFile);
}
}
}
/**
* @param string $filePath It is the path to access the file.
* @param string $directoryInArchive This is the directory where it will be stored in the archive
* @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name
* @param bool $isOnline
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This methods adds a file in the archive.
* If the file is local, $isOnline must be false,
* If the file online, $filePath must be an URL.
*/
public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false)
{
if (!empty($name)) {
$dirName = dirname($name);
if ($dirName == ".") {
$dirName = "";
}
$directoryInArchive .= DS . $dirName;
}
if (empty($name) || !is_scalar($name)) {
$name = basename($filePath);
} else {
$name = basename($name);
}
/**
* Download the file if it is online
* If it's local check if the file exists and if it is redable
*/
$fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp";
$this->copyFile($filePath, $fileDownloadCache, $isOnline);
/**
* Then write the file in the archive
*/
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
if (!empty($directoryInArchive)) {
$name = $this->formatFilePath(
$directoryInArchive . $name
);
}
$this->tar->addFile($filePath, $name);
/**
* And clear the download temp file
*/
unlink($fileDownloadCache);
return $this;
}
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
* This method creates a file in the archive with its content
*/
public function addFileFromString($content, $name, $directoryInArchive = "/")
{
if (empty($name) || !is_scalar($name)) {
throw new \ErrorException(
$this->translator->trans(
"The file name must be valid"
)
);
}
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
if (!empty($directoryInArchive)) {
$name = $this->formatFilePath(
$directoryInArchive . $name
);
}
try {
$this->tar->addFromString($name, $content);
} catch (\Exception $e) {
throw new \ErrorException(
$this->translator->trans(
"Error while writing the file into the archive, error message: %errmes",
[
"%errmes" => $e->getMessage()
]
)
);
}
}
/**
* @param $directoryPath
* @return $this
* @throws \ErrorException
*
* This method creates an empty directory
*/
public function addDirectory($directoryPath)
{
$directoryInArchive = $this->formatDirectoryPath($directoryPath);
if (!empty($directoryInArchive)) {
try {
$this->tar->addEmptyDir($directoryInArchive);
} catch (\Exception $e) {
throw new \ErrorException(
$this->translator->trans(
"The directory %dir has not been created in the archive",
[
"%dir" => $directoryInArchive
]
)
);
}
}
return $this;
}
/**
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This method returns a file content
*/
public function getFileContent($pathToFile)
{
$pathToFile = $this->formatFilePath($pathToFile);
if (!$this->hasFile($pathToFile)) {
$this->throwFileNotFound($pathToFile);
}
/** @var \PharFileInfo $fileInfo*/
$fileInfo = $this->tar[$pathToFile];
/** @var \SplFileObject $file */
$file = $fileInfo->openFile();
$content = "";
while (false !== ($char = $file->fgetc())) {
$content .= $char;
}
return $content;
}
/**
* @param $pathInArchive
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
*
* This method deletes a file in the archive
*/
public function deleteFile($pathInArchive)
{
if (!$this->hasFile($pathInArchive)) {
$this->throwFileNotFound($pathInArchive);
}
if (false === $this->tar->delete($pathInArchive)) {
throw new \ErrorException(
$this->translator->trans(
"Unknown error while deleting the file %file",
[
"%file" => $pathInArchive
]
)
);
}
}
/**
* @return \Thelia\Core\HttpFoundation\Response
*
* This method return an instance of a Response with the archive as content.
*/
public function buildArchiveResponse($filename)
{
if (!is_file($this->cacheFile)) {
$this->throwFileNotFound($this->cacheFile);
}
if (!is_readable($this->cacheFile)) {
throw new FileNotReadableException(
$this->translator->trans(
"The file %file is not readable",
[
"%file" => $this->cacheFile
]
)
);
}
$content = file_get_contents($this->cacheFile);
return new Response(
$content,
200,
[
"Content-Type" => $this->getMimeType(),
"Content-Disposition" => "attachment; filename=\"".$filename . "." . $this->getExtension() ."\"",
]
);
}
/**
* @param string $pathToArchive
* @param string $environment
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException
* @throws TarArchiveException
*
* Loads an archive
*/
public function loadArchive($pathToArchive, $isOnline = false)
{
$tar = clone $this;
$tar
->setCacheFile($tar->generateCacheFile($this->environment))
->copyFile($pathToArchive, $tar->getCacheFile(), $isOnline);
/**
* This throws TarArchiveBuilderException if
* the archive is not valid.
*/
return $tar->setEnvironment($tar->environment);
}
/**
* @param $pathToFile
* @return bool
*
* Checks if the archive has a file.
* In \PharData, if you call it as a array,
* the keys are the files in the archive.
*/
public function hasFile($pathToFile)
{
$isFile = false;
$pathToFile = $this->formatFilePath($pathToFile);
try {
/** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToFile];
if ($fileInfo->isFile()) {
$isFile = true;
}
/**
* Catch the exception to avoid its displaying.
*/
} catch (\BadMethodCallException $e) {}
return $isFile;
}
/**
* @param string $directory
* @return bool
*
* Check if the archive has a directory
*/
public function hasDirectory($directory)
{
$isDir = false;
$pathToDir = $this->formatDirectoryPath($directory);
try {
/** @var \PharFileInfo $fileInfo */
$fileInfo = $this->tar[$pathToDir];
if ($fileInfo->isDir()) {
$isDir = true;
}
/**
* Catch the exception to avoid its displaying.
*/
} catch (\BadMethodCallException $e) {}
return $isDir;
}
/**
* @param string $environment
* @return $this
*
* Sets the execution environment of the Kernel,
* used to know which cache is used.
*/
public function setEnvironment($environment)
{
if (empty($environment)) {
throw new \ErrorException(
$this->translator->trans(
"You must define an environment when you use an archive builder"
)
);
}
if ($this->cacheFile === null) {
$cacheFile = $this->generateCacheFile($environment);
if (file_exists($cacheFile)) {
unlink($cacheFile);
}
} else {
$cacheFile = $this->cacheFile;
}
$errorMessage = null;
try {
$this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT);
$this->compressionEntryPoint();
} catch (\BadMethodCallException $e) {
/**
* This should not happen
*/
$errorMessage = "You have badly called the method setEnvironment twice for %file";
} catch (\UnexpectedValueException $e) {
$errorMessage = "The file %file is corrupted";
}
if ($errorMessage !== null) {
throw new TarArchiveException(
$this->translator->trans(
$errorMessage,
[
"%file" => $cacheFile
]
)
);
}
$this->cacheFile = $cacheFile;
$this->environment = $environment;
return $this;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
*/
public function formatFilePath($initialString)
{
/**
* Remove the / at the beginning and the end.
*/
$initialString = trim($initialString, "/");
/**
* Remove the double, triple, ... slashes
*/
$initialString = preg_replace("#\/{2,}#", "/", $initialString);
return $initialString;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
*/
public function formatDirectoryPath($initialString)
{
$initialString = $this->formatFilePath($initialString);
return $initialString . "/";
}
/**
* @return string
*
* This method must return a string, the name of the format.
*
* example:
* return "XML";
*/
public function getName()
{
return "tar";
}
/**
* @return string
*
* This method must return a string, the extension of the file format, without the ".".
* The string should be lowercase.
*
* example:
* return "xml";
*/
public function getExtension()
{
return "tar";
}
/**
* @return string
*
* This method must return a string, the mime type of the file format.
*
* example:
* return "application/json";
*/
public function getMimeType()
{
return "application/x-tar";
}
protected function compressionEntryPoint()
{
/**
* This method must be overwritten if you want to do some
* stuff to compress you archive
*/
}
public function getCompression()
{
return $this->compression;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
/**
* Class TarBz2ArchiveBuilder
* @package Thelia\Core\FileFormat\Archive\ArchiveBuilder
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class TarBz2ArchiveBuilder extends TarArchiveBuilder
{
public function getName()
{
return "tar.bz2";
}
public function getMimeType()
{
return "application/x-bzip2";
}
public function getExtension()
{
return "tbz2";
}
protected function compressionEntryPoint()
{
if ($this->compression != \Phar::BZ2) {
$this->tar = $this->tar->compress(\Phar::BZ2, $this->getExtension());
}
$this->compression = \Phar::BZ2;
return $this;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
/**
* Class TarGzArchiveBuilder
* @package Thelia\Core\FileFormat\Archive\ArchiveBuilder
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class TarGzArchiveBuilder extends TarArchiveBuilder
{
public function getName()
{
return "tar.gz";
}
public function getMimeType()
{
return "application/x-gzip";
}
public function getExtension()
{
return "tgz";
}
protected function compressionEntryPoint()
{
if ($this->compression != \Phar::GZ) {
$this->tar = $this->tar->compress(\Phar::GZ, $this->getExtension());
}
$this->compression = \Phar::GZ;
return $this;
}
}

View File

@@ -0,0 +1,613 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive\ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\Exception\ZipArchiveException;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Thelia;
use Thelia\Exception\FileNotReadableException;
use Thelia\Tools\FileDownload\FileDownloaderInterface;
/**
* Class ZipArchiveBuilder
* @package Thelia\Core\FileFormat\Archive\ArchiveBuilder
* @author Benjamin Perche <bperche@openstudio.fr>
*
* This class is a driver defined by AbstractArchiveBuilder,
* it's goal is to manage Zip archives.
*
* You can create a new archive by creating a new instance,
* or load an existing zip with the static method loadArchive.
*/
class ZipArchiveBuilder extends AbstractArchiveBuilder
{
/**
* @var \ZipArchive
*/
protected $zip;
public function __construct()
{
parent::__construct();
$this->zip = new \ZipArchive();
}
/**
* On the destruction of the class,
* remove the temporary file.
*/
public function __destruct()
{
if ($this->zip instanceof \ZipArchive) {
@$this->zip->close();
if (file_exists($this->cacheFile)) {
unlink($this->cacheFile);
}
}
}
/**
* @param string $filePath It is the path to access the file.
* @param string $directoryInArchive This is the directory where it will be stored in the archive
* @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name
* @param bool $isOnline
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This methods adds a file in the archive.
* If the file is local, $isOnline must be false,
* If the file online, $filePath must be an URL.
*/
public function addFile($filePath, $directoryInArchive = null, $name = null, $isOnline = false)
{
if (!empty($name)) {
$directoryInArchive .= DS . dirname($name) ;
}
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
/**
* Add empty directory if it doesn't exist
*/
if (!empty($directoryInArchive)) {
$this->addDirectory($directoryInArchive);
}
if (empty($name) || !is_scalar($name)) {
$name = basename($filePath);
} else {
$name = basename($name);
}
/**
* Download the file if it is online
* If it's local check if the file exists and if it is redable
*/
$fileDownloadCache = $this->cacheDir . DS . md5(uniqid()) . ".tmp";
$this->copyFile($filePath, $fileDownloadCache, $isOnline);
/**
* Then write the file in the archive and commit the changes
*/
$destination = $directoryInArchive . $name;
if (!$this->zip->addFile($fileDownloadCache, $destination)) {
$translatedErrorMessage = $this->translator->trans(
"An error occurred while adding this file to the archive: %file",
[
"%file" => $fileDownloadCache
]
);
$this->logger->error($translatedErrorMessage);
// if error delete the cache file
unlink($fileDownloadCache);
throw new \ErrorException($translatedErrorMessage);
}
$this->commit();
// Delete the temp file
unlink($fileDownloadCache);
return $this;
}
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
* This method creates a file in the archive with its content
*/
public function addFileFromString($content, $name, $directoryInArchive = "/")
{
$directoryInArchive = $this->formatDirectoryPath($directoryInArchive);
if (!empty($directoryInArchive) && $directoryInArchive !== "/") {
$this->addDirectory($directoryInArchive);
}
if (empty($name) || !is_scalar($name)) {
throw new \ErrorException(
$this->translator->trans(
"The filename is not correct"
)
);
}
$filePath = $this->getFilePath($directoryInArchive . DS . $name);
if (!$this->zip->addFromString($filePath, $content)) {
throw new \ErrorException(
$this->translator->trans(
"Unable to write the file %file into the archive",
[
"%file" => $filePath,
]
)
);
}
$this->commit();
}
/**
* @param $directoryPath
* @return $this
* @throws \ErrorException
*
* This method creates an empty directory
*/
public function addDirectory($directoryPath)
{
$directoryInArchive = $this->formatDirectoryPath($directoryPath);
if (!empty($directoryInArchive)) {
$this->zip->addEmptyDir($directoryInArchive);
$this->commit();
if (!$this->hasDirectory($directoryInArchive)) {
throw new \ErrorException(
$this->translator->trans(
"The directory %dir has not been created in the archive",
[
"%dir" => $directoryInArchive
]
)
);
}
}
return $this;
}
/**
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This method returns a file content
*/
public function getFileContent($pathToFile)
{
$pathToFile = $this->formatFilePath($pathToFile);
if (!$this->hasFile($pathToFile)) {
$this->throwFileNotFound($pathToFile);
}
$stream = $this->zip->getStream($pathToFile);
$content = "";
while (!feof($stream)) {
$content .= fread($stream, 2);
}
fclose($stream);
return $content;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
*/
public function getFilePath($initialString)
{
/**
* Remove the / at the beginning and the end.
*/
$initialString = trim($initialString, "/");
/**
* Remove the double, triple, ... slashes
*/
$initialString = preg_replace("#\/{2,}#", "/", $initialString);
if (preg_match("#\/?[^\/]+\/[^\/]+\/?#", $initialString)) {
$initialString = "/" . $initialString;
}
return $initialString;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
*/
public function getDirectoryPath($initialString)
{
$initialString = $this->getFilePath($initialString);
if ($initialString[0] !== "/") {
$initialString = "/" . $initialString;
}
return $initialString . "/";
}
/**
* @param $pathInArchive
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
*
* This method deletes a file in the archive
*/
public function deleteFile($pathInArchive)
{
$pathInArchive = $this->formatFilePath($pathInArchive);
if (!$this->hasFile($pathInArchive)) {
$this->throwFileNotFound($pathInArchive);
}
$deleted = $this->zip->deleteName($pathInArchive);
if (!$deleted) {
throw new \ErrorException(
$this->translator->trans(
"The file %file has not been deleted",
[
"%file" => $pathInArchive,
]
)
);
}
return $this;
}
/**
* @return \Thelia\Core\HttpFoundation\Response
*
* This method return an instance of a Response with the archive as content.
*/
public function buildArchiveResponse($filename)
{
$this->zip->comment = "Generated by Thelia v" . Thelia::THELIA_VERSION;
$this->commit();
if (!file_exists($this->cacheFile)) {
$this->throwFileNotFound($this->cacheFile);
}
if (!is_readable($this->cacheFile)) {
throw new FileNotReadableException(
$this->translator->trans(
"The cache file %file is not readable",
[
"%file" => $this->cacheFile
]
)
);
}
$content = file_get_contents($this->cacheFile);
$this->zip->close();
return new Response(
$content,
200,
[
"Content-Type" => $this->getMimeType(),
"Content-Disposition" => "attachment; filename=\"". $filename . "." . $this->getExtension() ."\"",
]
);
}
/**
* @param string $pathToArchive
* @param bool $isOnline
* @param FileDownloaderInterface $fileDownloader
* @return ZipArchiveBuilder
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException
*
* Loads an archive
*/
public function loadArchive($pathToArchive, $isOnline = false)
{
$back = $this->zip;
$this->zip = new \ZipArchive();
$zip = clone $this;
$this->zip = $back;
$zip->setEnvironment($this->environment);
$zip->copyFile(
$pathToArchive,
$zip->getCacheFile(),
$isOnline
);
if (true !== $return = $zip->getRawZipArchive()->open($zip->getCacheFile())) {
throw new ZipArchiveException(
$zip->getZipErrorMessage($return)
);
}
return $zip;
}
/**
* @param $pathToFile
* @return bool
*
* Checks if the archive has a file
*/
public function hasFile($pathToFile)
{
return $this->zip
->locateName($this->formatFilePath($pathToFile)) !== false
;
}
/**
* @param string $directory
* @return bool
*
* Checks if the link $directory exists and if it's not a file.
*/
public function hasDirectory($directory)
{
$link = $this->zip->locateName($this->formatDirectoryPath($directory));
return $link !== false;
}
/**
* @param string $environment
* @return $this
*
* Sets the execution environment of the Kernel,
* used to know which cache is used.
*/
public function setEnvironment($environment)
{
parent::setEnvironment($environment);
$cacheFile = $this->generateCacheFile($environment);
if (file_exists($cacheFile)) {
unlink($cacheFile);
}
$opening = $this->zip->open(
$cacheFile,
\ZipArchive::CREATE
);
if ($opening !== true) {
throw new \ErrorException(
$this->translator->trans(
"An unknown error append"
)
);
}
$this->cacheFile = $cacheFile;
return $this;
}
/**
* @param $errorCode
* @return string
*
* Give the error message of a \ZipArchive error code
*/
public function getZipErrorMessage($errorCode)
{
switch ($errorCode) {
case \ZipArchive::ER_EXISTS:
$message = "The archive already exists";
break;
case \ZipArchive::ER_INCONS:
$message = "The archive is inconsistent";
break;
case \ZipArchive::ER_INVAL:
$message = "Invalid argument";
break;
case \ZipArchive::ER_MEMORY:
$message = "Memory error";
break;
case \ZipArchive::ER_NOENT:
$message = "The file doesn't exist";
break;
case \ZipArchive::ER_NOZIP:
$message = "The file is not a zip archive";
break;
case \ZipArchive::ER_OPEN:
$message = "The file could not be open";
break;
case \ZipArchive::ER_READ:
$message = "The file could not be read";
break;
case \ZipArchive::ER_SEEK:
$message = "Position error";
break;
default:
$message = "Unknown error on the ZIP archive";
break;
}
$zipMessageHead = $this->translator->trans(
"Zip Error"
);
$message = $this->translator->trans(
"[%zip_head] " . $message,
[
"%zip_head" => $zipMessageHead
]
);
return $message;
}
public function commit()
{
$this->zip->close();
$result = $this->zip->open($this->getCacheFile());
if ($result !== true) {
throw new \ErrorException(
$this->translator->trans(
"The changes could on the Zip Archive not be commited"
)
);
}
return $this;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid file path for \ZipArchive
*/
public function formatFilePath($initialString)
{
/**
* Remove the / at the beginning and the end.
*/
$initialString = trim($initialString, "/");
/**
* Remove the double, triple, ... slashes
*/
$initialString = preg_replace("#\/{2,}#", "/", $initialString);
if (preg_match("#\/?[^\/]+\/[^/]+\/?#", $initialString)) {
$initialString = "/" . $initialString;
}
return $initialString;
}
/**
* @param string $initialString
* @return string
*
* Gives a valid directory path for \ZipArchive
*/
public function formatDirectoryPath($initialString)
{
$initialString = $this->formatFilePath($initialString);
if ($initialString !== "" && $initialString[0] !== "/") {
$initialString = "/" . $initialString;
}
return $initialString . "/";
}
/**
* @return string
*
* This method must return a string, the name of the format.
*
* example:
* return "XML";
*/
public function getName()
{
return "ZIP";
}
/**
* @return string
*
* This method must return a string, the extension of the file format, without the ".".
* The string should be lowercase.
*
* example:
* return "xml";
*/
public function getExtension()
{
return "zip";
}
/**
* @return string
*
* This method must return a string, the mime type of the file format.
*
* example:
* return "application/json";
*/
public function getMimeType()
{
return "application/zip";
}
/**
* @return \ZipArchive
*/
public function getRawZipArchive()
{
return $this->zip;
}
}

View File

@@ -0,0 +1,115 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive;
/**
* Interface ArchiveBuilderInterface
* @package Thelia\Core\FileFormat\Archive
* @author Benjamin Perche <bperche@openstudio.fr>
*
* This interface defines the methods that an archive builder must have.
*/
interface ArchiveBuilderInterface
{
/**
* @param string $filePath It is the path to access the file.
* @param string $directoryInArchive This is the directory where it will be stored in the archive
* @param null|string $name The name of the file in the archive. if it null or empty, it keeps the same name
* @param bool $isOnline
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This methods adds a file in the archive.
* If the file is local, $isOnline must be false,
* If the file online, $filePath must be an URL.
*/
public function addFile($filePath, $directoryInArchive = "/", $name = null, $isOnline = false);
/**
* @param $content
* @param $name
* @param string $directoryInArchive
* @return mixed
* @throws \ErrorException
*
* This method creates a file in the archive with its content
*/
public function addFileFromString($content, $name, $directoryInArchive = "/");
/**
* @param string $pathToFile
* @return null|string
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\FileNotReadableException
* @throws \ErrorException
*
* This method returns a file content
*/
public function getFileContent($pathToFile);
/**
* @param $pathInArchive
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \ErrorException
*
* This method deletes a file in the archive
*/
public function deleteFile($pathInArchive);
/**
* @param $directoryPath
* @return $this
* @throws \ErrorException
*
* This method creates an empty directory
*/
public function addDirectory($directoryPath);
/**
* @params string $filename
* @return \Thelia\Core\HttpFoundation\Response
*
* This method return an instance of a Response with the archive as content.
*/
public function buildArchiveResponse($filename);
/**
* @param string $pathToArchive
* @param bool $isOnline
* @return $this
* @throws \Thelia\Exception\FileNotFoundException
* @throws \Thelia\Exception\HttpUrlException
*
* Loads an archive
*/
public function loadArchive($pathToArchive, $isOnline = false);
/**
* @param $pathToFile
* @return bool
*
* Checks if the archive has a file
*/
public function hasFile($pathToFile);
/**
* @param string $directory
* @return bool
*
* Check if the archive has a directory
*/
public function hasDirectory($directory);
}

View File

@@ -0,0 +1,155 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive;
use Thelia\Core\Translation\Translator;
/**
* Class ArchiveBuilderManager
* @package Thelia\Core\FileFormat\Archive
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ArchiveBuilderManager
{
/** @var array */
protected $archiveBuilders = array();
protected $environment;
public function __construct($environment)
{
$this->environment = $environment;
}
/**
* @param AbstractArchiveBuilder $archiveBuilder
* @return $this
*/
public function add(AbstractArchiveBuilder $archiveBuilder)
{
if (null !== $archiveBuilder) {
$archiveBuilder->setEnvironment($this->environment);
$this->archiveBuilders[$archiveBuilder->getName()] = $archiveBuilder;
}
return $this;
}
/**
* @param $name
* @return $this
* @throws \OutOfBoundsException
*/
public function delete($name)
{
if (!array_key_exists($name, $this->archiveBuilders)) {
$this->throwOutOfBounds($name);
}
unset($this->archiveBuilders[$name]);
return $this;
}
/**
* @return array
*/
public function getAll()
{
return $this->archiveBuilders;
}
/**
* @return array
*/
public function getNames()
{
$names = [];
/** @var AbstractArchiveBuilder $builder */
foreach ($this->archiveBuilders as $builder) {
$names[] = $builder->getName();
}
return $names;
}
public function get($name)
{
if (!array_key_exists($name, $this->archiveBuilders)) {
$this->throwOutOfBounds($name);
}
return $this->archiveBuilders[$name];
}
protected function throwOutOfBounds($name)
{
throw new \OutOfBoundsException(
Translator::getInstance()->trans(
"The archive builder \"%name\" doesn't exist",
[
"%name" => $name
]
)
);
}
/**
* @return array
*
* Return the extensions handled by archive builders
*/
public function getExtensions($withDot = false)
{
$extensions = [];
/** @var AbstractArchiveBuilder $archiveBuilder */
foreach ($this->archiveBuilders as $archiveBuilder) {
$extensionName = $withDot ? ".": "";
$extensionName .= $archiveBuilder->getExtension();
$extensions[$archiveBuilder->getName()] = $extensionName;
}
return $extensions;
}
/**
* @param $extension
* @return bool|AbstractArchiveBuilder
*/
public function getArchiveBuilderByExtension($extension)
{
$extensions = $this->getExtensions();
if (!in_array($extension, $extensions)) {
return false;
} else {
$flip = array_flip($extensions);
$archiveBuilderName = $flip[$extension];
return $this->archiveBuilders[$archiveBuilderName];
}
}
public function getMimeTypes()
{
$mimeTypes = [];
/** @var AbstractArchiveBuilder $formatter */
foreach ($this->archiveBuilders as $formatter) {
$mimeTypes[$formatter->getName()] = $formatter->getMimeType();
}
return $mimeTypes;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Archive;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Trait ArchiveBuilderManagerTrait
* @package Thelia\Core\FileFormat\Archive
* @author Benjamin Perche <bperche@openstudio.fr>
*/
trait ArchiveBuilderManagerTrait
{
/**
* @param ContainerInterface $container
* @return \Thelia\Core\FileFormat\Archive\ArchiveBuilderManager
*/
public function getArchiveBuilderManager(ContainerInterface $container)
{
return $container->get("thelia.manager.archive_builder_manager");
}
}

View File

@@ -0,0 +1,58 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat;
/**
* Interface FormatInterface
* @package Thelia\Core\FileFormat
* @author Benjamin Perche <bperche@openstudio.fr>
*
* This interface defines what a formatter must have:
* - A name ( example: XML, JSON, yaml )
* - An extension ( example: xml, json, yml )
* - A mime type ( example: application/xml, application/json, ... )
*/
interface FormatInterface
{
/**
* @return string
*
* This method must return a string, the name of the format.
*
* example:
* return "XML";
*/
public function getName();
/**
* @return string
*
* This method must return a string, the extension of the file format, without the ".".
* The string should be lowercase.
*
* example:
* return "xml";
*/
public function getExtension();
/**
* @return string
*
* This method must return a string, the mime type of the file format.
*
* example:
* return "application/json";
*/
public function getMimeType();
}

View File

@@ -0,0 +1,33 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat;
/**
* Class FormatType
* @package Thelia\Core\FileFormat
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FormatType
{
/**
* This type is for unbounded formats, in general serialization formats
* example: XML, json, yaml
*/
const UNBOUNDED = "export.unbounded";
/**
* This type is for tabled format ( matrix ), most used by spreadsheet application.
* example: CSV, ODS, XLS
*/
const TABLE = "export.table";
}

View File

@@ -0,0 +1,70 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting;
use Thelia\Core\FileFormat\FormatInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
/**
* Class AbstractFormatter
* @package Thelia\Core\FileFormat\Formatting
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class AbstractFormatter implements FormatInterface, FormatterInterface
{
const FILENAME = "data";
/** @var \Thelia\Core\Translation\Translator */
protected $translator;
/** @var \Thelia\Log\Tlog */
protected $logger;
/** @var array */
protected $order = array();
public function __construct()
{
$this->translator = Translator::getInstance();
$this->logger = Tlog::getInstance();
}
public function getOrder()
{
return $this->order;
}
public function setOrder(array $order)
{
$this->order = $order;
return $this;
}
public function checkOrders(array $values)
{
foreach ($this->getOrder() as $order) {
if (!array_key_exists($order, $values)) {
throw new \ErrorException(
$this->translator->trans(
"The column %column that you want to sort doesn't exist",
[
"%column" => $order
]
)
);
}
}
}
}

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting\Exception;
/**
* Class BadFormattedStringException
* @package Thelia\Core\FileFormat\Formatter\Exception
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class BadFormattedStringException extends \ErrorException
{
}

View File

@@ -0,0 +1,206 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting\Formatter;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType;
/**
* Class CSVFormatter
* @package Thelia\Core\FileFormat\Formatting\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class CSVFormatter extends AbstractFormatter
{
public $delimiter = ";";
public $lineReturn = "\n";
public $stringDelimiter = "\"";
/**
* @return string
*
* This method must return a string, the name of the format.
*
* example:
* return "XML";
*/
public function getName()
{
return "CSV";
}
/**
* @return string
*
* This method must return a string, the extension of the file format, without the ".".
* The string should be lowercase.
*
* example:
* return "xml";
*/
public function getExtension()
{
return "csv";
}
/**
* @return string
*
* This method must return a string, the mime type of the file format.
*
* example:
* return "application/json";
*/
public function getMimeType()
{
return "text/csv";
}
/**
* @param FormatterData $data
* @return mixed
*
* This method must use a FormatterData object and output
* a formatted value.
*/
public function encode(FormatterData $data)
{
$string = "";
/**
* Get the first row and delimiters lengths
*/
$firstRow = $data->getRow();
$delimiterLength = strlen($this->delimiter);
$lineReturnLength = strlen($this->lineReturn);
if ($firstRow === false) {
return "";
}
/**
* check if $this->order doesn't have non-existing rows
*/
$this->checkOrders($firstRow);
$rawKeys = array_keys($firstRow);
$keys = [];
foreach ($rawKeys as $key) {
$keys[$key] = $key;
}
$values = $data->getData();
array_unshift($values, $keys);
while (null !== $row = array_shift($values)) {
/**
* First put the sorted ones
*/
foreach ($this->order as $order) {
$string .= $this->formatField($row[$order]);
unset($row[$order]);
}
/**
* Then place the fields,
* order by name
*/
ksort($row);
foreach ($keys as $key) {
if (array_key_exists($key, $row)) {
$string .= $this->formatField($row[$key]);
}
}
$string = substr($string,0, -$delimiterLength) . $this->lineReturn;
}
return substr($string, 0, -$lineReturnLength);
}
protected function formatField($value)
{
if ($value === null) {
$value = "";
} elseif (!is_scalar($value)) {
$value = serialize($value);
}
$value = str_replace($this->stringDelimiter, "\\" . $this->stringDelimiter, $value);
return $this->stringDelimiter . $value . $this->stringDelimiter . $this->delimiter;
}
/**
* @param $rawData
* @return FormatterData
*
* This must takes raw data as argument and outputs
* a FormatterData object.
*/
public function decode($rawData)
{
$raw = explode($this->lineReturn, $rawData);
$decoded = [];
if (count($raw) > 0) {
$keys = explode($this->delimiter, array_shift($raw));
$keysLength = count($keys);
foreach ($keys as &$key) {
$key = trim($key, $this->stringDelimiter);
}
$columns = count ($keys);
while (null !== $row = array_shift($raw)) {
$newRow = [];
$row = explode($this->delimiter, $row);
if (count($row) >= $keysLength) {
for ($i = 0; $i < $columns; ++$i) {
$value = trim($row[$i], $this->stringDelimiter);
if (false !== $unserialized = @unserialize($row[$i])) {
$value = $unserialized;
}
$newRow[$keys[$i]] = $value;
}
$decoded[] = $newRow;
}
}
}
return (new FormatterData())->setData($decoded);
}
/**
* @return string
*
* return a string that defines the handled format type.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* examples:
* return FormatType::TABLE;
* return FormatType::UNBOUNDED;
*/
public function getHandledType()
{
return FormatType::TABLE;
}
}

View File

@@ -0,0 +1,95 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting\Formatter;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType;
/**
* Class JsonFormatter
* @package Thelia\Core\FileFormat\Formatting\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class JsonFormatter extends AbstractFormatter
{
/**
* @return string
*
* This method must return a string, the name of the format.
*
* example:
* return "XML";
*/
public function getName()
{
return "Json";
}
/**
* @return string
*
* This method must return a string, the extension of the file format, without the ".".
* The string should be lowercase.
*
* example:
* return "xml";
*/
public function getExtension()
{
return "json";
}
/**
* @return string
*
* This method must return a string, the mime type of the file format.
*
* example:
* return "application/json";
*/
public function getMimeType()
{
return "application/json";
}
/**
* @param FormatterData $data
* @return mixed
*
* This method must use a FormatterData object and output
* a formatted value.
*/
public function encode(FormatterData $data)
{
return json_encode($data->getData());
}
/**
* @param $rawData
* @return FormatterData
*
* This must takes raw data as argument and outputs
* a FormatterData object.
*/
public function decode($rawData)
{
return (new FormatterData())->setData(
json_decode($rawData, true)
);
}
public function getHandledType()
{
return FormatType::UNBOUNDED;
}
}

View File

@@ -0,0 +1,239 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting\Formatter;
use Symfony\Component\DependencyInjection\SimpleXMLElement;
use Thelia\Core\FileFormat\Formatting\Exception\BadFormattedStringException;
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType;
/**
* Class XMLFormatter
* @package Thelia\Core\FileFormat\Formatting\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class XMLFormatter extends AbstractFormatter
{
public $root = "data";
public $rowName = "row";
public $nodeName = "entry";
/**
* @return string
*
* This method must return a string, the name of the format.
*
* example:
* return "XML";
*/
public function getName()
{
return "XML";
}
/**
* @return string
*
* This method must return a string, the extension of the file format, without the ".".
* The string should be lowercase.
*
* example:
* return "xml";
*/
public function getExtension()
{
return "xml";
}
/**
* @return string
*
* This method must return a string, the mime type of the file format.
*
* example:
* return "application/json";
*/
public function getMimeType()
{
return "application/xml";
}
/**
* @param FormatterData $data
* @return mixed
*
* This method must use a FormatterData object and output
* a formatted value.
*/
public function encode(FormatterData $data)
{
$arrayData = $data->getData();
$domDocument = new \DOMDocument("1.0");
$container = $domDocument->appendChild(new \DOMElement($this->root));
foreach ($arrayData as $key=>$entry) {
if (is_array($entry)) {
$node = $container->appendChild(new \DOMElement($this->rowName));
$this->recursiveBuild($entry, $node);
} else {
$node = new \DOMElement($this->nodeName);
$container->appendChild($node);
/** @var \DOMElement $lastChild */
$lastChild = $container->lastChild;
$lastChild->setAttribute("name",$key);
$lastChild->setAttribute("value", $entry);
}
}
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
return $domDocument->saveXML();
}
protected function recursiveBuild(array $data, \DOMNode $node)
{
foreach ($data as $key=>$entry) {
if (is_array($entry)) {
$newNode = $node->appendChild(new \DOMElement($key));
$this->recursiveBuild($entry, $newNode);
} else {
$inputNode = new \DOMElement($this->nodeName);
$node->appendChild($inputNode);
/** @var \DOMElement $lastChild */
$lastChild = $node->lastChild;
$lastChild->setAttribute("name",$key);
$lastChild->setAttribute("value", $entry);
}
}
}
/**
* @param $rawData
* @return FormatterData
*
* This must takes raw data as argument and outputs
* a FormatterData object.
*/
public function decode($rawData)
{
$raw = $this->rawDecode($rawData);
return (new FormatterData())->setData($this->recursiveDecode($raw));
}
public function recursiveDecode(array &$data, array &$parent = null)
{
$row = [];
foreach ($data as $name => &$child) {
if (is_array($child)) {
$data = $this->recursiveDecode($child, $data);
}
if ($name === "name" || $name === "value") {
$row[$name] = $this->getValue($name, $data);
}
if (count($row) == 2) {
reset($parent);
if (is_int($key = key($parent))) {
$parent[$row["name"]] = $row["value"];
unset($parent[$key]);
} else {
$data[$row["name"]] = $row["value"];
}
$row=[];
}
}
return $parent === null ? $data : $parent;
}
public function getValue($name, array &$data)
{
$value = $data[$name];
unset ($data[$name]);
return $value;
}
/**
* @param $rawData
* @return array
* @throws \Thelia\Core\FileFormat\Formatting\Exception\BadFormattedStringException
*/
public function rawDecode($rawData)
{
try {
$xml = new SimpleXMLElement($rawData);
} catch (\Exception $e) {
$errorMessage = $this->translator->trans(
"You tried to load a bad formatted XML"
);
$this->logger->error(
$errorMessage .": ". $e->getMessage()
);
throw new BadFormattedStringException(
$errorMessage
);
}
$array = [];
foreach ($xml->children() as $child) {
$this->recursiveRawDecode($array, $child);
}
return $array;
}
protected function recursiveRawDecode(array &$data, \SimpleXMLElement $node)
{
if ($node->count()) {
if (!array_key_exists($node->getName(), $data)) {
$data[$node->getName()] = [];
}
$row = &$data[$node->getName()];
foreach ($node->children() as $child) {
$this->recursiveRawDecode($row, $child);
}
} else {
$newRow = array();
/** @var SimpleXMLElement $attribute */
foreach ($node->attributes() as $attribute) {
$newRow[$attribute->getName()] = $node->getAttributeAsPhp($attribute->getName());
}
if ($node->getName() === $this->nodeName) {
$data[] = $newRow;
} else {
$data[$node->getName()] = $newRow;
}
}
}
public function getHandledType()
{
return FormatType::UNBOUNDED;
}
}

View File

@@ -0,0 +1,240 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Map\TableMap;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Lang;
/**
* Class FormatterData
* @package Thelia\Core\FileFormat\Formatting
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FormatterData
{
protected $lang;
/** @var array */
protected $data = array();
/** @var null|array */
protected $aliases;
/** @var Translator */
protected $translator;
/**
* @param array $aliases
*
* $aliases is a associative array where the key represents propel TYPE_PHP_NAME of column if you use
* loadModelCriteria, or your own aliases for setData, and the value
* is the alias. It can be null or empty if you don't want aliases,
* but remember to always define all the fields the you want:
* non aliases fields will be ignored.
*/
public function __construct(array $aliases = null)
{
$this->translator = Translator::getInstance();
if (!is_array($aliases)) {
$aliases = [];
}
/**
* Lower all the values
*/
foreach ($aliases as $key => $value) {
$lowerKey = strtolower($key);
$lowerValue = strtolower($value);
if ($lowerKey !== $key) {
$aliases[$lowerKey] = $lowerValue;
unset($aliases[$key]);
} else {
$aliases[$key] = $lowerValue;
}
}
$this->aliases = $aliases;
}
/**
* @param array $data
* @return $this
*
* Sets raw data with aliases
* may bug with some formatter
*/
public function setData(array $data)
{
$this->data = $this->applyAliases($data, $this->aliases);
return $this;
}
/**
* @param ModelCriteria $criteria
* @return $this|null
*
* Loads a model criteria.
* Warning: This doesn't goodly support multi table queries.
* If you need to use more than one table, use a PDO instance and
* use the fetchArray() method, or select every columns you need
*/
public function loadModelCriteria(ModelCriteria $criteria)
{
$propelData = $criteria->find();
if (empty($propelData)) {
return null;
}
$asColumns = $propelData->getFormatter()->getAsColumns();
/**
* Format it correctly
* After this pass, we MUST have a 2D array.
* The first may be keyed with integers.
*/
$formattedResult = $propelData
->toArray(null, false, TableMap::TYPE_COLNAME);
if (count($asColumns) > 1) {
/**
* Request with multiple select
* Apply propel aliases
*/
$formattedResult = $this->applyAliases($formattedResult, $asColumns);
} elseif (count($asColumns) === 1) {
/**
* Request with one select
*/
$key = str_replace("\"", "", array_keys($asColumns)[0]);
$formattedResult = [[$key => $formattedResult[0]]];
}
$data = $this->applyAliases($formattedResult, $this->aliases);
/**
* Then store it
*/
$this->data = $data;
return $this;
}
/**
* @param array $data
* @param array $aliases
*/
public function applyAliases(array $data, array $aliases)
{
$formattedData = [];
foreach ($data as $key=>$entry) {
$key = strtolower($key);
if (is_array($entry)) {
$formattedData[$key] = $this->applyAliases($entry, $aliases);
} else {
$alias = isset($aliases[$key]) ? $aliases[$key] : $key;
$formattedData[$alias] = $entry;
}
}
return $formattedData;
}
/**
* @param array $row
* @return $this
*/
public function addRow(array $row)
{
$this->data += [$this->applyAliases($row, $this->aliases)];
return $this;
}
/**
* @param int $index
* @return array|bool
*/
public function popRow()
{
$row = array_pop($this->data);
return $row;
}
/**
* @param int $index
* @return array|bool
* @throws \OutOfBoundsException
*/
public function getRow($index = 0, $reverseAliases = false)
{
if (empty($this->data)) {
return false;
} elseif (!isset($this->data[$index])) {
throw new \OutOfBoundsException(
$this->translator->trans(
"Bad index value %idx",
[
"%idx" => $index
]
)
);
}
$row = $this->data[$index];
if ($reverseAliases === true) {
$row = $this->reverseAliases($row, $this->aliases);
}
return $row;
}
/**
* @param array $data
* @param array $aliases
* @return array
*/
protected function reverseAliases(array $data, array $aliases)
{
return $this->applyAliases($data, array_flip($aliases));
}
public function getData()
{
return $this->data;
}
public function getDataReverseAliases()
{
return $this->reverseAliases($this->data, $this->aliases);
}
public function setLang(Lang $lang = null)
{
$this->lang = $lang;
return $this;
}
public function getLang()
{
return $this->lang;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting;
/**
* Interface FormatterInterface
* @package Thelia\Core\FileFormat\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
interface FormatterInterface
{
/**
* @param FormatterData $data
* @return mixed
*
* This method must use a FormatterData object and output
* a formatted value.
*/
public function encode(FormatterData $data);
/**
* @param $rawData
* @return FormatterData
*
* This must takes raw data as argument and outputs
* a FormatterData object.
*/
public function decode($rawData);
/**
* @return string
*
* return a string that defines the handled format type.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* examples:
* return FormatType::TABLE;
* return FormatType::UNBOUNDED;
*/
public function getHandledType();
}

View File

@@ -0,0 +1,193 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting;
use Thelia\Core\Translation\Translator;
/**
* Class FormatterManager
* @package Thelia\Core\FileFormat\Formatting
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FormatterManager
{
protected $formatters = array();
/**
* @param $archiveCreator
* @return $this
*/
public function add(AbstractFormatter $formatter)
{
if (null !== $formatter) {
$this->formatters[$formatter->getName()] = $formatter;
}
return $this;
}
/**
* @param $name
* @return $this
* @throws \OutOfBoundsException
*/
public function delete($name)
{
if (!array_key_exists($name, $this->formatters)) {
$this->throwOutOfBounds($name);
}
unset($this->formatters[$name]);
return $this;
}
public function get($name)
{
if (!array_key_exists($name, $this->formatters)) {
$this->throwOutOfBounds($name);
}
return $this->formatters[$name];
}
/**
* @return array[AbstractFormatter]
*/
public function getAll()
{
return $this->formatters;
}
/**
* @return array
*/
public function getNames()
{
$names = [];
/** @var AbstractFormatter $formatter */
foreach ($this->formatters as $formatter) {
$names[] = $formatter->getName();
}
return $names;
}
/**
* @param $name
* @throws \OutOfBoundsException
*/
protected function throwOutOfBounds($name)
{
throw new \OutOfBoundsException(
Translator::getInstance()->trans(
"The formatter \"%name\" doesn't exist",
[
"%name" => $name
]
)
);
}
/**
* @return array
*
* Return the extensions handled by archive builders
*/
public function getExtensions($withDot = false)
{
$extensions = [];
/** @var AbstractFormatter $formatter */
foreach ($this->formatters as $formatter) {
$extensionName = $withDot ? ".": "";
$extensionName .= $formatter->getExtension();
$extensions[$formatter->getName()] = $extensionName;
}
return $extensions;
}
public function getExtensionsByTypes($types, $withDot = false)
{
$extensions = [];
/** @var AbstractFormatter $formatter */
foreach ($this->getFormattersByTypes($types) as $formatter) {
$extensionName = $withDot ? ".": "";
$extensionName .= $formatter->getExtension();
$extensions[$formatter->getName()] = $extensionName;
}
return $extensions;
}
/**
* @param $extension
* @return bool|AbstractFormatter
*/
public function getFormatterByExtension($extension)
{
if ($extension[0] === ".") {
$extension = substr($extension, 1);
}
$extensions = $this->getExtensions();
if (!in_array($extension, $extensions)) {
return false;
} else {
$flip = array_flip($extensions);
$formatterName = $flip[$extension];
return $this->formatters[$formatterName];
}
}
public function getFormattersByTypes($types)
{
if (!is_array($types)) {
$types = [$types];
}
$selectedFormatters = [];
/** @var AbstractFormatter $formatter */
foreach ($this->formatters as $formatter) {
$handledType = $formatter->getHandledType();
if (in_array($handledType, $types)) {
$selectedFormatters[$formatter->getName()] = $formatter;
}
}
return $selectedFormatters;
}
public function getMimeTypesByTypes($types)
{
if (!is_array($types)) {
$types = [$types];
}
$mimeTypes = [];
/** @var AbstractFormatter $formatter */
foreach ($this->getFormattersByTypes($types) as $formatter) {
$mimeTypes[$formatter->getName()] = $formatter->getMimeType();
}
return $mimeTypes;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\FileFormat\Formatting;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Trait FormatterManagerTrait
* @package Thelia\Core\FileFormat\Formatter
* @author Benjamin Perche <bperche@openstudio.fr>
*/
trait FormatterManagerTrait
{
/**
* @param ContainerInterface $container
* @return \Thelia\Core\FileFormat\Formatting\FormatterManager
*/
public function getFormatterManager(ContainerInterface $container)
{
return $container->get("thelia.manager.formatter_manager");
}
}

View File

@@ -105,7 +105,7 @@ final class AdminResources
const EXPORT = "admin.export";
const EXPORT_CUSTOMER_NEWSLETTER = "admin.export.customer.newsletter";
const IMPORT = "admin.import";
const TOOLS = "admin.tools";
}

View File

@@ -0,0 +1,132 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;
/**
* Class ArchiveBuilder
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ArchiveBuilder extends BaseLoop implements ArraySearchLoopInterface
{
/**
* this method returns an array
*
* @return array
*/
public function buildArray()
{
/** @var \Thelia\Core\FileFormat\Archive\archiveBuilderManager $service */
$service = $this->container->get("thelia.manager.archive_builder_manager");
$rawArchiveBuilders = array_change_key_case($service->getAll());
$allowedArchiveBuilder = $this->getAllowed_archive_builder();
$archiveBuilders = [];
if ($allowedArchiveBuilder !== null) {
$allowedArchiveBuilder = explode(",", $allowedArchiveBuilder);
foreach ($allowedArchiveBuilder as $archiveBuilder) {
$archiveBuilder = trim(strtolower($archiveBuilder));
if (isset($rawArchiveBuilders[$archiveBuilder])) {
$archiveBuilders[$archiveBuilder] = $rawArchiveBuilders[$archiveBuilder];
}
}
} else {
$archiveBuilders = $rawArchiveBuilders;
}
switch ($this->getOrder()) {
case "alpha":
ksort($archiveBuilders);
break;
case "alpha_reverse":
krsort($archiveBuilders);
break;
}
return $archiveBuilders;
}
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
/** @var \Thelia\Core\FileFormat\Archive\AbstractarchiveBuilder $archiveBuilder */
foreach ($loopResult->getResultDataCollection() as $archiveBuilder) {
$loopResultRow = new LoopResultRow();
$loopResultRow
->set("NAME", $archiveBuilder->getName())
->set("EXTENSION", $archiveBuilder->getExtension())
->set("MIME_TYPE", $archiveBuilder->getMimeType())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* Definition of loop arguments
*
* example :
*
* public function getArgDefinitions()
* {
* return new ArgumentCollection(
*
* Argument::createIntListTypeArgument('id'),
* new Argument(
* 'ref',
* new TypeCollection(
* new Type\AlphaNumStringListType()
* )
* ),
* Argument::createIntListTypeArgument('category'),
* Argument::createBooleanTypeArgument('new'),
* ...
* );
* }
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createAnyTypeArgument("allowed_archive_builder"),
new Argument(
"order",
new TypeCollection(
new EnumType(["alpha", "alpha_reverse"])
),
"alpha"
)
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Model\ExportQuery;
/**
* Class Export
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class Export extends ImportExportType
{
protected function getBaseUrl()
{
return $this->container->getParameter("export.base_url");
}
protected function getQueryModel()
{
return ExportQuery::create();
}
protected function getCategoryName()
{
return "ExportCategoryId";
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Model\ExportCategoryQuery;
/**
* Class ExportCategory
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ExportCategory extends ImportExportCategory
{
protected function getQueryModel()
{
return ExportCategoryQuery::create();
}
}

View File

@@ -0,0 +1,143 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\ArraySearchLoopInterface;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\ExportQuery;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;
/**
* Class Formatter
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class Formatter extends BaseLoop implements ArraySearchLoopInterface
{
/**
* this method returns an array
*
* @return array
*/
public function buildArray()
{
/** @var \Thelia\Core\FileFormat\Formatting\FormatterManager $service */
$service = $this->container->get("thelia.manager.formatter_manager");
$rawFormatters = array_change_key_case($service->getAll());
$exportId = $this->getExport();
$formatters = [];
if ($exportId !== null) {
$export = ExportQuery::create()->findPk($exportId);
if (null !== $export) {
$handlerInstance = $export->getHandleClassInstance($this->container);
$types = $handlerInstance->getHandledTypes();
if (is_scalar($types)) {
$types = [$types];
}
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
foreach ($rawFormatters as $key=>$formatter) {
if (in_array($formatter->getHandledType(), $types)) {
$formatters[$key] = $formatter;
}
}
}
} else {
$formatters = $rawFormatters;
}
switch ($this->getOrder()) {
case "alpha":
ksort($formatters);
break;
case "alpha_reverse":
krsort($formatters);
break;
}
return $formatters;
}
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
foreach ($loopResult->getResultDataCollection() as $formatter) {
$loopResultRow = new LoopResultRow();
$loopResultRow
->set("NAME", $formatter->getName())
->set("EXTENSION", $formatter->getExtension())
->set("MIME_TYPE", $formatter->getMimeType())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* Definition of loop arguments
*
* example :
*
* public function getArgDefinitions()
* {
* return new ArgumentCollection(
*
* Argument::createIntListTypeArgument('id'),
* new Argument(
* 'ref',
* new TypeCollection(
* new Type\AlphaNumStringListType()
* )
* ),
* Argument::createIntListTypeArgument('category'),
* Argument::createBooleanTypeArgument('new'),
* ...
* );
* }
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntTypeArgument("export"),
new Argument(
"order",
new TypeCollection(
new EnumType(["alpha", "alpha_reverse"])
),
"alpha"
)
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Model\ImportQuery;
/**
* Class Import
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class Import extends ImportExportType
{
protected function getBaseUrl()
{
return $this->container->getParameter("import.base_url");
}
protected function getQueryModel()
{
return ImportQuery::create();
}
protected function getCategoryName()
{
return "ImportCategoryId";
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Thelia\Model\ImportCategoryQuery;
/**
* Class ImportCategory
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ImportCategory extends ImportExportCategory
{
protected function getQueryModel()
{
return ImportCategoryQuery::create();
}
}

View File

@@ -0,0 +1,139 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Type\EnumListType;
use Thelia\Type\TypeCollection;
/**
* Class ImportExportCategory
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class ImportExportCategory extends BaseI18nLoop implements PropelSearchLoopInterface
{
protected $timestampable = true;
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $category) {
$loopResultRow = new LoopResultRow($category);
$loopResultRow
->set("ID", $category->getId())
->set("TITLE", $category->getVirtualColumn("i18n_TITLE"))
->set("POSITION", $category->getPosition())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* this method returns a Propel ModelCriteria
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildModelCriteria()
{
/** @var ModelCriteria $query */
$query = $this->getQueryModel();
$this->configureI18nProcessing($query, array('TITLE'));
if (null !== $ids = $this->getId()) {
$query->filterById($ids, Criteria::IN);
}
if (null !== $orders = $this->getOrder()) {
foreach ($orders as $order) {
switch ($order) {
case "id":
$query->orderById();
break;
case "id_reverse":
$query->orderById(Criteria::DESC);
break;
case "alpha":
$query->addAscendingOrderByColumn("i18n_TITLE");
break;
case "alpha_reverse":
$query->addDescendingOrderByColumn("i18n_TITLE");
break;
case "manual":
$query->orderByPosition();
break;
case "manual_reverse":
$query->orderByPosition(Criteria::DESC);
break;
}
}
}
return $query;
}
/**
* Definition of loop arguments
*
* example :
*
* public function getArgDefinitions()
* {
* return new ArgumentCollection(
*
* Argument::createIntListTypeArgument('id'),
* new Argument(
* 'ref',
* new TypeCollection(
* new Type\AlphaNumStringListType()
* )
* ),
* Argument::createIntListTypeArgument('category'),
* Argument::createBooleanTypeArgument('new'),
* ...
* );
* }
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
new Argument(
"order",
new TypeCollection(
new EnumListType(["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"])
),
"manual"
)
);
}
abstract protected function getQueryModel();
}

View File

@@ -0,0 +1,169 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Exception\ClassNotFoundException;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Tools\URL;
use Thelia\Type\EnumListType;
use Thelia\Type\TypeCollection;
/**
* Class ImportExportType
* @package Thelia\Core\Template\Loop
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class ImportExportType extends BaseI18nLoop implements PropelSearchLoopInterface
{
const DEFAULT_ORDER = "manual";
protected $timestampable = true;
/**
* @param LoopResult $loopResult
*
* @return LoopResult
*/
public function parseResults(LoopResult $loopResult)
{
foreach ($loopResult->getResultDataCollection() as $type) {
$loopResultRow = new LoopResultRow($type);
$url = URL::getInstance()->absoluteUrl(
$this->getBaseUrl() . DS . $type->getId()
);
try {
$loopResultRow
->set("HANDLE_CLASS", $type->getHandleClass())
->set("ID", $type->getId())
->set("TITLE", $type->getVirtualColumn("i18n_TITLE"))
->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION"))
->set("URL", $url)
->set("POSITION", $type->getPosition())
->set("CATEGORY_ID", $type->getByName($this->getCategoryName()))
;
} catch (ClassNotFoundException $e) {
} catch (\ErrorException $e) {}
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* this method returns a Propel ModelCriteria
*
* @return \Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildModelCriteria()
{
/** @var ModelCriteria $query */
$query = $this->getQueryModel();
$this->configureI18nProcessing($query, array('TITLE', 'DESCRIPTION'));
if (null !== $ids = $this->getId()) {
$query->filterById($ids);
}
if (null !== $categories = $this->getCategory()) {
$query->filterBy($this->getCategoryName(), $categories, Criteria::IN);
}
if (null !== $orders = $this->getOrder()) {
foreach ($orders as $order) {
switch ($order) {
case "id":
$query->orderById();
break;
case "id_reverse":
$query->orderById(Criteria::DESC);
break;
case "alpha":
$query->addAscendingOrderByColumn("i18n_TITLE");
break;
case "alpha_reverse":
$query->addDescendingOrderByColumn("i18n_TITLE");
break;
case "manual":
$query->orderByPosition();
break;
case "manual_reverse":
$query->orderByPosition(Criteria::DESC);
break;
}
}
}
return $query;
}
/**
* Definition of loop arguments
*
* example :
*
* public function getArgDefinitions()
* {
* return new ArgumentCollection(
*
* Argument::createIntListTypeArgument('id'),
* new Argument(
* 'ref',
* new TypeCollection(
* new Type\AlphaNumStringListType()
* )
* ),
* Argument::createIntListTypeArgument('category'),
* Argument::createBooleanTypeArgument('new'),
* ...
* );
* }
*
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
*/
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createIntListTypeArgument('id'),
Argument::createIntListTypeArgument('category'),
new Argument(
"order",
new TypeCollection(
new EnumListType(static::getAllowedOrders())
),
static::DEFAULT_ORDER
)
);
}
public static function getAllowedOrders()
{
return ["id", "id_reverse", "alpha", "alpha_reverse", "manual", "manual_reverse"];
}
abstract protected function getBaseUrl();
abstract protected function getQueryModel();
abstract protected function getCategoryName();
}

View File

@@ -84,7 +84,7 @@ class ProductSaleElements extends BaseLoop implements PropelSearchLoopInterface
break;
case "quantity_reverse":
$search->orderByQuantity(Criteria::DESC);
break;
break;
case "min_price":
$search->addAscendingOrderByColumn('price_FINAL_PRICE', Criteria::ASC);
break;

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Exception;
/**
* Class FileNotFoundException
* @package Thelia\Exception
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FileNotFoundException extends \ErrorException
{
}

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Exception;
/**
* Class FileNotReadableException
* @package Thelia\Exception
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class FileNotReadableException extends \Exception
{
}

View File

@@ -0,0 +1,23 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Exception;
/**
* Class HttpUrlException
* @package Thelia\Exception
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class HttpUrlException extends \Exception
{
}

View File

@@ -0,0 +1,98 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Translation\Translator;
use Thelia\Model\LangQuery;
/**
* Class ExportForm
* @package Thelia\Form
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ExportForm extends BaseForm
{
protected $translator;
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
{
$this->translator = Translator::getInstance();
parent::__construct($request, $type, $data, $options);
}
protected function buildForm()
{
$this->formBuilder
->add("formatter", "text", array(
"label" => $this->translator->trans("File format"),
"label_attr" => ["for" => "formatter"],
"required" => true,
))
->add("do_compress", "checkbox", array(
"label" => $this->translator->trans("Do compress"),
"label_attr" => ["for" => "do_compress"],
"required" => false,
))
->add("archive_builder", "text", array(
"label" => $this->translator->trans("Archive Format"),
"label_attr" => ["for" => "archive_builder"],
"required" => false,
))
->add("images", "checkbox", array(
"label" => $this->translator->trans("Include images"),
"label_attr" => ["for" => "with_images"],
"required" => false,
))
->add("documents", "checkbox", array(
"label" => $this->translator->trans("Include documents"),
"label_attr" => ["for" => "with_documents"],
"required" => false,
))
->add("language", "integer", array(
"label" => $this->translator->trans("Language"),
"label_attr" => ["for" => "language"],
"required" => true,
"constraints" => [
new Callback([
"methods" => [
[$this, "checkLanguage"],
]
])
]
))
;
}
public function getName()
{
return "thelia_export";
}
public function checkLanguage($value, ExecutionContextInterface $context)
{
if (null === LangQuery::create()->findPk($value)) {
$context->addViolation(
$this->translator->trans(
"The language \"%id\" doesn't exist",
[
"%id" => $value
]
)
);
}
}
}

View File

@@ -0,0 +1,102 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\LangQuery;
/**
* Class ImportForm
* @package Thelia\Form
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ImportForm extends BaseForm
{
/** @var Translator */
protected $translator;
public function __construct(Request $request, $type = "form", $data = array(), $options = array())
{
$this->translator = Translator::getInstance();
parent::__construct($request, $type, $data, $options); // TODO: Change the autogenerated stub
}
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("file_upload", "file", array(
"label" => $this->translator->trans("File to upload"),
"label_attr" => ["for" => "file_to_upload"],
"required" => true,
))
->add("language", "integer", array(
"label" => $this->translator->trans("Language"),
"label_attr" => ["for" => "language"],
"required" => true,
"constraints" => [
new Callback([
"methods" => [
[$this, "checkLanguage"],
]
])
]
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_import";
}
public function checkLanguage($value, ExecutionContextInterface $context)
{
if (null === LangQuery::create()->findPk($value)) {
$context->addViolation(
$this->translator->trans(
"The language \"%id\" doesn't exist",
[
"%id" => $value
]
)
);
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Model\Lang;
/**
* Class AbstractHandler
* @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class AbstractHandler
{
/** @var \Symfony\Component\DependencyInjection\ContainerInterface */
protected $container;
protected $defaultLocale;
/**
* @param ContainerInterface $container
*
* Dependency injection: load the container to be able to get parameters and services
*/
public function __construct(ContainerInterface $container)
{
$this->defaultLocale = Lang::getDefaultLanguage()->getLocale();
$this->container = $container;
}
public function getContainer()
{
return $this->container;
}
/**
* @return \Thelia\Core\HttpFoundation\Request
*/
public function getRequest()
{
return $this->container->get("request");
}
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
abstract public function getHandledTypes();
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export;
/**
* Interface DocumentsExportInterface
* @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
interface DocumentsExportInterface
{
const DOCUMENTS_DIRECTORY = "documents";
/**
* @return array
*
* return an array with the paths to the documents to include in the archive
*/
public function getDocumentsPaths();
}

View File

@@ -0,0 +1,204 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export;
use Propel\Runtime\ActiveQuery\Criterion\Exception\InvalidValueException;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\Exception\LoopException;
use Thelia\Core\Translation\Translator;
use Thelia\Files\FileModelInterface;
use Thelia\Model\Lang;
use Thelia\ImportExport\AbstractHandler;
/**
* Interface ExportHandler
* @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class ExportHandler extends AbstractHandler
{
protected $locale;
/** @var array */
protected $order = array();
protected $isImageExport = false;
protected $isDocumentExport = false;
/**
* @return array
*
* You may override this method to return an array, containing
* the order that you want to have for your columns.
* The order appliance depends on the formatter
*/
protected function getDefaultOrder()
{
return array();
}
/**
* @return null|array
*
* You may override this method to return an array, containing
* the aliases to use.
*/
protected function getAliases()
{
return null;
}
/**
* @return array
*
* Use this method to access the order.
*
*/
public function getOrder()
{
$order = $this->getDefaultOrder();
if (empty($order)) {
$order = $this->order;
}
return $order;
}
public function setOrder(array $order)
{
$this->order = $order;
return $this;
}
/**
* @param \Thelia\Model\Lang $lang
* @return \Thelia\Core\FileFormat\Formatting\FormatterData
*
* The method builds the FormatterData for the formatter
*/
public function buildData(Lang $lang)
{
$data = new FormatterData($this->getAliases());
$query = $this->buildDataSet($lang);
if ($query instanceof ModelCriteria) {
return $data->loadModelCriteria($query);
} elseif (is_array($query)) {
return $data->setData($query);
} elseif ($query instanceof BaseLoop) {
$pagination = null;
$results = $query->exec($pagination);
for ($results->rewind(); $results->valid(); $results->next() ) {
$current = $results->current();
$data->addRow($current->getVarVal());
}
return $data;
}
throw new InvalidValueException(
Translator::getInstance()->trans(
"The method \"%class\"::buildDataSet must return an array or a ModelCriteria",
[
"%class" => get_class($this),
]
)
);
}
public function renderLoop($type, array $args = array())
{
$loopsDefinition = $this->container->getParameter("thelia.parser.loops");
if (!isset($loopsDefinition[$type])) {
throw new LoopException(
Translator::getInstance()->trans(
"The loop \"%loop\" doesn't exist",
[
"%loop" => $type
]
)
);
}
$reflection = new \ReflectionClass($loopsDefinition[$type]);
if (!$reflection->isSubclassOf("Thelia\\Core\\Template\\Element\\BaseLoop")) {
throw new LoopException(
Translator::getInstance()->trans(
"The class \"%class\" must be a subclass of %baseClass",
[
"%class" => $loopsDefinition[$type],
"%baseClass" => "Thelia\\Core\\Template\\Element\\BaseLoop",
]
)
);
}
/** @var BaseLoop $loopInstance */
$loopInstance = $reflection->newInstance($this->container);
$loopInstance->initializeArgs($args);
return $loopInstance;
}
protected function addFileToArray(FileModelInterface $model, array &$paths)
{
$path = $model->getUploadDir() . DS . $model->getFile();
if (is_file($path) && is_readable($path)) {
$parent = $model->getParentFileModel();
$name = constant($parent::TABLE_MAP . "::TABLE_NAME");
$paths[$name . DS . $model->getFile()] = $path;
}
}
public function setDocumentExport($bool)
{
$this->isDocumentExport = (bool) $bool;
return $this;
}
public function setImageExport($bool)
{
$this->isImageExport = (bool) $bool;
return $this;
}
public function isDocumentExport()
{
return $this->isDocumentExport;
}
public function isImageExport()
{
return $this->isImageExport;
}
/**
* @param Lang $lang
* @return ModelCriteria|array|BaseLoop
*/
abstract public function buildDataSet(Lang $lang);
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export;
/**
* interface ImagesExportInterface
* @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
interface ImagesExportInterface
{
const IMAGES_DIRECTORY = "images";
/**
* @return array
*
* return an array with the paths to the images to include in the archive
*/
public function getImagesPaths();
}

View File

@@ -0,0 +1,310 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\FileFormat\FormatType;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\ImportExport\Export\DocumentsExportInterface;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\ImportExport\Export\ImagesExportInterface;
use Thelia\Model\Content;
use Thelia\Model\ContentDocumentI18nQuery;
use Thelia\Model\ContentDocumentQuery;
use Thelia\Model\ContentImageQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\FolderDocumentQuery;
use Thelia\Model\FolderImageQuery;
use Thelia\Model\Lang;
use Thelia\Model\Map\ContentDocumentTableMap;
use Thelia\Model\Map\ContentFolderTableMap;
use Thelia\Model\Map\ContentI18nTableMap;
use Thelia\Model\Map\ContentTableMap;
use Thelia\Model\Map\FolderDocumentTableMap;
use Thelia\Model\Map\FolderI18nTableMap;
use Thelia\Model\Map\FolderImageTableMap;
use Thelia\Model\Map\FolderTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
/**
* Class ContentExport
* @package Thelia\ImportExport\Export\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ContentExport extends ExportHandler implements
ImagesExportInterface,
DocumentsExportInterface
{
const DIRECTORY_NAME = "content";
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
/**
* @return ContentQuery
*/
public function getQuery(Lang $lang)
{
$locale = $lang->getLocale();
$contentI18nJoin = new Join(ContentTableMap::ID, ContentI18nTableMap::ID, Criteria::LEFT_JOIN);
$folderI18nJoin = new Join(FolderTableMap::ID, FolderI18nTableMap::ID, Criteria::LEFT_JOIN);
$urlJoin = new Join(ContentTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
$query = ContentQuery::create()
->select([
ContentTableMap::ID,
ContentTableMap::VISIBLE,
"content_TITLE",
"content_CHAPO",
"content_DESCRIPTION",
"content_CONCLUSION",
"content_seo_TITLE",
"content_seo_DESCRIPTION",
"content_seo_KEYWORDS",
"url_URL",
"folder_TITLE",
"folder_ID",
"folder_IS_DEFAULT"
])
->_if($this->isImageExport())
->useContentImageQuery("content_image_join", Criteria::LEFT_JOIN)
->addAsColumn("content_IMAGES", "GROUP_CONCAT(DISTINCT `content_image_join`.FILE)")
->addSelectColumn("content_IMAGES")
->groupByContentId()
->endUse()
->_endif()
->_if($this->isDocumentExport())
->useContentDocumentQuery("content_document_join", Criteria::LEFT_JOIN)
->addAsColumn("content_DOCUMENTS", "GROUP_CONCAT(DISTINCT `content_document_join`.FILE)")
->addSelectColumn("content_DOCUMENTS")
->groupByContentId()
->endUse()
->_endif()
->useContentFolderQuery(null, Criteria::LEFT_JOIN)
->useFolderQuery(null, Criteria::LEFT_JOIN)
->_if($this->isDocumentExport())
->useFolderDocumentQuery(null, Criteria::LEFT_JOIN)
->addAsColumn("folder_DOCUMENTS", "GROUP_CONCAT(DISTINCT ".FolderDocumentTableMap::FILE.")")
->addSelectColumn("folder_DOCUMENTS")
->endUse()
->_endif()
->_if($this->isImageExport())
->useFolderImageQuery(null, Criteria::LEFT_JOIN)
->addAsColumn("folder_IMAGES", "GROUP_CONCAT(DISTINCT ".FolderImageTableMap::FILE.")")
->addSelectColumn("folder_IMAGES")
->endUse()
->_endif()
->addJoinObject($folderI18nJoin, "folder_i18n_join")
->addJoinCondition("folder_i18n_join", FolderI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)
->addAsColumn("folder_TITLE", FolderI18nTableMap::TITLE)
->addAsColumn("folder_ID", FolderTableMap::ID)
->endUse()
->addAsColumn("folder_IS_DEFAULT", ContentFolderTableMap::DEFAULT_FOLDER)
->endUse()
->addJoinObject($contentI18nJoin, "content_i18n_join")
->addJoinCondition("content_i18n_join", ContentI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)
->addAsColumn("content_TITLE", ContentI18nTableMap::TITLE)
->addAsColumn("content_CHAPO", ContentI18nTableMap::CHAPO)
->addAsColumn("content_DESCRIPTION", ContentI18nTableMap::DESCRIPTION)
->addAsColumn("content_CONCLUSION", ContentI18nTableMap::POSTSCRIPTUM)
->addAsColumn("content_seo_TITLE", ContentI18nTableMap::META_TITLE)
->addAsColumn("content_seo_DESCRIPTION", ContentI18nTableMap::META_DESCRIPTION)
->addAsColumn("content_seo_KEYWORDS", ContentI18nTableMap::META_KEYWORDS)
->addJoinObject($urlJoin, "url_rewriting_join")
->addJoinCondition(
"url_rewriting_join",
RewritingUrlTableMap::VIEW . " = ?",
(new Content())->getRewrittenUrlViewName(),
null,
\PDO::PARAM_STR
)
->addJoinCondition(
"url_rewriting_join",
RewritingUrlTableMap::VIEW_LOCALE . " = ?",
$locale,
null,
\PDO::PARAM_STR
)
->addAsColumn("url_URL", RewritingUrlTableMap::URL)
->groupBy(ContentTableMap::ID)
->groupBy("folder_ID")
->orderById()
;
return $query;
}
/**
* @param Lang $lang
* @return ModelCriteria|array|BaseLoop
*/
public function buildDataSet(Lang $lang)
{
$query = $this->getQuery($lang);
$dataSet = $query
->find()
->toArray()
;
$previous = null;
foreach ($dataSet as &$line) {
if ($previous === null || $previous !== $line[ContentTableMap::ID]) {
$previous = $line[ContentTableMap::ID];
} else {
/**
* Do not repeat content values
*/
$line["content_TITLE"] = "";
$line[ContentTableMap::VISIBLE] = "";
$line["content_CHAPO"] = "";
$line["content_DESCRIPTION"] = "";
$line["content_CONCLUSION"] = "";
$line["content_seo_TITLE"] = "";
$line["content_seo_DESCRIPTION"] = "";
$line["content_seo_KEYWORDS"] = "";
$line["url_URL"] = "";
$line["content_IMAGES"] = "";
$line["content_DOCUMENTS"] = "";
if (isset($line["content_IMAGES"])) {
$line["content_IMAGES"] = "";
}
if (isset($line["content_DOCUMENTS"])) {
$line["content_DOCUMENTS"] = "";
}
}
}
return $dataSet;
}
protected function getDefaultOrder()
{
return [
"id",
"title",
"chapo",
"description",
"conclusion",
"visible",
"seo_title",
"seo_description",
"seo_keywords",
"url",
"folder_id",
"is_default_folder",
"folder_title",
];
}
protected function getAliases()
{
return [
ContentTableMap::ID => "id",
ContentTableMap::VISIBLE => "visible",
"content_TITLE" => "title",
"content_CHAPO" => "chapo",
"content_DESCRIPTION" => "description",
"content_CONCLUSION" => "conclusion",
"content_seo_TITLE" => "seo_title",
"content_seo_DESCRIPTION" => "seo_description",
"content_seo_KEYWORDS" => "seo_keywords",
"url_URL" => "url",
"folder_TITLE" => "folder_title",
"folder_ID" => "folder_id",
"folder_IS_DEFAULT" => "is_default_folder"
];
}
/**
* @return array
*
* return an array with the paths to the documents to include in the archive
*/
public function getDocumentsPaths()
{
$documentPaths = [];
$folderDocuments = FolderDocumentQuery::create()
->find();
/** @var \Thelia\Model\FolderDocument $folderDocument */
foreach ($folderDocuments as $folderDocument) {
$this->addFileToArray($folderDocument, $documentPaths);
}
$contentDocuments = ContentDocumentQuery::create()
->find();
/** @var \Thelia\Model\ContentDocument $contentDocument */
foreach ($contentDocuments as $contentDocument) {
$this->addFileToArray($contentDocument, $documentPaths);
}
return $documentPaths;
}
/**
* @return array
*
* return an array with the paths to the images to include in the archive
*/
public function getImagesPaths()
{
$imagePaths = [];
$folderImages = FolderImageQuery::create()
->find();
/** @var \Thelia\Model\FolderDocument $folderImage */
foreach ($folderImages as $folderImage) {
$this->addFileToArray($folderImage, $imagePaths);
}
$contentImages = ContentImageQuery::create()
->find();
/** @var \Thelia\Model\ContentImage $contentImage */
foreach ($contentImages as $contentImage) {
$this->addFileToArray($contentImage, $imagePaths);
}
return $imagePaths;
}
}

View File

@@ -0,0 +1,357 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\FileFormat\FormatType;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\Model\Currency;
use Thelia\Model\CustomerQuery;
use Thelia\Model\Lang;
use Thelia\Model\Map\AddressTableMap;
use Thelia\Model\Map\CountryI18nTableMap;
use Thelia\Model\Map\CountryTableMap;
use Thelia\Model\Map\CustomerTableMap;
use Thelia\Model\Map\CustomerTitleI18nTableMap;
use Thelia\Model\Map\NewsletterTableMap;
use Thelia\Model\OrderQuery;
use Thelia\Tools\I18n;
/**
* Class CustomerExport
* @package Thelia\ImportExport\Export\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class CustomerExport extends ExportHandler
{
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
*
* The tax engine of Thelia is in PHP, so we can't compute orders for each customers
* directly in SQL, we need two SQL queries, and some computing to get the last order amount and total amount.
*/
public function buildDataSet(Lang $lang)
{
$locale = $lang->getLocale();
$defaultLocale = Lang::getDefaultLanguage()->getLocale();
/**
* This first query get each customer info and addresses.
*/
$newsletterJoin = new Join(CustomerTableMap::EMAIL, NewsletterTableMap::EMAIL, Criteria::LEFT_JOIN);
$query = CustomerQuery::create()
->useCustomerTitleQuery("customer_title_")
->useCustomerTitleI18nQuery("customer_title_i18n_")
->addAsColumn("title_TITLE", "customer_title_i18n_.SHORT")
->endUse()
->endUse()
->useAddressQuery()
->useCountryQuery()
->useCountryI18nQuery()
->addAsColumn("address_COUNTRY", CountryI18nTableMap::TITLE)
->endUse()
->endUse()
->useCustomerTitleQuery("address_title")
->useCustomerTitleI18nQuery("address_title_i18n")
->addAsColumn("address_TITLE", "address_title_i18n.SHORT")
->endUse()
->endUse()
->addAsColumn("address_LABEL", AddressTableMap::LABEL)
->addAsColumn("address_FIRST_NAME", AddressTableMap::FIRSTNAME)
->addAsColumn("address_LAST_NAME", AddressTableMap::LASTNAME)
->addAsColumn("address_COMPANY", AddressTableMap::COMPANY)
->addAsColumn("address_ADDRESS1", AddressTableMap::ADDRESS1)
->addAsColumn("address_ADDRESS2", AddressTableMap::ADDRESS2)
->addAsColumn("address_ADDRESS3", AddressTableMap::ADDRESS3)
->addAsColumn("address_ZIPCODE", AddressTableMap::ZIPCODE)
->addAsColumn("address_CITY", AddressTableMap::CITY)
->addAsColumn("address_PHONE", AddressTableMap::PHONE)
->addAsColumn("address_CELLPHONE", AddressTableMap::CELLPHONE)
->addAsColumn("address_IS_DEFAULT", AddressTableMap::IS_DEFAULT)
->endUse()
->addJoinObject($newsletterJoin)
->addAsColumn("newsletter_IS_REGISTRED", "IF(NOT ISNULL(".NewsletterTableMap::EMAIL."),1,0)")
->select([
CustomerTableMap::ID,
CustomerTableMap::REF,
CustomerTableMap::LASTNAME,
CustomerTableMap::FIRSTNAME,
CustomerTableMap::EMAIL,
CustomerTableMap::DISCOUNT,
CustomerTableMap::CREATED_AT,
"title_TITLE",
"address_TITLE",
"address_LABEL",
"address_COMPANY",
"address_FIRST_NAME",
"address_LAST_NAME",
"address_ADDRESS1",
"address_ADDRESS2",
"address_ADDRESS3",
"address_ZIPCODE",
"address_CITY",
"address_COUNTRY",
"address_PHONE",
"address_CELLPHONE",
"address_IS_DEFAULT",
"newsletter_IS_REGISTRED",
])
->orderById()
;
I18n::addI18nCondition(
$query,
CountryI18nTableMap::TABLE_NAME,
CountryTableMap::ID,
CountryI18nTableMap::ID,
CountryI18nTableMap::LOCALE,
$locale
);
I18n::addI18nCondition(
$query,
CustomerTitleI18nTableMap::TABLE_NAME,
"`customer_title_`.ID",
"`customer_title_i18n_`.ID",
"`customer_title_i18n_`.LOCALE",
$locale
);
I18n::addI18nCondition(
$query,
CustomerTitleI18nTableMap::TABLE_NAME,
"`address_title`.ID",
"`address_title_i18n`.ID",
"`address_title_i18n`.LOCALE",
$locale
);
/** @var CustomerQuery $query */
$results = $query
->find()
->toArray()
;
/**
* Then get the orders
*/
$orders = OrderQuery::create()
->useCustomerQuery()
->orderById()
->endUse()
->find()
;
/**
* And add them info the array
*/
$orders->rewind();
$arrayLength = count($results);
$previousCustomerId = null;
for ($i = 0; $i < $arrayLength; ++$i) {
$currentCustomer = &$results[$i];
$currentCustomerId = $currentCustomer[CustomerTableMap::ID];
unset ($currentCustomer[CustomerTableMap::ID]);
if ($currentCustomerId === $previousCustomerId) {
$currentCustomer["title_TITLE"] = "";
$currentCustomer[CustomerTableMap::LASTNAME] = "";
$currentCustomer[CustomerTableMap::FIRSTNAME] = "";
$currentCustomer[CustomerTableMap::EMAIL] = "";
$currentCustomer["address_COMPANY"] = "";
$currentCustomer["newsletter_IS_REGISTRED"] = "";
$currentCustomer[CustomerTableMap::CREATED_AT] = "";
$currentCustomer[CustomerTableMap::DISCOUNT] = "";
$currentCustomer += [
"order_TOTAL" => "",
"last_order_AMOUNT" => "",
"last_order_DATE" => "",
];
} else {
/**
* Reformat created_at date
*/
$date = $currentCustomer[CustomerTableMap::CREATED_AT];
$dateTime = new \DateTime($date);
$currentCustomer[CustomerTableMap::CREATED_AT] = $dateTime->format($lang->getDatetimeFormat());
/**
* Then compute everything about the orders
*/
$total = 0;
$lastOrderAmount = 0;
$lastOrderDate = null;
$lastOrder = null;
$lastOrderCurrencyCode = null;
$lastOrderId = 0;
$defaultCurrency = Currency::getDefaultCurrency();
$defaultCurrencyCode = $defaultCurrency
->getCode()
;
if (empty($defaultCurrencyCode)) {
$defaultCurrencyCode = $defaultCurrency
->getCode()
;
}
$formattedDate = null;
/** @var \Thelia\Model\Order $currentOrder */
while (false !== $currentOrder = $orders->current()) {
if ($currentCustomerId != $currentOrder->getCustomerId()) {
break;
}
$amount = $currentOrder->getTotalAmount($tax);
if (0 < $rate = $currentOrder->getCurrencyRate()) {
$amount = round($amount / $rate, 2);
}
$total += $amount;
/** @var \DateTime $date */
$date = $currentOrder->getCreatedAt();
if (null === $lastOrderDate || ($date >= $lastOrderDate && $lastOrderId < $currentOrder->getId())) {
$lastOrder = $currentOrder;
$lastOrderDate = $date;
$lastOrderId = $currentOrder->getId();
}
$orders->next();
}
if ($lastOrderDate !== null) {
$formattedDate = $lastOrderDate->format($lang->getDatetimeFormat());
$orderCurrency = $lastOrder->getCurrency();
$lastOrderCurrencyCode = $orderCurrency
->getCode()
;
if (empty($lastOrderCurrencyCode)) {
$lastOrderCurrencyCode = $orderCurrency
->getCode()
;
}
$lastOrderAmount = $lastOrder->getTotalAmount($tax_);
}
$currentCustomer += [
"order_TOTAL" => $total . " " . $defaultCurrencyCode,
"last_order_AMOUNT" => $lastOrderAmount === 0 ? "" : $lastOrderAmount . " " . $lastOrderCurrencyCode,
"last_order_DATE" => $formattedDate,
];
}
$previousCustomerId = $currentCustomerId;
}
return $results;
}
protected function getAliases()
{
return [
CustomerTableMap::REF => "ref",
CustomerTableMap::LASTNAME => "last_name",
CustomerTableMap::FIRSTNAME => "first_name",
CustomerTableMap::EMAIL => "email",
CustomerTableMap::DISCOUNT => "discount",
CustomerTableMap::CREATED_AT => "sign_up_date",
"title_TITLE" => "title",
"address_TITLE" => "address_title",
"address_LABEL" => "label",
"address_IS_DEFAULT" => "is_default_address",
"address_COMPANY" => "company",
"address_ADDRESS1" => "address1",
"address_ADDRESS2" => "address2",
"address_ADDRESS3" => "address3",
"address_ZIPCODE" => "zipcode",
"address_CITY" => "city",
"address_COUNTRY" => "country",
"address_PHONE" => "phone",
"address_CELLPHONE" => "cellphone",
"address_FIRST_NAME" => "address_first_name",
"address_LAST_NAME" => "address_last_name",
"newsletter_IS_REGISTRED" => "is_registered_to_newsletter",
"order_TOTAL" => "total_orders",
"last_order_AMOUNT" => "last_order_amount",
"last_order_DATE" => "last_order_date",
];
}
public function getOrder()
{
return [
"ref",
"title",
"last_name",
"first_name",
"email",
"discount",
"is_registered_to_newsletter",
"sign_up_date",
"total_orders",
"last_order_amount",
"last_order_date",
"label",
"address_title",
"address_first_name",
"address_last_name",
"company",
"address1",
"address2",
"address3",
"zipcode",
"city",
"country",
"phone",
"cellphone",
"is_default_address",
];
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Thelia\Core\FileFormat\FormatType;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\Model\CustomerQuery;
use Thelia\Model\Lang;
use Thelia\Model\Map\CustomerTableMap;
use Thelia\Model\Map\NewsletterTableMap;
use Thelia\Model\NewsletterQuery;
/**
* Class MailingExport
* @package Thelia\ImportExport\Export
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class MailingExport extends ExportHandler
{
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildDataSet(Lang $lang)
{
$newsletter = NewsletterQuery::create()
->select([
NewsletterTableMap::EMAIL,
NewsletterTableMap::LASTNAME,
NewsletterTableMap::FIRSTNAME,
])
->find()
->toArray()
;
$customers = CustomerQuery::create()
->select([
CustomerTableMap::EMAIL,
CustomerTableMap::LASTNAME,
CustomerTableMap::FIRSTNAME,
])
->find()
->toArray()
;
return $customers + $newsletter;
}
protected function getAliases()
{
$email = "email";
$lastName = "last_name";
$firstName = "first_name";
return [
NewsletterTableMap::EMAIL => $email,
CustomerTableMap::EMAIL => $email,
NewsletterTableMap::LASTNAME => $lastName,
CustomerTableMap::LASTNAME => $lastName,
NewsletterTableMap::FIRSTNAME => $firstName,
CustomerTableMap::FIRSTNAME => $firstName,
];
}
/**
* @return string|array
*
* Define all the type of export/formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
}

View File

@@ -0,0 +1,446 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\FileFormat\FormatType;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\Model\Lang;
use Thelia\Model\Map\CountryI18nTableMap;
use Thelia\Model\Map\CurrencyTableMap;
use Thelia\Model\Map\CustomerTableMap;
use Thelia\Model\Map\CustomerTitleI18nTableMap;
use Thelia\Model\Map\OrderCouponTableMap;
use Thelia\Model\Map\OrderProductTableMap;
use Thelia\Model\Map\OrderProductTaxTableMap;
use Thelia\Model\Map\OrderStatusI18nTableMap;
use Thelia\Model\Map\OrderStatusTableMap;
use Thelia\Model\Map\OrderTableMap;
use Thelia\Model\OrderQuery;
use Thelia\Tools\I18n;
/**
* Class OrderExport
* @package Thelia\ImportExport\Export\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class OrderExport extends ExportHandler
{
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
protected function getQuery(Lang $lang)
{
$locale = $lang->getLocale();
$query = OrderQuery::create()
->useCurrencyQuery()
->addAsColumn("currency_CODE", CurrencyTableMap::CODE)
->endUse()
->useCustomerQuery()
->addAsColumn("customer_REF", CustomerTableMap::REF)
->endUse()
->useOrderProductQuery()
->useOrderProductTaxQuery(null, Criteria::LEFT_JOIN)
->addAsColumn(
"product_TAX",
"IF(".OrderProductTableMap::WAS_IN_PROMO.",".
"SUM(".OrderProductTaxTableMap::PROMO_AMOUNT."),".
"SUM(".OrderProductTaxTableMap::AMOUNT.")".
")"
)
->addAsColumn("tax_TITLE", OrderProductTableMap::TAX_RULE_TITLE)
->endUse()
->addAsColumn("product_TITLE", OrderProductTableMap::TITLE)
->addAsColumn(
"product_PRICE",
"IF(".OrderProductTableMap::WAS_IN_PROMO.",".
OrderProductTableMap::PROMO_PRICE .",".
OrderProductTableMap::PRICE .
")"
)
->addAsColumn("product_QUANTITY", OrderProductTableMap::QUANTITY)
->addAsColumn("product_WAS_IN_PROMO", OrderProductTableMap::WAS_IN_PROMO)
->groupById()
->endUse()
->orderById()
->groupById()
->useOrderCouponQuery(null, Criteria::LEFT_JOIN)
->addAsColumn("coupon_COUPONS", "GROUP_CONCAT(".OrderCouponTableMap::TITLE.")")
->groupBy(OrderCouponTableMap::ORDER_ID)
->endUse()
->useModuleRelatedByPaymentModuleIdQuery("payment_module")
->addAsColumn("payment_module_TITLE", "`payment_module`.CODE")
->endUse()
->useModuleRelatedByDeliveryModuleIdQuery("delivery_module")
->addAsColumn("delivery_module_TITLE", "`delivery_module`.CODE")
->endUse()
->useOrderAddressRelatedByDeliveryOrderAddressIdQuery("delivery_address_join")
->useCustomerTitleQuery("delivery_address_customer_title_join")
->useCustomerTitleI18nQuery("delivery_address_customer_title_i18n_join")
->addAsColumn("delivery_address_TITLE", "`delivery_address_customer_title_i18n_join`.SHORT")
->endUse()
->endUse()
->useCountryQuery("delivery_address_country_join")
->useCountryI18nQuery("delivery_address_country_i18n_join")
->addAsColumn("delivery_address_country_TITLE", "`delivery_address_country_i18n_join`.TITLE")
->endUse()
->addAsColumn("delivery_address_COMPANY", "`delivery_address_join`.COMPANY")
->addAsColumn("delivery_address_FIRSTNAME", "`delivery_address_join`.FIRSTNAME")
->addAsColumn("delivery_address_LASTNAME", "`delivery_address_join`.LASTNAME")
->addAsColumn("delivery_address_ADDRESS1", "`delivery_address_join`.ADDRESS1")
->addAsColumn("delivery_address_ADDRESS2", "`delivery_address_join`.ADDRESS2")
->addAsColumn("delivery_address_ADDRESS3", "`delivery_address_join`.ADDRESS3")
->addAsColumn("delivery_address_ZIPCODE", "`delivery_address_join`.ZIPCODE")
->addAsColumn("delivery_address_CITY", "`delivery_address_join`.CITY")
->addAsColumn("delivery_address_PHONE", "`delivery_address_join`.PHONE")
->endUse()
->endUse()
->useOrderAddressRelatedByInvoiceOrderAddressIdQuery("invoice_address_join")
->useCustomerTitleQuery("invoice_address_customer_title_join")
->useCustomerTitleI18nQuery("invoice_address_customer_title_i18n_join")
->addAsColumn("invoice_address_TITLE", "`invoice_address_customer_title_i18n_join`.SHORT")
->endUse()
->endUse()
->useCountryQuery("invoice_address_country_join")
->useCountryI18nQuery("invoice_address_country_i18n_join")
->addAsColumn("invoice_address_country_TITLE", "`invoice_address_country_i18n_join`.TITLE")
->endUse()
->endUse()
->addAsColumn("invoice_address_COMPANY", "`invoice_address_join`.COMPANY")
->addAsColumn("invoice_address_FIRSTNAME", "`invoice_address_join`.FIRSTNAME")
->addAsColumn("invoice_address_LASTNAME", "`invoice_address_join`.LASTNAME")
->addAsColumn("invoice_address_ADDRESS1", "`invoice_address_join`.ADDRESS1")
->addAsColumn("invoice_address_ADDRESS2", "`invoice_address_join`.ADDRESS2")
->addAsColumn("invoice_address_ADDRESS3", "`invoice_address_join`.ADDRESS3")
->addAsColumn("invoice_address_ZIPCODE", "`invoice_address_join`.ZIPCODE")
->addAsColumn("invoice_address_CITY", "`invoice_address_join`.CITY")
->addAsColumn("invoice_address_PHONE", "`invoice_address_join`.PHONE")
->endUse()
->useOrderStatusQuery()
->useOrderStatusI18nQuery()
->addAsColumn("order_status_TITLE", OrderStatusI18nTableMap::TITLE)
->endUse()
->endUse()
->select([
OrderTableMap::REF,
"customer_REF",
"product_TITLE",
"product_PRICE",
"product_TAX",
"tax_TITLE",
// PRODUCT_TTC_PRICE
"product_QUANTITY",
"product_WAS_IN_PROMO",
// ORDER_TOTAL_TTC
OrderTableMap::DISCOUNT,
"coupon_COUPONS",
// TOTAL_WITH_DISCOUNT
OrderTableMap::POSTAGE,
// total ttc +postage
"payment_module_TITLE",
OrderTableMap::INVOICE_REF,
OrderTableMap::DELIVERY_REF,
"delivery_module_TITLE",
"delivery_address_TITLE",
"delivery_address_COMPANY",
"delivery_address_FIRSTNAME",
"delivery_address_LASTNAME",
"delivery_address_ADDRESS1",
"delivery_address_ADDRESS2",
"delivery_address_ADDRESS3",
"delivery_address_ZIPCODE",
"delivery_address_CITY",
"delivery_address_country_TITLE",
"delivery_address_PHONE",
"invoice_address_TITLE",
"invoice_address_COMPANY",
"invoice_address_FIRSTNAME",
"invoice_address_LASTNAME",
"invoice_address_ADDRESS1",
"invoice_address_ADDRESS2",
"invoice_address_ADDRESS3",
"invoice_address_ZIPCODE",
"invoice_address_CITY",
"invoice_address_country_TITLE",
"invoice_address_PHONE",
"order_status_TITLE",
"currency_CODE",
OrderTableMap::CREATED_AT,
])
->orderByCreatedAt(Criteria::DESC)
;
I18n::addI18nCondition(
$query,
CustomerTitleI18nTableMap::TABLE_NAME,
"`delivery_address_customer_title_join`.ID",
CustomerTitleI18nTableMap::ID,
"`delivery_address_customer_title_i18n_join`.LOCALE",
$locale
);
I18n::addI18nCondition(
$query,
CustomerTitleI18nTableMap::TABLE_NAME,
"`invoice_address_customer_title_join`.ID",
CustomerTitleI18nTableMap::ID,
"`invoice_address_customer_title_i18n_join`.LOCALE",
$locale
);
I18n::addI18nCondition(
$query,
CountryI18nTableMap::TABLE_NAME,
"`delivery_address_country_join`.ID",
CountryI18nTableMap::ID,
"`delivery_address_country_i18n_join`.LOCALE",
$locale
);
I18n::addI18nCondition(
$query,
CountryI18nTableMap::TABLE_NAME,
"`invoice_address_country_join`.ID",
CountryI18nTableMap::ID,
"`invoice_address_country_i18n_join`.LOCALE",
$locale
);
I18n::addI18nCondition(
$query,
OrderStatusI18nTableMap::TABLE_NAME,
OrderStatusI18nTableMap::ID,
OrderStatusTableMap::ID,
OrderStatusI18nTableMap::LOCALE,
$locale
);
return $query;
}
/**
* @param Lang $lang
* @return ModelCriteria|array|BaseLoop
*/
public function buildDataSet(Lang $lang)
{
$query = $this->getQuery($lang);
$dataSet = $query
->find()
->toArray()
;
$orders = OrderQuery::create()
->orderById()
->find()
;
$current = 0;
$previous = null;
foreach ($dataSet as &$line) {
/**
* Add computed columns
*/
$line["order_TOTAL_TTC"] = "";
$line["order_TOTAL_WITH_DISCOUNT"] = "";
$line["order_TOTAL_WITH_DISCOUNT_AND_POSTAGE"] = "";
if (null === $previous || $previous !== $line[OrderTableMap::REF]) {
$previous = $line[OrderTableMap::REF];
/** @var \Thelia\Model\Order $order */
$order = $orders->get($current);
$line["order_TOTAL_TTC"] = $order->getTotalAmount($tax, false, false);
$line["order_TOTAL_WITH_DISCOUNT"] = $order->getTotalAmount($tax, false, true);
$line["order_TOTAL_WITH_DISCOUNT_AND_POSTAGE"] = $order->getTotalAmount($tax, true, true);
/**
* Format the date
*/
$date = new \DateTime($line[OrderTableMap::CREATED_AT]);
$line[OrderTableMap::CREATED_AT] = $date->format($lang->getDatetimeFormat());
$current++;
} else {
/**
* Remove all the information of the order
* for each line that only contains a product.
*/
$line["customer_REF"] = "";
$line[OrderTableMap::DISCOUNT] = "";
$line["coupon_COUPONS"] = "";
$line[OrderTableMap::POSTAGE] = "";
$line["payment_module_TITLE"] = "";
$line[OrderTableMap::INVOICE_REF] = "";
$line["delivery_module_TITLE"] = "";
$line["delivery_address_TITLE"] = "";
$line["delivery_address_COMPANY"] = "";
$line["delivery_address_FIRSTNAME"] = "";
$line["delivery_address_LASTNAME"] = "";
$line["delivery_address_ADDRESS1"] = "";
$line["delivery_address_ADDRESS2"] = "";
$line["delivery_address_ADDRESS3"] = "";
$line["delivery_address_ZIPCODE"] = "";
$line["delivery_address_CITY"] = "";
$line["delivery_address_country_TITLE"] = "";
$line["delivery_address_PHONE"] = "";
$line["invoice_address_TITLE"] = "";
$line["invoice_address_COMPANY"] = "";
$line["invoice_address_FIRSTNAME"] = "";
$line["invoice_address_LASTNAME"] = "";
$line["invoice_address_ADDRESS1"] = "";
$line["invoice_address_ADDRESS2"] = "";
$line["invoice_address_ADDRESS3"] = "";
$line["invoice_address_ZIPCODE"] = "";
$line["invoice_address_CITY"] = "";
$line["invoice_address_country_TITLE"] = "";
$line["invoice_address_PHONE"] = "";
$line["order_status_TITLE"] = "";
$line[OrderTableMap::CREATED_AT] = "";
}
$line["product_TAXED_PRICE"] = $line["product_PRICE"] + $line["product_TAX"];
}
return $dataSet;
}
protected function getAliases()
{
return [
OrderTableMap::REF => "ref",
"customer_REF" => "customer_ref",
"product_TITLE" => "product_title",
"product_PRICE" => "price",
"product_TAX" => "tax_amount",
"tax_TITLE" => "tax_title",
"order_TOTAL_TTC" => "total_including_taxes",
"product_QUANTITY" => "quantity",
"product_WAS_IN_PROMO" => "was_in_promo",
"order_TOTAL_WITH_DISCOUNT" => "total_with_discount",
OrderTableMap::DISCOUNT => "discount",
"coupon_COUPONS" => "coupons",
"order_TOTAL_WITH_DISCOUNT_AND_POSTAGE" => "total_discount_and_postage",
OrderTableMap::POSTAGE => "postage",
"product_TAXED_PRICE" => "taxed_price",
"payment_module_TITLE" => "payment_module",
OrderTableMap::INVOICE_REF => "invoice_ref",
OrderTableMap::DELIVERY_REF => "delivery_ref",
"delivery_module_TITLE" => "delivery_module",
"delivery_address_TITLE" => "delivery_title",
"delivery_address_COMPANY" => "delivery_company",
"delivery_address_FIRSTNAME" => "delivery_first_name",
"delivery_address_LASTNAME" => "delivery_last_name",
"delivery_address_ADDRESS1" => "delivery_address1",
"delivery_address_ADDRESS2" => "delivery_address2",
"delivery_address_ADDRESS3" => "delivery_address3",
"delivery_address_ZIPCODE" => "delivery_zip_code",
"delivery_address_CITY" => "delivery_city",
"delivery_address_country_TITLE" => "delivery_country",
"delivery_address_PHONE" => "delivery_phone",
"invoice_address_TITLE" => "invoice_title",
"invoice_address_COMPANY" => "invoice_company",
"invoice_address_FIRSTNAME" => "invoice_first_name",
"invoice_address_LASTNAME" => "invoice_last_name",
"invoice_address_ADDRESS1" => "invoice_address1",
"invoice_address_ADDRESS2" => "invoice_address2",
"invoice_address_ADDRESS3" => "invoice_address3",
"invoice_address_ZIPCODE" => "invoice_zip_code",
"invoice_address_CITY" => "invoice_city",
"invoice_address_country_TITLE" => "invoice_country",
"invoice_address_PHONE" => "invoice_phone",
"order_status_TITLE" => "status",
"currency_CODE" => "currency",
OrderTableMap::CREATED_AT => "date",
];
}
public function getOrder()
{
return [
"ref",
"date",
"customer_ref",
"discount",
"coupons",
"postage",
"total_including_taxes",
"total_with_discount",
"total_discount_and_postage",
"delivery_module",
"delivery_ref",
"payment_module",
"invoice_ref",
"status",
"delivery_title",
"delivery_company",
"delivery_first_name",
"delivery_last_name",
"delivery_address1",
"delivery_address2",
"delivery_address3",
"delivery_zip_code",
"delivery_city",
"delivery_country",
"delivery_phone",
"invoice_title",
"invoice_company",
"invoice_first_name",
"invoice_last_name",
"invoice_address1",
"invoice_address2",
"invoice_address3",
"invoice_zip_code",
"invoice_city",
"invoice_country",
"invoice_phone",
"product_title",
"price",
"taxed_price",
"currency",
"was_in_promo",
"quantity",
"tax_amount",
"tax_title",
];
}
}

View File

@@ -0,0 +1,151 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\Model\Base\AttributeCombinationQuery;
use Thelia\Model\Lang;
use Thelia\Model\Map\AttributeAvI18nTableMap;
use Thelia\Model\Map\AttributeAvTableMap;
use Thelia\Model\Map\CurrencyTableMap;
use Thelia\Model\Map\ProductI18nTableMap;
use Thelia\Model\Map\ProductPriceTableMap;
use Thelia\Model\Map\ProductSaleElementsTableMap;
use Thelia\Model\Map\ProductTableMap;
/**
* Class ProductPricesExport
* @package Thelia\ImportExport\Export\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ProductPricesExport extends ExportHandler
{
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria|\Thelia\Core\Template\Element\BaseLoop
*/
public function buildDataSet(Lang $lang)
{
$locale = $lang->getLocale();
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$attributeAvJoin = new Join(AttributeAvTableMap::ID, AttributeAvI18nTableMap::ID, Criteria::LEFT_JOIN);
$query = AttributeCombinationQuery::create()
->useProductSaleElementsQuery()
->useProductPriceQuery()
->useCurrencyQuery()
->addAsColumn("currency_CODE", CurrencyTableMap::CODE)
->endUse()
->addAsColumn("price_PRICE", ProductPriceTableMap::PRICE)
->addAsColumn("price_PROMO_PRICE", ProductPriceTableMap::PROMO_PRICE)
->endUse()
->useProductQuery()
->addJoinObject($productJoin, "product_join")
->addJoinCondition(
"product_join",
ProductI18nTableMap::LOCALE . " = ?",
$locale,
null,
\PDO::PARAM_STR
)
->addAsColumn("product_TITLE", ProductI18nTableMap::TITLE)
->addAsColumn("product_ID", ProductTableMap::ID)
->endUse()
->addAsColumn("product_sale_elements_REF", ProductSaleElementsTableMap::REF)
->addAsColumn("product_sale_elements_EAN_CODE", ProductSaleElementsTableMap::EAN_CODE)
->addAsColumn("product_sale_elements_PROMO", ProductSaleElementsTableMap::PROMO)
->endUse()
->useAttributeAvQuery()
->addJoinObject($attributeAvJoin, "attribute_av_join")
->addJoinCondition(
"attribute_av_join",
AttributeAvI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR
)
->addAsColumn(
"attribute_av_i18n_ATTRIBUTES",
"GROUP_CONCAT(DISTINCT ".AttributeAvI18nTableMap::TITLE.")"
)
->endUse()
->select([
"product_sale_elements_REF",
"product_sale_elements_EAN_CODE",
"product_sale_elements_PROMO",
"price_PRICE",
"price_PROMO_PRICE",
"currency_CODE",
"product_TITLE",
"attribute_av_i18n_ATTRIBUTES",
])
->groupBy("product_sale_elements_REF")
;
return $query;
}
public function getOrder()
{
return [
"product_id",
"ref",
"title",
"attributes",
"ean",
"price",
"promo_price",
"currency",
"promo",
];
}
protected function getAliases()
{
return [
"product_sale_elements_REF" => "ref",
"product_sale_elements_EAN_CODE" => "ean",
"price_PRICE" => "price",
"price_PROMO_PRICE" => "promo_price",
"currency_CODE" => "currency",
"product_TITLE" => "title",
"attribute_av_i18n_ATTRIBUTES" => "attributes",
"product_sale_elements_PROMO" => "promo",
];
}
}

View File

@@ -0,0 +1,130 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Core\FileFormat\FormatType;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\Model\Map\ProductI18nTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\Product;
use Thelia\Model\ProductAssociatedContentQuery;
use Thelia\Model\Lang;
/**
* Class ProductSEOExport
* @package Thelia\ImportExport\Export\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ProductSEOExport extends ExportHandler
{
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
/**
* @param Lang $lang
* @return array|\Propel\Runtime\ActiveQuery\ModelCriteria
*/
public function buildDataSet(Lang $lang)
{
$locale = $this->locale = $lang->getLocale();
/**
* Join objects
*/
$urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN);
$productJoin = new Join(ProductTableMap::ID, ProductI18nTableMap::ID, Criteria::LEFT_JOIN);
$query = ProductAssociatedContentQuery::create()
->useProductQuery()
->addJoinObject($productJoin, "product_join")
->addJoinCondition("product_join", ProductI18nTableMap::LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)
->addAsColumn("product_i18n_TITLE", ProductI18nTableMap::TITLE)
->addAsColumn("product_REF", ProductTableMap::REF)
->addAsColumn("product_VISIBLE", ProductTableMap::VISIBLE)
->addAsColumn("product_seo_TITLE", ProductI18nTableMap::META_TITLE)
->addAsColumn("product_seo_META_DESCRIPTION", ProductI18nTableMap::META_DESCRIPTION)
->addAsColumn("product_seo_META_KEYWORDS", ProductI18nTableMap::META_KEYWORDS)
->endUse()
->addJoinObject($urlJoin, "rewriting_url_join")
->addJoinCondition("rewriting_url_join", RewritingUrlTableMap::VIEW_LOCALE . " = ?", $locale, null, \PDO::PARAM_STR)
->addJoinCondition(
"rewriting_url_join",
RewritingUrlTableMap::VIEW . " = ?",(new Product())->getRewrittenUrlViewName(),
null,
\PDO::PARAM_STR
)
->addJoinCondition("rewriting_url_join", "ISNULL(".RewritingUrlTableMap::REDIRECTED.")")
->addAsColumn("product_URL", RewritingUrlTableMap::URL)
->select([
"product_REF",
"product_VISIBLE",
"product_i18n_TITLE",
"product_URL",
"product_seo_TITLE",
"product_seo_META_DESCRIPTION",
"product_seo_META_KEYWORDS",
])
;
return $query;
}
protected function getDefaultOrder()
{
return [
"ref",
"product_title",
"visible",
"url",
"page_title",
"meta_description",
"meta_keywords",
];
}
protected function getAliases()
{
return [
"product_REF" => "ref",
"product_VISIBLE" => "visible",
"product_i18n_TITLE" => "product_title",
"product_URL" => "url",
"product_seo_TITLE" => "page_title",
"product_seo_META_DESCRIPTION" => "meta_description",
"product_seo_META_KEYWORDS" => "meta_keywords",
];
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Export\Type;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\Lang;
use Thelia\Model\Map\AttributeCombinationTableMap;
use Thelia\Model\Map\ProductSaleElementsTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\Map\TaxRuleI18nTableMap;
use Thelia\Model\Map\TaxRuleTableMap;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Tools\I18n;
/**
* Class ProductTaxedPricesExport
* @package Thelia\ImportExport\Export\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ProductTaxedPricesExport extends ProductPricesExport
{
public function buildDataSet(Lang $lang)
{
/** @var \Thelia\Model\AttributeCombinationQuery $query */
$query = parent::buildDataSet($lang);
$pseJoin = new Join(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductSaleElementsTableMap::ID);
$pseJoin->setRightTableAlias("pse_tax_join");
$productJoin = new Join(ProductSaleElementsTableMap::ID, ProductTableMap::ID);
$productJoin->setRightTableAlias("product_tax_join");
$taxJoin = new Join("`product_tax_join`.TAX_RULE_ID", TaxRuleTableMap::ID, Criteria::LEFT_JOIN);
$taxI18nJoin = new Join(TaxRuleTableMap::ID, TaxRuleI18nTableMap::ID, Criteria::LEFT_JOIN);
$query
->addJoinObject($pseJoin, "pse_tax_join")
->addJoinObject($productJoin, "product_tax_join")
->addJoinObject($productJoin)
->addJoinObject($taxJoin)
->addJoinObject($taxI18nJoin)
->addAsColumn("product_TAX_TITLE", TaxRuleI18nTableMap::TITLE)
->addAsColumn("tax_ID", TaxRuleTableMap::ID)
->select($query->getSelect() + [
"product_TAX_TITLE",
"tax_ID",
])
;
I18n::addI18nCondition(
$query,
TaxRuleI18nTableMap::TABLE_NAME,
TaxRuleTableMap::ID,
TaxRuleI18nTableMap::ID,
TaxRuleI18nTableMap::LOCALE,
$lang->getLocale()
);
$dataSet = $query
->keepQuery(true)
->find()
->toArray()
;
$productSaleElements = ProductSaleElementsQuery::create()
->find()
->toKeyIndex("Ref")
;
$currencies = CurrencyQuery::create()
->find()
->toKeyIndex("Code")
;
foreach ($dataSet as &$line) {
/** @var \Thelia\Model\ProductSaleElements $pse */
$pse = $productSaleElements[$line["product_sale_elements_REF"]];
$pricesTools = $pse->getPricesByCurrency($currencies[$line["currency_CODE"]]);
$line["price_PRICE"] = $pricesTools->getPrice();
$line["price_PROMO_PRICE"] = $pricesTools->getPromoPrice();
}
return $dataSet;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Import;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\AbstractHandler;
/**
* Class ImportHandler
* @package Thelia\ImportExport
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class ImportHandler extends AbstractHandler
{
protected $importedRows = 0;
/** @var Translator */
protected $translator;
public function __construct(ContainerInterface $container)
{
$this->translator = Translator::getInstance();
parent::__construct($container);
}
public function getImportedRows()
{
return $this->importedRows;
}
protected function checkMandatoryColumns(array $row)
{
$mandatoryColumns = $this->getMandatoryColumns();
sort($mandatoryColumns);
$diff = [];
foreach ($mandatoryColumns as $name) {
if (!isset($row[$name]) || empty($row[$name])) {
$diff[] = $name;
}
}
if (!empty($diff)) {
throw new \UnexpectedValueException(
$this->translator->trans(
"The following columns are missing: %columns",
[
"%columns" => implode(", ", $diff),
]
)
);
}
}
/**
* @return array The mandatory columns to have for import
*/
abstract protected function getMandatoryColumns();
/**
* @param \Thelia\Core\FileFormat\Formatting\FormatterData
* @return string|array error messages
*
* The method does the import routine from a FormatterData
*/
abstract public function retrieveFromFormatterData(FormatterData $data);
}

View File

@@ -0,0 +1,136 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Import\Type;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\Import\ImportHandler;
use Thelia\Model\Currency;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\ProductPrice;
use Thelia\Model\ProductPriceQuery;
use Thelia\Model\ProductSaleElementsQuery;
/**
* Class ProductPricesImport
* @package Thelia\ImportExport\Import\Type
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ProductPricesImport extends ImportHandler
{
/**
* @return string|array
*
* Define all the type of formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
/**
* @param \Thelia\Core\FileFormat\Formatting\FormatterData
* @return string|array error messages
*
* The method does the import routine from a FormatterData
*/
public function retrieveFromFormatterData(FormatterData $data)
{
$errors = [];
$translator = Translator::getInstance();
while (null !== $row = $data->popRow()) {
$this->checkMandatoryColumns($row);
$obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]);
if ($obj === null) {
$errorMessage = $translator->trans(
"The product sale element reference %ref doesn't exist",
[
"%ref" => $row["ref"]
]
);
$errors[] = $errorMessage ;
} else {
$currency = null;
if (isset($row["currency"])) {
$currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
}
if ($currency === null) {
$currency = Currency::getDefaultCurrency();
}
$price = ProductPriceQuery::create()
->filterByProductSaleElementsId($obj->getId())
->findOneByCurrencyId($currency->getId())
;
if ($price === null) {
$price = new ProductPrice();
$price
->setProductSaleElements($obj)
->setCurrency($currency)
;
}
$price->setPrice($row["price"]);
if (isset($row["promo_price"])) {
$price->setPromoPrice($row["promo_price"]);
}
if (isset($row["promo"])) {
$price
->getProductSaleElements()
->setPromo((int) $row["promo"])
->save()
;
}
$price->save();
$this->importedRows++;
}
}
return $errors;
}
/**
* @return array The mandatory columns to have for import
*/
protected function getMandatoryColumns()
{
return ["ref", "price"];
}
}

View File

@@ -0,0 +1,94 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\ImportExport\Import\Type;
use Thelia\Core\FileFormat\Formatting\FormatterData;
use Thelia\Core\FileFormat\FormatType;
use Thelia\ImportExport\Import\ImportHandler;
use Thelia\Model\ProductSaleElementsQuery;
/**
* Class ControllerTestBase
* @package Thelia\ImportExport\Import
* @author Benjamin Perche <bperche@openstudio.fr>
*/
class ProductStockImport extends ImportHandler
{
/**
* @param \Thelia\Core\FileFormat\Formatting\FormatterData
* @return string|array error messages
*
* The method does the import routine from a FormatterData
*/
public function retrieveFromFormatterData(FormatterData $data)
{
$errors = [];
while (null !== $row = $data->popRow()) {
/**
* Check for mandatory columns
*/
$this->checkMandatoryColumns($row);
$obj = ProductSaleElementsQuery::create()->findOneByRef($row["ref"]);
if ($obj === null) {
$errors[] = $this->translator->trans(
"The product sale element reference %ref doesn't exist",
[
"%ref" => $row["ref"]
]
);
} else {
$obj->setQuantity($row["stock"]);
if (isset($row["ean"]) && !empty($row["ean"])) {
$obj->setEanCode($row["ean"]);
}
$obj->save();
$this->importedRows++;
}
}
return $errors;
}
protected function getMandatoryColumns()
{
return ["ref", "stock"];
}
/**
* @return string|array
*
* Define all the type of import/formatters that this can handle
* return a string if it handle a single type ( specific exports ),
* or an array if multiple.
*
* Thelia types are defined in \Thelia\Core\FileFormat\FormatType
*
* example:
* return array(
* FormatType::TABLE,
* FormatType::UNBOUNDED,
* );
*/
public function getHandledTypes()
{
return array(
FormatType::TABLE,
FormatType::UNBOUNDED,
);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,508 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\ExportCategoryI18n as ChildExportCategoryI18n;
use Thelia\Model\ExportCategoryI18nQuery as ChildExportCategoryI18nQuery;
use Thelia\Model\Map\ExportCategoryI18nTableMap;
/**
* Base class that represents a query for the 'export_category_i18n' table.
*
*
*
* @method ChildExportCategoryI18nQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildExportCategoryI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column
* @method ChildExportCategoryI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column
*
* @method ChildExportCategoryI18nQuery groupById() Group by the id column
* @method ChildExportCategoryI18nQuery groupByLocale() Group by the locale column
* @method ChildExportCategoryI18nQuery groupByTitle() Group by the title column
*
* @method ChildExportCategoryI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildExportCategoryI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildExportCategoryI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildExportCategoryI18nQuery leftJoinExportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ExportCategory relation
* @method ChildExportCategoryI18nQuery rightJoinExportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ExportCategory relation
* @method ChildExportCategoryI18nQuery innerJoinExportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ExportCategory relation
*
* @method ChildExportCategoryI18n findOne(ConnectionInterface $con = null) Return the first ChildExportCategoryI18n matching the query
* @method ChildExportCategoryI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildExportCategoryI18n matching the query, or a new ChildExportCategoryI18n object populated from the query conditions when no match is found
*
* @method ChildExportCategoryI18n findOneById(int $id) Return the first ChildExportCategoryI18n filtered by the id column
* @method ChildExportCategoryI18n findOneByLocale(string $locale) Return the first ChildExportCategoryI18n filtered by the locale column
* @method ChildExportCategoryI18n findOneByTitle(string $title) Return the first ChildExportCategoryI18n filtered by the title column
*
* @method array findById(int $id) Return ChildExportCategoryI18n objects filtered by the id column
* @method array findByLocale(string $locale) Return ChildExportCategoryI18n objects filtered by the locale column
* @method array findByTitle(string $title) Return ChildExportCategoryI18n objects filtered by the title column
*
*/
abstract class ExportCategoryI18nQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ExportCategoryI18nQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ExportCategoryI18n', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildExportCategoryI18nQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildExportCategoryI18nQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ExportCategoryI18nQuery) {
return $criteria;
}
$query = new \Thelia\Model\ExportCategoryI18nQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(array(12, 34), $con);
* </code>
*
* @param array[$id, $locale] $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildExportCategoryI18n|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ExportCategoryI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ExportCategoryI18nTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExportCategoryI18n A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `LOCALE`, `TITLE` FROM `export_category_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
$stmt->bindValue(':p1', $key[1], PDO::PARAM_STR);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildExportCategoryI18n();
$obj->hydrate($row);
ExportCategoryI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExportCategoryI18n|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
$this->addUsingAlias(ExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL);
$this->addUsingAlias(ExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
return $this;
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
if (empty($keys)) {
return $this->add(null, '1<>1', Criteria::CUSTOM);
}
foreach ($keys as $key) {
$cton0 = $this->getNewCriterion(ExportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL);
$cton1 = $this->getNewCriterion(ExportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
$cton0->addAnd($cton1);
$this->addOr($cton0);
}
return $this;
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @see filterByExportCategory()
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ExportCategoryI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ExportCategoryI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportCategoryI18nTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the locale column
*
* Example usage:
* <code>
* $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue'
* $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%'
* </code>
*
* @param string $locale The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByLocale($locale = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($locale)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $locale)) {
$locale = str_replace('*', '%', $locale);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportCategoryI18nTableMap::LOCALE, $locale, $comparison);
}
/**
* Filter the query on the title column
*
* Example usage:
* <code>
* $query->filterByTitle('fooValue'); // WHERE title = 'fooValue'
* $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%'
* </code>
*
* @param string $title The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByTitle($title = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($title)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $title)) {
$title = str_replace('*', '%', $title);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportCategoryI18nTableMap::TITLE, $title, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\ExportCategory object
*
* @param \Thelia\Model\ExportCategory|ObjectCollection $exportCategory The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByExportCategory($exportCategory, $comparison = null)
{
if ($exportCategory instanceof \Thelia\Model\ExportCategory) {
return $this
->addUsingAlias(ExportCategoryI18nTableMap::ID, $exportCategory->getId(), $comparison);
} elseif ($exportCategory instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(ExportCategoryI18nTableMap::ID, $exportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByExportCategory() only accepts arguments of type \Thelia\Model\ExportCategory or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ExportCategory relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function joinExportCategory($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ExportCategory');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ExportCategory');
}
return $this;
}
/**
* Use the ExportCategory relation ExportCategory object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ExportCategoryQuery A secondary query class using the current class as primary query
*/
public function useExportCategoryQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinExportCategory($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ExportCategory', '\Thelia\Model\ExportCategoryQuery');
}
/**
* Exclude object from result
*
* @param ChildExportCategoryI18n $exportCategoryI18n Object to remove from the list of results
*
* @return ChildExportCategoryI18nQuery The current query, for fluid interface
*/
public function prune($exportCategoryI18n = null)
{
if ($exportCategoryI18n) {
$this->addCond('pruneCond0', $this->getAliasedColName(ExportCategoryI18nTableMap::ID), $exportCategoryI18n->getId(), Criteria::NOT_EQUAL);
$this->addCond('pruneCond1', $this->getAliasedColName(ExportCategoryI18nTableMap::LOCALE), $exportCategoryI18n->getLocale(), Criteria::NOT_EQUAL);
$this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
}
return $this;
}
/**
* Deletes all rows from the export_category_i18n table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ExportCategoryI18nTableMap::clearInstancePool();
ExportCategoryI18nTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildExportCategoryI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildExportCategoryI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryI18nTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ExportCategoryI18nTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ExportCategoryI18nTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ExportCategoryI18nTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
} // ExportCategoryI18nQuery

View File

@@ -0,0 +1,797 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\ExportCategory as ChildExportCategory;
use Thelia\Model\ExportCategoryI18nQuery as ChildExportCategoryI18nQuery;
use Thelia\Model\ExportCategoryQuery as ChildExportCategoryQuery;
use Thelia\Model\Map\ExportCategoryTableMap;
/**
* Base class that represents a query for the 'export_category' table.
*
*
*
* @method ChildExportCategoryQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildExportCategoryQuery orderByRef($order = Criteria::ASC) Order by the ref column
* @method ChildExportCategoryQuery orderByPosition($order = Criteria::ASC) Order by the position column
* @method ChildExportCategoryQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildExportCategoryQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
* @method ChildExportCategoryQuery groupById() Group by the id column
* @method ChildExportCategoryQuery groupByRef() Group by the ref column
* @method ChildExportCategoryQuery groupByPosition() Group by the position column
* @method ChildExportCategoryQuery groupByCreatedAt() Group by the created_at column
* @method ChildExportCategoryQuery groupByUpdatedAt() Group by the updated_at column
*
* @method ChildExportCategoryQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildExportCategoryQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildExportCategoryQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildExportCategoryQuery leftJoinExport($relationAlias = null) Adds a LEFT JOIN clause to the query using the Export relation
* @method ChildExportCategoryQuery rightJoinExport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Export relation
* @method ChildExportCategoryQuery innerJoinExport($relationAlias = null) Adds a INNER JOIN clause to the query using the Export relation
*
* @method ChildExportCategoryQuery leftJoinExportCategoryI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ExportCategoryI18n relation
* @method ChildExportCategoryQuery rightJoinExportCategoryI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ExportCategoryI18n relation
* @method ChildExportCategoryQuery innerJoinExportCategoryI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ExportCategoryI18n relation
*
* @method ChildExportCategory findOne(ConnectionInterface $con = null) Return the first ChildExportCategory matching the query
* @method ChildExportCategory findOneOrCreate(ConnectionInterface $con = null) Return the first ChildExportCategory matching the query, or a new ChildExportCategory object populated from the query conditions when no match is found
*
* @method ChildExportCategory findOneById(int $id) Return the first ChildExportCategory filtered by the id column
* @method ChildExportCategory findOneByRef(string $ref) Return the first ChildExportCategory filtered by the ref column
* @method ChildExportCategory findOneByPosition(int $position) Return the first ChildExportCategory filtered by the position column
* @method ChildExportCategory findOneByCreatedAt(string $created_at) Return the first ChildExportCategory filtered by the created_at column
* @method ChildExportCategory findOneByUpdatedAt(string $updated_at) Return the first ChildExportCategory filtered by the updated_at column
*
* @method array findById(int $id) Return ChildExportCategory objects filtered by the id column
* @method array findByRef(string $ref) Return ChildExportCategory objects filtered by the ref column
* @method array findByPosition(int $position) Return ChildExportCategory objects filtered by the position column
* @method array findByCreatedAt(string $created_at) Return ChildExportCategory objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildExportCategory objects filtered by the updated_at column
*
*/
abstract class ExportCategoryQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ExportCategoryQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ExportCategory', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildExportCategoryQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildExportCategoryQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ExportCategoryQuery) {
return $criteria;
}
$query = new \Thelia\Model\ExportCategoryQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(12, $con);
* </code>
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildExportCategory|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ExportCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ExportCategoryTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExportCategory A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `REF`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `export_category` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildExportCategory();
$obj->hydrate($row);
ExportCategoryTableMap::addInstanceToPool($obj, (string) $key);
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExportCategory|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(12, 56, 832), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
return $this->addUsingAlias(ExportCategoryTableMap::ID, $key, Criteria::EQUAL);
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
return $this->addUsingAlias(ExportCategoryTableMap::ID, $keys, Criteria::IN);
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ExportCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ExportCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportCategoryTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the ref column
*
* Example usage:
* <code>
* $query->filterByRef('fooValue'); // WHERE ref = 'fooValue'
* $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%'
* </code>
*
* @param string $ref The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByRef($ref = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($ref)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $ref)) {
$ref = str_replace('*', '%', $ref);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportCategoryTableMap::REF, $ref, $comparison);
}
/**
* Filter the query on the position column
*
* Example usage:
* <code>
* $query->filterByPosition(1234); // WHERE position = 1234
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
* </code>
*
* @param mixed $position The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByPosition($position = null, $comparison = null)
{
if (is_array($position)) {
$useMinMax = false;
if (isset($position['min'])) {
$this->addUsingAlias(ExportCategoryTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($position['max'])) {
$this->addUsingAlias(ExportCategoryTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportCategoryTableMap::POSITION, $position, $comparison);
}
/**
* Filter the query on the created_at column
*
* Example usage:
* <code>
* $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13'
* </code>
*
* @param mixed $createdAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByCreatedAt($createdAt = null, $comparison = null)
{
if (is_array($createdAt)) {
$useMinMax = false;
if (isset($createdAt['min'])) {
$this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createdAt['max'])) {
$this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, $createdAt, $comparison);
}
/**
* Filter the query on the updated_at column
*
* Example usage:
* <code>
* $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13'
* </code>
*
* @param mixed $updatedAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByUpdatedAt($updatedAt = null, $comparison = null)
{
if (is_array($updatedAt)) {
$useMinMax = false;
if (isset($updatedAt['min'])) {
$this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updatedAt['max'])) {
$this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, $updatedAt, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\Export object
*
* @param \Thelia\Model\Export|ObjectCollection $export the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByExport($export, $comparison = null)
{
if ($export instanceof \Thelia\Model\Export) {
return $this
->addUsingAlias(ExportCategoryTableMap::ID, $export->getExportCategoryId(), $comparison);
} elseif ($export instanceof ObjectCollection) {
return $this
->useExportQuery()
->filterByPrimaryKeys($export->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByExport() only accepts arguments of type \Thelia\Model\Export or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Export relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function joinExport($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Export');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Export');
}
return $this;
}
/**
* Use the Export relation Export object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ExportQuery A secondary query class using the current class as primary query
*/
public function useExportQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinExport($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Export', '\Thelia\Model\ExportQuery');
}
/**
* Filter the query by a related \Thelia\Model\ExportCategoryI18n object
*
* @param \Thelia\Model\ExportCategoryI18n|ObjectCollection $exportCategoryI18n the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function filterByExportCategoryI18n($exportCategoryI18n, $comparison = null)
{
if ($exportCategoryI18n instanceof \Thelia\Model\ExportCategoryI18n) {
return $this
->addUsingAlias(ExportCategoryTableMap::ID, $exportCategoryI18n->getId(), $comparison);
} elseif ($exportCategoryI18n instanceof ObjectCollection) {
return $this
->useExportCategoryI18nQuery()
->filterByPrimaryKeys($exportCategoryI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByExportCategoryI18n() only accepts arguments of type \Thelia\Model\ExportCategoryI18n or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ExportCategoryI18n relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function joinExportCategoryI18n($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ExportCategoryI18n');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ExportCategoryI18n');
}
return $this;
}
/**
* Use the ExportCategoryI18n relation ExportCategoryI18n object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ExportCategoryI18nQuery A secondary query class using the current class as primary query
*/
public function useExportCategoryI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinExportCategoryI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ExportCategoryI18n', '\Thelia\Model\ExportCategoryI18nQuery');
}
/**
* Exclude object from result
*
* @param ChildExportCategory $exportCategory Object to remove from the list of results
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function prune($exportCategory = null)
{
if ($exportCategory) {
$this->addUsingAlias(ExportCategoryTableMap::ID, $exportCategory->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
/**
* Deletes all rows from the export_category table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ExportCategoryTableMap::clearInstancePool();
ExportCategoryTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildExportCategory or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildExportCategory object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportCategoryTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ExportCategoryTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ExportCategoryTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ExportCategoryTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
// i18n behavior
/**
* Adds a JOIN clause to the query using the i18n relation
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$relationName = $relationAlias ? $relationAlias : 'ExportCategoryI18n';
return $this
->joinExportCategoryI18n($relationAlias, $joinType)
->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale);
}
/**
* Adds a JOIN clause to the query and hydrates the related I18n object.
* Shortcut for $c->joinI18n($locale)->with()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN)
{
$this
->joinI18n($locale, null, $joinType)
->with('ExportCategoryI18n');
$this->with['ExportCategoryI18n']->setIsWithOneToMany(false);
return $this;
}
/**
* Use the I18n relation query object
*
* @see useQuery()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildExportCategoryI18nQuery A secondary query class using the current class as primary query
*/
public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinI18n($locale, $relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ExportCategoryI18n', '\Thelia\Model\ExportCategoryI18nQuery');
}
// timestampable behavior
/**
* Filter by the latest updated
*
* @param int $nbDays Maximum age of the latest update in days
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function recentlyUpdated($nbDays = 7)
{
return $this->addUsingAlias(ExportCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Filter by the latest created
*
* @param int $nbDays Maximum age of in days
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function recentlyCreated($nbDays = 7)
{
return $this->addUsingAlias(ExportCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Order by update date desc
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function lastUpdatedFirst()
{
return $this->addDescendingOrderByColumn(ExportCategoryTableMap::UPDATED_AT);
}
/**
* Order by update date asc
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function firstUpdatedFirst()
{
return $this->addAscendingOrderByColumn(ExportCategoryTableMap::UPDATED_AT);
}
/**
* Order by create date desc
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function lastCreatedFirst()
{
return $this->addDescendingOrderByColumn(ExportCategoryTableMap::CREATED_AT);
}
/**
* Order by create date asc
*
* @return ChildExportCategoryQuery The current query, for fluid interface
*/
public function firstCreatedFirst()
{
return $this->addAscendingOrderByColumn(ExportCategoryTableMap::CREATED_AT);
}
} // ExportCategoryQuery

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,541 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\ExportI18n as ChildExportI18n;
use Thelia\Model\ExportI18nQuery as ChildExportI18nQuery;
use Thelia\Model\Map\ExportI18nTableMap;
/**
* Base class that represents a query for the 'export_i18n' table.
*
*
*
* @method ChildExportI18nQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildExportI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column
* @method ChildExportI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column
* @method ChildExportI18nQuery orderByDescription($order = Criteria::ASC) Order by the description column
*
* @method ChildExportI18nQuery groupById() Group by the id column
* @method ChildExportI18nQuery groupByLocale() Group by the locale column
* @method ChildExportI18nQuery groupByTitle() Group by the title column
* @method ChildExportI18nQuery groupByDescription() Group by the description column
*
* @method ChildExportI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildExportI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildExportI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildExportI18nQuery leftJoinExport($relationAlias = null) Adds a LEFT JOIN clause to the query using the Export relation
* @method ChildExportI18nQuery rightJoinExport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Export relation
* @method ChildExportI18nQuery innerJoinExport($relationAlias = null) Adds a INNER JOIN clause to the query using the Export relation
*
* @method ChildExportI18n findOne(ConnectionInterface $con = null) Return the first ChildExportI18n matching the query
* @method ChildExportI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildExportI18n matching the query, or a new ChildExportI18n object populated from the query conditions when no match is found
*
* @method ChildExportI18n findOneById(int $id) Return the first ChildExportI18n filtered by the id column
* @method ChildExportI18n findOneByLocale(string $locale) Return the first ChildExportI18n filtered by the locale column
* @method ChildExportI18n findOneByTitle(string $title) Return the first ChildExportI18n filtered by the title column
* @method ChildExportI18n findOneByDescription(string $description) Return the first ChildExportI18n filtered by the description column
*
* @method array findById(int $id) Return ChildExportI18n objects filtered by the id column
* @method array findByLocale(string $locale) Return ChildExportI18n objects filtered by the locale column
* @method array findByTitle(string $title) Return ChildExportI18n objects filtered by the title column
* @method array findByDescription(string $description) Return ChildExportI18n objects filtered by the description column
*
*/
abstract class ExportI18nQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ExportI18nQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ExportI18n', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildExportI18nQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildExportI18nQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ExportI18nQuery) {
return $criteria;
}
$query = new \Thelia\Model\ExportI18nQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(array(12, 34), $con);
* </code>
*
* @param array[$id, $locale] $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildExportI18n|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ExportI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ExportI18nTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExportI18n A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `LOCALE`, `TITLE`, `DESCRIPTION` FROM `export_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
$stmt->bindValue(':p1', $key[1], PDO::PARAM_STR);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildExportI18n();
$obj->hydrate($row);
ExportI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExportI18n|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
$this->addUsingAlias(ExportI18nTableMap::ID, $key[0], Criteria::EQUAL);
$this->addUsingAlias(ExportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
return $this;
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
if (empty($keys)) {
return $this->add(null, '1<>1', Criteria::CUSTOM);
}
foreach ($keys as $key) {
$cton0 = $this->getNewCriterion(ExportI18nTableMap::ID, $key[0], Criteria::EQUAL);
$cton1 = $this->getNewCriterion(ExportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
$cton0->addAnd($cton1);
$this->addOr($cton0);
}
return $this;
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @see filterByExport()
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ExportI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ExportI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportI18nTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the locale column
*
* Example usage:
* <code>
* $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue'
* $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%'
* </code>
*
* @param string $locale The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterByLocale($locale = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($locale)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $locale)) {
$locale = str_replace('*', '%', $locale);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportI18nTableMap::LOCALE, $locale, $comparison);
}
/**
* Filter the query on the title column
*
* Example usage:
* <code>
* $query->filterByTitle('fooValue'); // WHERE title = 'fooValue'
* $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%'
* </code>
*
* @param string $title The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterByTitle($title = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($title)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $title)) {
$title = str_replace('*', '%', $title);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportI18nTableMap::TITLE, $title, $comparison);
}
/**
* Filter the query on the description column
*
* Example usage:
* <code>
* $query->filterByDescription('fooValue'); // WHERE description = 'fooValue'
* $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%'
* </code>
*
* @param string $description The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterByDescription($description = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($description)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $description)) {
$description = str_replace('*', '%', $description);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportI18nTableMap::DESCRIPTION, $description, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\Export object
*
* @param \Thelia\Model\Export|ObjectCollection $export The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function filterByExport($export, $comparison = null)
{
if ($export instanceof \Thelia\Model\Export) {
return $this
->addUsingAlias(ExportI18nTableMap::ID, $export->getId(), $comparison);
} elseif ($export instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(ExportI18nTableMap::ID, $export->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByExport() only accepts arguments of type \Thelia\Model\Export or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Export relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function joinExport($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Export');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Export');
}
return $this;
}
/**
* Use the Export relation Export object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ExportQuery A secondary query class using the current class as primary query
*/
public function useExportQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinExport($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Export', '\Thelia\Model\ExportQuery');
}
/**
* Exclude object from result
*
* @param ChildExportI18n $exportI18n Object to remove from the list of results
*
* @return ChildExportI18nQuery The current query, for fluid interface
*/
public function prune($exportI18n = null)
{
if ($exportI18n) {
$this->addCond('pruneCond0', $this->getAliasedColName(ExportI18nTableMap::ID), $exportI18n->getId(), Criteria::NOT_EQUAL);
$this->addCond('pruneCond1', $this->getAliasedColName(ExportI18nTableMap::LOCALE), $exportI18n->getLocale(), Criteria::NOT_EQUAL);
$this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
}
return $this;
}
/**
* Deletes all rows from the export_i18n table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ExportI18nTableMap::clearInstancePool();
ExportI18nTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildExportI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildExportI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportI18nTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ExportI18nTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ExportI18nTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ExportI18nTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
} // ExportI18nQuery

View File

@@ -0,0 +1,879 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\Export as ChildExport;
use Thelia\Model\ExportI18nQuery as ChildExportI18nQuery;
use Thelia\Model\ExportQuery as ChildExportQuery;
use Thelia\Model\Map\ExportTableMap;
/**
* Base class that represents a query for the 'export' table.
*
*
*
* @method ChildExportQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildExportQuery orderByRef($order = Criteria::ASC) Order by the ref column
* @method ChildExportQuery orderByExportCategoryId($order = Criteria::ASC) Order by the export_category_id column
* @method ChildExportQuery orderByPosition($order = Criteria::ASC) Order by the position column
* @method ChildExportQuery orderByHandleClass($order = Criteria::ASC) Order by the handle_class column
* @method ChildExportQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildExportQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
* @method ChildExportQuery groupById() Group by the id column
* @method ChildExportQuery groupByRef() Group by the ref column
* @method ChildExportQuery groupByExportCategoryId() Group by the export_category_id column
* @method ChildExportQuery groupByPosition() Group by the position column
* @method ChildExportQuery groupByHandleClass() Group by the handle_class column
* @method ChildExportQuery groupByCreatedAt() Group by the created_at column
* @method ChildExportQuery groupByUpdatedAt() Group by the updated_at column
*
* @method ChildExportQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildExportQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildExportQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildExportQuery leftJoinExportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ExportCategory relation
* @method ChildExportQuery rightJoinExportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ExportCategory relation
* @method ChildExportQuery innerJoinExportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ExportCategory relation
*
* @method ChildExportQuery leftJoinExportI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ExportI18n relation
* @method ChildExportQuery rightJoinExportI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ExportI18n relation
* @method ChildExportQuery innerJoinExportI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ExportI18n relation
*
* @method ChildExport findOne(ConnectionInterface $con = null) Return the first ChildExport matching the query
* @method ChildExport findOneOrCreate(ConnectionInterface $con = null) Return the first ChildExport matching the query, or a new ChildExport object populated from the query conditions when no match is found
*
* @method ChildExport findOneById(int $id) Return the first ChildExport filtered by the id column
* @method ChildExport findOneByRef(string $ref) Return the first ChildExport filtered by the ref column
* @method ChildExport findOneByExportCategoryId(int $export_category_id) Return the first ChildExport filtered by the export_category_id column
* @method ChildExport findOneByPosition(int $position) Return the first ChildExport filtered by the position column
* @method ChildExport findOneByHandleClass(string $handle_class) Return the first ChildExport filtered by the handle_class column
* @method ChildExport findOneByCreatedAt(string $created_at) Return the first ChildExport filtered by the created_at column
* @method ChildExport findOneByUpdatedAt(string $updated_at) Return the first ChildExport filtered by the updated_at column
*
* @method array findById(int $id) Return ChildExport objects filtered by the id column
* @method array findByRef(string $ref) Return ChildExport objects filtered by the ref column
* @method array findByExportCategoryId(int $export_category_id) Return ChildExport objects filtered by the export_category_id column
* @method array findByPosition(int $position) Return ChildExport objects filtered by the position column
* @method array findByHandleClass(string $handle_class) Return ChildExport objects filtered by the handle_class column
* @method array findByCreatedAt(string $created_at) Return ChildExport objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildExport objects filtered by the updated_at column
*
*/
abstract class ExportQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ExportQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\Export', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildExportQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildExportQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ExportQuery) {
return $criteria;
}
$query = new \Thelia\Model\ExportQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(12, $con);
* </code>
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildExport|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ExportTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ExportTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExport A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `REF`, `EXPORT_CATEGORY_ID`, `POSITION`, `HANDLE_CLASS`, `CREATED_AT`, `UPDATED_AT` FROM `export` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildExport();
$obj->hydrate($row);
ExportTableMap::addInstanceToPool($obj, (string) $key);
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildExport|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(12, 56, 832), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
return $this->addUsingAlias(ExportTableMap::ID, $key, Criteria::EQUAL);
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
return $this->addUsingAlias(ExportTableMap::ID, $keys, Criteria::IN);
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ExportTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ExportTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the ref column
*
* Example usage:
* <code>
* $query->filterByRef('fooValue'); // WHERE ref = 'fooValue'
* $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%'
* </code>
*
* @param string $ref The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByRef($ref = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($ref)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $ref)) {
$ref = str_replace('*', '%', $ref);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportTableMap::REF, $ref, $comparison);
}
/**
* Filter the query on the export_category_id column
*
* Example usage:
* <code>
* $query->filterByExportCategoryId(1234); // WHERE export_category_id = 1234
* $query->filterByExportCategoryId(array(12, 34)); // WHERE export_category_id IN (12, 34)
* $query->filterByExportCategoryId(array('min' => 12)); // WHERE export_category_id > 12
* </code>
*
* @see filterByExportCategory()
*
* @param mixed $exportCategoryId The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByExportCategoryId($exportCategoryId = null, $comparison = null)
{
if (is_array($exportCategoryId)) {
$useMinMax = false;
if (isset($exportCategoryId['min'])) {
$this->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategoryId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($exportCategoryId['max'])) {
$this->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategoryId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategoryId, $comparison);
}
/**
* Filter the query on the position column
*
* Example usage:
* <code>
* $query->filterByPosition(1234); // WHERE position = 1234
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
* </code>
*
* @param mixed $position The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByPosition($position = null, $comparison = null)
{
if (is_array($position)) {
$useMinMax = false;
if (isset($position['min'])) {
$this->addUsingAlias(ExportTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($position['max'])) {
$this->addUsingAlias(ExportTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportTableMap::POSITION, $position, $comparison);
}
/**
* Filter the query on the handle_class column
*
* Example usage:
* <code>
* $query->filterByHandleClass('fooValue'); // WHERE handle_class = 'fooValue'
* $query->filterByHandleClass('%fooValue%'); // WHERE handle_class LIKE '%fooValue%'
* </code>
*
* @param string $handleClass The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByHandleClass($handleClass = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($handleClass)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $handleClass)) {
$handleClass = str_replace('*', '%', $handleClass);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ExportTableMap::HANDLE_CLASS, $handleClass, $comparison);
}
/**
* Filter the query on the created_at column
*
* Example usage:
* <code>
* $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13'
* </code>
*
* @param mixed $createdAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByCreatedAt($createdAt = null, $comparison = null)
{
if (is_array($createdAt)) {
$useMinMax = false;
if (isset($createdAt['min'])) {
$this->addUsingAlias(ExportTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createdAt['max'])) {
$this->addUsingAlias(ExportTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportTableMap::CREATED_AT, $createdAt, $comparison);
}
/**
* Filter the query on the updated_at column
*
* Example usage:
* <code>
* $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13'
* </code>
*
* @param mixed $updatedAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByUpdatedAt($updatedAt = null, $comparison = null)
{
if (is_array($updatedAt)) {
$useMinMax = false;
if (isset($updatedAt['min'])) {
$this->addUsingAlias(ExportTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updatedAt['max'])) {
$this->addUsingAlias(ExportTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ExportTableMap::UPDATED_AT, $updatedAt, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\ExportCategory object
*
* @param \Thelia\Model\ExportCategory|ObjectCollection $exportCategory The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByExportCategory($exportCategory, $comparison = null)
{
if ($exportCategory instanceof \Thelia\Model\ExportCategory) {
return $this
->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategory->getId(), $comparison);
} elseif ($exportCategory instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(ExportTableMap::EXPORT_CATEGORY_ID, $exportCategory->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByExportCategory() only accepts arguments of type \Thelia\Model\ExportCategory or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ExportCategory relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function joinExportCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ExportCategory');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ExportCategory');
}
return $this;
}
/**
* Use the ExportCategory relation ExportCategory object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ExportCategoryQuery A secondary query class using the current class as primary query
*/
public function useExportCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinExportCategory($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ExportCategory', '\Thelia\Model\ExportCategoryQuery');
}
/**
* Filter the query by a related \Thelia\Model\ExportI18n object
*
* @param \Thelia\Model\ExportI18n|ObjectCollection $exportI18n the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function filterByExportI18n($exportI18n, $comparison = null)
{
if ($exportI18n instanceof \Thelia\Model\ExportI18n) {
return $this
->addUsingAlias(ExportTableMap::ID, $exportI18n->getId(), $comparison);
} elseif ($exportI18n instanceof ObjectCollection) {
return $this
->useExportI18nQuery()
->filterByPrimaryKeys($exportI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByExportI18n() only accepts arguments of type \Thelia\Model\ExportI18n or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ExportI18n relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function joinExportI18n($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ExportI18n');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ExportI18n');
}
return $this;
}
/**
* Use the ExportI18n relation ExportI18n object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ExportI18nQuery A secondary query class using the current class as primary query
*/
public function useExportI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinExportI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ExportI18n', '\Thelia\Model\ExportI18nQuery');
}
/**
* Exclude object from result
*
* @param ChildExport $export Object to remove from the list of results
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function prune($export = null)
{
if ($export) {
$this->addUsingAlias(ExportTableMap::ID, $export->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
/**
* Deletes all rows from the export table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ExportTableMap::clearInstancePool();
ExportTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildExport or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildExport object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ExportTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ExportTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ExportTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ExportTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
// i18n behavior
/**
* Adds a JOIN clause to the query using the i18n relation
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$relationName = $relationAlias ? $relationAlias : 'ExportI18n';
return $this
->joinExportI18n($relationAlias, $joinType)
->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale);
}
/**
* Adds a JOIN clause to the query and hydrates the related I18n object.
* Shortcut for $c->joinI18n($locale)->with()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN)
{
$this
->joinI18n($locale, null, $joinType)
->with('ExportI18n');
$this->with['ExportI18n']->setIsWithOneToMany(false);
return $this;
}
/**
* Use the I18n relation query object
*
* @see useQuery()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildExportI18nQuery A secondary query class using the current class as primary query
*/
public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinI18n($locale, $relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ExportI18n', '\Thelia\Model\ExportI18nQuery');
}
// timestampable behavior
/**
* Filter by the latest updated
*
* @param int $nbDays Maximum age of the latest update in days
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function recentlyUpdated($nbDays = 7)
{
return $this->addUsingAlias(ExportTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Filter by the latest created
*
* @param int $nbDays Maximum age of in days
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function recentlyCreated($nbDays = 7)
{
return $this->addUsingAlias(ExportTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Order by update date desc
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function lastUpdatedFirst()
{
return $this->addDescendingOrderByColumn(ExportTableMap::UPDATED_AT);
}
/**
* Order by update date asc
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function firstUpdatedFirst()
{
return $this->addAscendingOrderByColumn(ExportTableMap::UPDATED_AT);
}
/**
* Order by create date desc
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function lastCreatedFirst()
{
return $this->addDescendingOrderByColumn(ExportTableMap::CREATED_AT);
}
/**
* Order by create date asc
*
* @return ChildExportQuery The current query, for fluid interface
*/
public function firstCreatedFirst()
{
return $this->addAscendingOrderByColumn(ExportTableMap::CREATED_AT);
}
} // ExportQuery

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,508 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\ImportCategoryI18n as ChildImportCategoryI18n;
use Thelia\Model\ImportCategoryI18nQuery as ChildImportCategoryI18nQuery;
use Thelia\Model\Map\ImportCategoryI18nTableMap;
/**
* Base class that represents a query for the 'import_category_i18n' table.
*
*
*
* @method ChildImportCategoryI18nQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildImportCategoryI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column
* @method ChildImportCategoryI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column
*
* @method ChildImportCategoryI18nQuery groupById() Group by the id column
* @method ChildImportCategoryI18nQuery groupByLocale() Group by the locale column
* @method ChildImportCategoryI18nQuery groupByTitle() Group by the title column
*
* @method ChildImportCategoryI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildImportCategoryI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildImportCategoryI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildImportCategoryI18nQuery leftJoinImportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportCategory relation
* @method ChildImportCategoryI18nQuery rightJoinImportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportCategory relation
* @method ChildImportCategoryI18nQuery innerJoinImportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportCategory relation
*
* @method ChildImportCategoryI18n findOne(ConnectionInterface $con = null) Return the first ChildImportCategoryI18n matching the query
* @method ChildImportCategoryI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportCategoryI18n matching the query, or a new ChildImportCategoryI18n object populated from the query conditions when no match is found
*
* @method ChildImportCategoryI18n findOneById(int $id) Return the first ChildImportCategoryI18n filtered by the id column
* @method ChildImportCategoryI18n findOneByLocale(string $locale) Return the first ChildImportCategoryI18n filtered by the locale column
* @method ChildImportCategoryI18n findOneByTitle(string $title) Return the first ChildImportCategoryI18n filtered by the title column
*
* @method array findById(int $id) Return ChildImportCategoryI18n objects filtered by the id column
* @method array findByLocale(string $locale) Return ChildImportCategoryI18n objects filtered by the locale column
* @method array findByTitle(string $title) Return ChildImportCategoryI18n objects filtered by the title column
*
*/
abstract class ImportCategoryI18nQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ImportCategoryI18nQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportCategoryI18n', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildImportCategoryI18nQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildImportCategoryI18nQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ImportCategoryI18nQuery) {
return $criteria;
}
$query = new \Thelia\Model\ImportCategoryI18nQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(array(12, 34), $con);
* </code>
*
* @param array[$id, $locale] $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildImportCategoryI18n|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ImportCategoryI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ImportCategoryI18nTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImportCategoryI18n A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `LOCALE`, `TITLE` FROM `import_category_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
$stmt->bindValue(':p1', $key[1], PDO::PARAM_STR);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildImportCategoryI18n();
$obj->hydrate($row);
ImportCategoryI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImportCategoryI18n|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
$this->addUsingAlias(ImportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL);
$this->addUsingAlias(ImportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
return $this;
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
if (empty($keys)) {
return $this->add(null, '1<>1', Criteria::CUSTOM);
}
foreach ($keys as $key) {
$cton0 = $this->getNewCriterion(ImportCategoryI18nTableMap::ID, $key[0], Criteria::EQUAL);
$cton1 = $this->getNewCriterion(ImportCategoryI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
$cton0->addAnd($cton1);
$this->addOr($cton0);
}
return $this;
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @see filterByImportCategory()
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ImportCategoryI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ImportCategoryI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportCategoryI18nTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the locale column
*
* Example usage:
* <code>
* $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue'
* $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%'
* </code>
*
* @param string $locale The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByLocale($locale = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($locale)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $locale)) {
$locale = str_replace('*', '%', $locale);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportCategoryI18nTableMap::LOCALE, $locale, $comparison);
}
/**
* Filter the query on the title column
*
* Example usage:
* <code>
* $query->filterByTitle('fooValue'); // WHERE title = 'fooValue'
* $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%'
* </code>
*
* @param string $title The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByTitle($title = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($title)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $title)) {
$title = str_replace('*', '%', $title);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportCategoryI18nTableMap::TITLE, $title, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\ImportCategory object
*
* @param \Thelia\Model\ImportCategory|ObjectCollection $importCategory The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function filterByImportCategory($importCategory, $comparison = null)
{
if ($importCategory instanceof \Thelia\Model\ImportCategory) {
return $this
->addUsingAlias(ImportCategoryI18nTableMap::ID, $importCategory->getId(), $comparison);
} elseif ($importCategory instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(ImportCategoryI18nTableMap::ID, $importCategory->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByImportCategory() only accepts arguments of type \Thelia\Model\ImportCategory or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ImportCategory relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function joinImportCategory($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ImportCategory');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ImportCategory');
}
return $this;
}
/**
* Use the ImportCategory relation ImportCategory object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ImportCategoryQuery A secondary query class using the current class as primary query
*/
public function useImportCategoryQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinImportCategory($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ImportCategory', '\Thelia\Model\ImportCategoryQuery');
}
/**
* Exclude object from result
*
* @param ChildImportCategoryI18n $importCategoryI18n Object to remove from the list of results
*
* @return ChildImportCategoryI18nQuery The current query, for fluid interface
*/
public function prune($importCategoryI18n = null)
{
if ($importCategoryI18n) {
$this->addCond('pruneCond0', $this->getAliasedColName(ImportCategoryI18nTableMap::ID), $importCategoryI18n->getId(), Criteria::NOT_EQUAL);
$this->addCond('pruneCond1', $this->getAliasedColName(ImportCategoryI18nTableMap::LOCALE), $importCategoryI18n->getLocale(), Criteria::NOT_EQUAL);
$this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
}
return $this;
}
/**
* Deletes all rows from the import_category_i18n table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ImportCategoryI18nTableMap::clearInstancePool();
ImportCategoryI18nTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildImportCategoryI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildImportCategoryI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryI18nTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ImportCategoryI18nTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ImportCategoryI18nTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ImportCategoryI18nTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
} // ImportCategoryI18nQuery

View File

@@ -0,0 +1,797 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\ImportCategory as ChildImportCategory;
use Thelia\Model\ImportCategoryI18nQuery as ChildImportCategoryI18nQuery;
use Thelia\Model\ImportCategoryQuery as ChildImportCategoryQuery;
use Thelia\Model\Map\ImportCategoryTableMap;
/**
* Base class that represents a query for the 'import_category' table.
*
*
*
* @method ChildImportCategoryQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildImportCategoryQuery orderByRef($order = Criteria::ASC) Order by the ref column
* @method ChildImportCategoryQuery orderByPosition($order = Criteria::ASC) Order by the position column
* @method ChildImportCategoryQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildImportCategoryQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
* @method ChildImportCategoryQuery groupById() Group by the id column
* @method ChildImportCategoryQuery groupByRef() Group by the ref column
* @method ChildImportCategoryQuery groupByPosition() Group by the position column
* @method ChildImportCategoryQuery groupByCreatedAt() Group by the created_at column
* @method ChildImportCategoryQuery groupByUpdatedAt() Group by the updated_at column
*
* @method ChildImportCategoryQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildImportCategoryQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildImportCategoryQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildImportCategoryQuery leftJoinImport($relationAlias = null) Adds a LEFT JOIN clause to the query using the Import relation
* @method ChildImportCategoryQuery rightJoinImport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Import relation
* @method ChildImportCategoryQuery innerJoinImport($relationAlias = null) Adds a INNER JOIN clause to the query using the Import relation
*
* @method ChildImportCategoryQuery leftJoinImportCategoryI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportCategoryI18n relation
* @method ChildImportCategoryQuery rightJoinImportCategoryI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportCategoryI18n relation
* @method ChildImportCategoryQuery innerJoinImportCategoryI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportCategoryI18n relation
*
* @method ChildImportCategory findOne(ConnectionInterface $con = null) Return the first ChildImportCategory matching the query
* @method ChildImportCategory findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportCategory matching the query, or a new ChildImportCategory object populated from the query conditions when no match is found
*
* @method ChildImportCategory findOneById(int $id) Return the first ChildImportCategory filtered by the id column
* @method ChildImportCategory findOneByRef(string $ref) Return the first ChildImportCategory filtered by the ref column
* @method ChildImportCategory findOneByPosition(int $position) Return the first ChildImportCategory filtered by the position column
* @method ChildImportCategory findOneByCreatedAt(string $created_at) Return the first ChildImportCategory filtered by the created_at column
* @method ChildImportCategory findOneByUpdatedAt(string $updated_at) Return the first ChildImportCategory filtered by the updated_at column
*
* @method array findById(int $id) Return ChildImportCategory objects filtered by the id column
* @method array findByRef(string $ref) Return ChildImportCategory objects filtered by the ref column
* @method array findByPosition(int $position) Return ChildImportCategory objects filtered by the position column
* @method array findByCreatedAt(string $created_at) Return ChildImportCategory objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildImportCategory objects filtered by the updated_at column
*
*/
abstract class ImportCategoryQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ImportCategoryQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportCategory', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildImportCategoryQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildImportCategoryQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ImportCategoryQuery) {
return $criteria;
}
$query = new \Thelia\Model\ImportCategoryQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(12, $con);
* </code>
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildImportCategory|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ImportCategoryTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ImportCategoryTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImportCategory A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `REF`, `POSITION`, `CREATED_AT`, `UPDATED_AT` FROM `import_category` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildImportCategory();
$obj->hydrate($row);
ImportCategoryTableMap::addInstanceToPool($obj, (string) $key);
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImportCategory|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(12, 56, 832), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
return $this->addUsingAlias(ImportCategoryTableMap::ID, $key, Criteria::EQUAL);
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
return $this->addUsingAlias(ImportCategoryTableMap::ID, $keys, Criteria::IN);
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ImportCategoryTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ImportCategoryTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportCategoryTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the ref column
*
* Example usage:
* <code>
* $query->filterByRef('fooValue'); // WHERE ref = 'fooValue'
* $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%'
* </code>
*
* @param string $ref The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByRef($ref = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($ref)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $ref)) {
$ref = str_replace('*', '%', $ref);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportCategoryTableMap::REF, $ref, $comparison);
}
/**
* Filter the query on the position column
*
* Example usage:
* <code>
* $query->filterByPosition(1234); // WHERE position = 1234
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
* </code>
*
* @param mixed $position The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByPosition($position = null, $comparison = null)
{
if (is_array($position)) {
$useMinMax = false;
if (isset($position['min'])) {
$this->addUsingAlias(ImportCategoryTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($position['max'])) {
$this->addUsingAlias(ImportCategoryTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportCategoryTableMap::POSITION, $position, $comparison);
}
/**
* Filter the query on the created_at column
*
* Example usage:
* <code>
* $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13'
* </code>
*
* @param mixed $createdAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByCreatedAt($createdAt = null, $comparison = null)
{
if (is_array($createdAt)) {
$useMinMax = false;
if (isset($createdAt['min'])) {
$this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createdAt['max'])) {
$this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, $createdAt, $comparison);
}
/**
* Filter the query on the updated_at column
*
* Example usage:
* <code>
* $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13'
* </code>
*
* @param mixed $updatedAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByUpdatedAt($updatedAt = null, $comparison = null)
{
if (is_array($updatedAt)) {
$useMinMax = false;
if (isset($updatedAt['min'])) {
$this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updatedAt['max'])) {
$this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, $updatedAt, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\Import object
*
* @param \Thelia\Model\Import|ObjectCollection $import the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByImport($import, $comparison = null)
{
if ($import instanceof \Thelia\Model\Import) {
return $this
->addUsingAlias(ImportCategoryTableMap::ID, $import->getImportCategoryId(), $comparison);
} elseif ($import instanceof ObjectCollection) {
return $this
->useImportQuery()
->filterByPrimaryKeys($import->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByImport() only accepts arguments of type \Thelia\Model\Import or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Import relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function joinImport($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Import');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Import');
}
return $this;
}
/**
* Use the Import relation Import object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ImportQuery A secondary query class using the current class as primary query
*/
public function useImportQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinImport($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Import', '\Thelia\Model\ImportQuery');
}
/**
* Filter the query by a related \Thelia\Model\ImportCategoryI18n object
*
* @param \Thelia\Model\ImportCategoryI18n|ObjectCollection $importCategoryI18n the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function filterByImportCategoryI18n($importCategoryI18n, $comparison = null)
{
if ($importCategoryI18n instanceof \Thelia\Model\ImportCategoryI18n) {
return $this
->addUsingAlias(ImportCategoryTableMap::ID, $importCategoryI18n->getId(), $comparison);
} elseif ($importCategoryI18n instanceof ObjectCollection) {
return $this
->useImportCategoryI18nQuery()
->filterByPrimaryKeys($importCategoryI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByImportCategoryI18n() only accepts arguments of type \Thelia\Model\ImportCategoryI18n or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ImportCategoryI18n relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function joinImportCategoryI18n($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ImportCategoryI18n');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ImportCategoryI18n');
}
return $this;
}
/**
* Use the ImportCategoryI18n relation ImportCategoryI18n object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ImportCategoryI18nQuery A secondary query class using the current class as primary query
*/
public function useImportCategoryI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinImportCategoryI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ImportCategoryI18n', '\Thelia\Model\ImportCategoryI18nQuery');
}
/**
* Exclude object from result
*
* @param ChildImportCategory $importCategory Object to remove from the list of results
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function prune($importCategory = null)
{
if ($importCategory) {
$this->addUsingAlias(ImportCategoryTableMap::ID, $importCategory->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
/**
* Deletes all rows from the import_category table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ImportCategoryTableMap::clearInstancePool();
ImportCategoryTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildImportCategory or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildImportCategory object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportCategoryTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ImportCategoryTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ImportCategoryTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ImportCategoryTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
// i18n behavior
/**
* Adds a JOIN clause to the query using the i18n relation
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$relationName = $relationAlias ? $relationAlias : 'ImportCategoryI18n';
return $this
->joinImportCategoryI18n($relationAlias, $joinType)
->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale);
}
/**
* Adds a JOIN clause to the query and hydrates the related I18n object.
* Shortcut for $c->joinI18n($locale)->with()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN)
{
$this
->joinI18n($locale, null, $joinType)
->with('ImportCategoryI18n');
$this->with['ImportCategoryI18n']->setIsWithOneToMany(false);
return $this;
}
/**
* Use the I18n relation query object
*
* @see useQuery()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildImportCategoryI18nQuery A secondary query class using the current class as primary query
*/
public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinI18n($locale, $relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ImportCategoryI18n', '\Thelia\Model\ImportCategoryI18nQuery');
}
// timestampable behavior
/**
* Filter by the latest updated
*
* @param int $nbDays Maximum age of the latest update in days
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function recentlyUpdated($nbDays = 7)
{
return $this->addUsingAlias(ImportCategoryTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Filter by the latest created
*
* @param int $nbDays Maximum age of in days
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function recentlyCreated($nbDays = 7)
{
return $this->addUsingAlias(ImportCategoryTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Order by update date desc
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function lastUpdatedFirst()
{
return $this->addDescendingOrderByColumn(ImportCategoryTableMap::UPDATED_AT);
}
/**
* Order by update date asc
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function firstUpdatedFirst()
{
return $this->addAscendingOrderByColumn(ImportCategoryTableMap::UPDATED_AT);
}
/**
* Order by create date desc
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function lastCreatedFirst()
{
return $this->addDescendingOrderByColumn(ImportCategoryTableMap::CREATED_AT);
}
/**
* Order by create date asc
*
* @return ChildImportCategoryQuery The current query, for fluid interface
*/
public function firstCreatedFirst()
{
return $this->addAscendingOrderByColumn(ImportCategoryTableMap::CREATED_AT);
}
} // ImportCategoryQuery

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,541 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\ImportI18n as ChildImportI18n;
use Thelia\Model\ImportI18nQuery as ChildImportI18nQuery;
use Thelia\Model\Map\ImportI18nTableMap;
/**
* Base class that represents a query for the 'import_i18n' table.
*
*
*
* @method ChildImportI18nQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildImportI18nQuery orderByLocale($order = Criteria::ASC) Order by the locale column
* @method ChildImportI18nQuery orderByTitle($order = Criteria::ASC) Order by the title column
* @method ChildImportI18nQuery orderByDescription($order = Criteria::ASC) Order by the description column
*
* @method ChildImportI18nQuery groupById() Group by the id column
* @method ChildImportI18nQuery groupByLocale() Group by the locale column
* @method ChildImportI18nQuery groupByTitle() Group by the title column
* @method ChildImportI18nQuery groupByDescription() Group by the description column
*
* @method ChildImportI18nQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildImportI18nQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildImportI18nQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildImportI18nQuery leftJoinImport($relationAlias = null) Adds a LEFT JOIN clause to the query using the Import relation
* @method ChildImportI18nQuery rightJoinImport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Import relation
* @method ChildImportI18nQuery innerJoinImport($relationAlias = null) Adds a INNER JOIN clause to the query using the Import relation
*
* @method ChildImportI18n findOne(ConnectionInterface $con = null) Return the first ChildImportI18n matching the query
* @method ChildImportI18n findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImportI18n matching the query, or a new ChildImportI18n object populated from the query conditions when no match is found
*
* @method ChildImportI18n findOneById(int $id) Return the first ChildImportI18n filtered by the id column
* @method ChildImportI18n findOneByLocale(string $locale) Return the first ChildImportI18n filtered by the locale column
* @method ChildImportI18n findOneByTitle(string $title) Return the first ChildImportI18n filtered by the title column
* @method ChildImportI18n findOneByDescription(string $description) Return the first ChildImportI18n filtered by the description column
*
* @method array findById(int $id) Return ChildImportI18n objects filtered by the id column
* @method array findByLocale(string $locale) Return ChildImportI18n objects filtered by the locale column
* @method array findByTitle(string $title) Return ChildImportI18n objects filtered by the title column
* @method array findByDescription(string $description) Return ChildImportI18n objects filtered by the description column
*
*/
abstract class ImportI18nQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ImportI18nQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\ImportI18n', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildImportI18nQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildImportI18nQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ImportI18nQuery) {
return $criteria;
}
$query = new \Thelia\Model\ImportI18nQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(array(12, 34), $con);
* </code>
*
* @param array[$id, $locale] $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildImportI18n|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ImportI18nTableMap::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ImportI18nTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImportI18n A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `LOCALE`, `TITLE`, `DESCRIPTION` FROM `import_i18n` WHERE `ID` = :p0 AND `LOCALE` = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
$stmt->bindValue(':p1', $key[1], PDO::PARAM_STR);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildImportI18n();
$obj->hydrate($row);
ImportI18nTableMap::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImportI18n|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
$this->addUsingAlias(ImportI18nTableMap::ID, $key[0], Criteria::EQUAL);
$this->addUsingAlias(ImportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
return $this;
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
if (empty($keys)) {
return $this->add(null, '1<>1', Criteria::CUSTOM);
}
foreach ($keys as $key) {
$cton0 = $this->getNewCriterion(ImportI18nTableMap::ID, $key[0], Criteria::EQUAL);
$cton1 = $this->getNewCriterion(ImportI18nTableMap::LOCALE, $key[1], Criteria::EQUAL);
$cton0->addAnd($cton1);
$this->addOr($cton0);
}
return $this;
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @see filterByImport()
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ImportI18nTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ImportI18nTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportI18nTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the locale column
*
* Example usage:
* <code>
* $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue'
* $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%'
* </code>
*
* @param string $locale The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterByLocale($locale = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($locale)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $locale)) {
$locale = str_replace('*', '%', $locale);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportI18nTableMap::LOCALE, $locale, $comparison);
}
/**
* Filter the query on the title column
*
* Example usage:
* <code>
* $query->filterByTitle('fooValue'); // WHERE title = 'fooValue'
* $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%'
* </code>
*
* @param string $title The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterByTitle($title = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($title)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $title)) {
$title = str_replace('*', '%', $title);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportI18nTableMap::TITLE, $title, $comparison);
}
/**
* Filter the query on the description column
*
* Example usage:
* <code>
* $query->filterByDescription('fooValue'); // WHERE description = 'fooValue'
* $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%'
* </code>
*
* @param string $description The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterByDescription($description = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($description)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $description)) {
$description = str_replace('*', '%', $description);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportI18nTableMap::DESCRIPTION, $description, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\Import object
*
* @param \Thelia\Model\Import|ObjectCollection $import The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function filterByImport($import, $comparison = null)
{
if ($import instanceof \Thelia\Model\Import) {
return $this
->addUsingAlias(ImportI18nTableMap::ID, $import->getId(), $comparison);
} elseif ($import instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(ImportI18nTableMap::ID, $import->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByImport() only accepts arguments of type \Thelia\Model\Import or Collection');
}
}
/**
* Adds a JOIN clause to the query using the Import relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function joinImport($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('Import');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'Import');
}
return $this;
}
/**
* Use the Import relation Import object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ImportQuery A secondary query class using the current class as primary query
*/
public function useImportQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinImport($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'Import', '\Thelia\Model\ImportQuery');
}
/**
* Exclude object from result
*
* @param ChildImportI18n $importI18n Object to remove from the list of results
*
* @return ChildImportI18nQuery The current query, for fluid interface
*/
public function prune($importI18n = null)
{
if ($importI18n) {
$this->addCond('pruneCond0', $this->getAliasedColName(ImportI18nTableMap::ID), $importI18n->getId(), Criteria::NOT_EQUAL);
$this->addCond('pruneCond1', $this->getAliasedColName(ImportI18nTableMap::LOCALE), $importI18n->getLocale(), Criteria::NOT_EQUAL);
$this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
}
return $this;
}
/**
* Deletes all rows from the import_i18n table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ImportI18nTableMap::clearInstancePool();
ImportI18nTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildImportI18n or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildImportI18n object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportI18nTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ImportI18nTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ImportI18nTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ImportI18nTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
} // ImportI18nQuery

View File

@@ -0,0 +1,879 @@
<?php
namespace Thelia\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveQuery\ModelJoin;
use Propel\Runtime\Collection\Collection;
use Propel\Runtime\Collection\ObjectCollection;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Thelia\Model\Import as ChildImport;
use Thelia\Model\ImportI18nQuery as ChildImportI18nQuery;
use Thelia\Model\ImportQuery as ChildImportQuery;
use Thelia\Model\Map\ImportTableMap;
/**
* Base class that represents a query for the 'import' table.
*
*
*
* @method ChildImportQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildImportQuery orderByRef($order = Criteria::ASC) Order by the ref column
* @method ChildImportQuery orderByImportCategoryId($order = Criteria::ASC) Order by the import_category_id column
* @method ChildImportQuery orderByPosition($order = Criteria::ASC) Order by the position column
* @method ChildImportQuery orderByHandleClass($order = Criteria::ASC) Order by the handle_class column
* @method ChildImportQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildImportQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
* @method ChildImportQuery groupById() Group by the id column
* @method ChildImportQuery groupByRef() Group by the ref column
* @method ChildImportQuery groupByImportCategoryId() Group by the import_category_id column
* @method ChildImportQuery groupByPosition() Group by the position column
* @method ChildImportQuery groupByHandleClass() Group by the handle_class column
* @method ChildImportQuery groupByCreatedAt() Group by the created_at column
* @method ChildImportQuery groupByUpdatedAt() Group by the updated_at column
*
* @method ChildImportQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildImportQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildImportQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildImportQuery leftJoinImportCategory($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportCategory relation
* @method ChildImportQuery rightJoinImportCategory($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportCategory relation
* @method ChildImportQuery innerJoinImportCategory($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportCategory relation
*
* @method ChildImportQuery leftJoinImportI18n($relationAlias = null) Adds a LEFT JOIN clause to the query using the ImportI18n relation
* @method ChildImportQuery rightJoinImportI18n($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ImportI18n relation
* @method ChildImportQuery innerJoinImportI18n($relationAlias = null) Adds a INNER JOIN clause to the query using the ImportI18n relation
*
* @method ChildImport findOne(ConnectionInterface $con = null) Return the first ChildImport matching the query
* @method ChildImport findOneOrCreate(ConnectionInterface $con = null) Return the first ChildImport matching the query, or a new ChildImport object populated from the query conditions when no match is found
*
* @method ChildImport findOneById(int $id) Return the first ChildImport filtered by the id column
* @method ChildImport findOneByRef(string $ref) Return the first ChildImport filtered by the ref column
* @method ChildImport findOneByImportCategoryId(int $import_category_id) Return the first ChildImport filtered by the import_category_id column
* @method ChildImport findOneByPosition(int $position) Return the first ChildImport filtered by the position column
* @method ChildImport findOneByHandleClass(string $handle_class) Return the first ChildImport filtered by the handle_class column
* @method ChildImport findOneByCreatedAt(string $created_at) Return the first ChildImport filtered by the created_at column
* @method ChildImport findOneByUpdatedAt(string $updated_at) Return the first ChildImport filtered by the updated_at column
*
* @method array findById(int $id) Return ChildImport objects filtered by the id column
* @method array findByRef(string $ref) Return ChildImport objects filtered by the ref column
* @method array findByImportCategoryId(int $import_category_id) Return ChildImport objects filtered by the import_category_id column
* @method array findByPosition(int $position) Return ChildImport objects filtered by the position column
* @method array findByHandleClass(string $handle_class) Return ChildImport objects filtered by the handle_class column
* @method array findByCreatedAt(string $created_at) Return ChildImport objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildImport objects filtered by the updated_at column
*
*/
abstract class ImportQuery extends ModelCriteria
{
/**
* Initializes internal state of \Thelia\Model\Base\ImportQuery object.
*
* @param string $dbName The database name
* @param string $modelName The phpName of a model, e.g. 'Book'
* @param string $modelAlias The alias for the model in this query, e.g. 'b'
*/
public function __construct($dbName = 'thelia', $modelName = '\\Thelia\\Model\\Import', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildImportQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildImportQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Thelia\Model\ImportQuery) {
return $criteria;
}
$query = new \Thelia\Model\ImportQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
/**
* Find object by primary key.
* Propel uses the instance pool to skip the database if the object exists.
* Go fast if the query is untouched.
*
* <code>
* $obj = $c->findPk(12, $con);
* </code>
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ChildImport|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = ImportTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(ImportTableMap::DATABASE_NAME);
}
$this->basePreSelect($con);
if ($this->formatter || $this->modelAlias || $this->with || $this->select
|| $this->selectColumns || $this->asColumns || $this->selectModifiers
|| $this->map || $this->having || $this->joins) {
return $this->findPkComplex($key, $con);
} else {
return $this->findPkSimple($key, $con);
}
}
/**
* Find object by primary key using raw SQL to go fast.
* Bypass doSelect() and the object formatter by using generated code.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImport A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT `ID`, `REF`, `IMPORT_CATEGORY_ID`, `POSITION`, `HANDLE_CLASS`, `CREATED_AT`, `UPDATED_AT` FROM `import` WHERE `ID` = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
}
$obj = null;
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
$obj = new ChildImport();
$obj->hydrate($row);
ImportTableMap::addInstanceToPool($obj, (string) $key);
}
$stmt->closeCursor();
return $obj;
}
/**
* Find object by primary key.
*
* @param mixed $key Primary key to use for the query
* @param ConnectionInterface $con A connection object
*
* @return ChildImport|array|mixed the result, formatted by the current formatter
*/
protected function findPkComplex($key, $con)
{
// As the query uses a PK condition, no limit(1) is necessary.
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKey($key)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}
/**
* Find objects by primary key
* <code>
* $objs = $c->findPks(array(12, 56, 832), $con);
* </code>
* @param array $keys Primary keys to use for the query
* @param ConnectionInterface $con an optional connection object
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
public function findPks($keys, $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}
$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria
->filterByPrimaryKeys($keys)
->doSelect($con);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}
/**
* Filter the query by primary key
*
* @param mixed $key Primary key to use for the query
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
return $this->addUsingAlias(ImportTableMap::ID, $key, Criteria::EQUAL);
}
/**
* Filter the query by a list of primary keys
*
* @param array $keys The list of primary key to use for the query
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
return $this->addUsingAlias(ImportTableMap::ID, $keys, Criteria::IN);
}
/**
* Filter the query on the id column
*
* Example usage:
* <code>
* $query->filterById(1234); // WHERE id = 1234
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
* $query->filterById(array('min' => 12)); // WHERE id > 12
* </code>
*
* @param mixed $id The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterById($id = null, $comparison = null)
{
if (is_array($id)) {
$useMinMax = false;
if (isset($id['min'])) {
$this->addUsingAlias(ImportTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(ImportTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the ref column
*
* Example usage:
* <code>
* $query->filterByRef('fooValue'); // WHERE ref = 'fooValue'
* $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%'
* </code>
*
* @param string $ref The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByRef($ref = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($ref)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $ref)) {
$ref = str_replace('*', '%', $ref);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportTableMap::REF, $ref, $comparison);
}
/**
* Filter the query on the import_category_id column
*
* Example usage:
* <code>
* $query->filterByImportCategoryId(1234); // WHERE import_category_id = 1234
* $query->filterByImportCategoryId(array(12, 34)); // WHERE import_category_id IN (12, 34)
* $query->filterByImportCategoryId(array('min' => 12)); // WHERE import_category_id > 12
* </code>
*
* @see filterByImportCategory()
*
* @param mixed $importCategoryId The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByImportCategoryId($importCategoryId = null, $comparison = null)
{
if (is_array($importCategoryId)) {
$useMinMax = false;
if (isset($importCategoryId['min'])) {
$this->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategoryId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($importCategoryId['max'])) {
$this->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategoryId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategoryId, $comparison);
}
/**
* Filter the query on the position column
*
* Example usage:
* <code>
* $query->filterByPosition(1234); // WHERE position = 1234
* $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34)
* $query->filterByPosition(array('min' => 12)); // WHERE position > 12
* </code>
*
* @param mixed $position The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByPosition($position = null, $comparison = null)
{
if (is_array($position)) {
$useMinMax = false;
if (isset($position['min'])) {
$this->addUsingAlias(ImportTableMap::POSITION, $position['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($position['max'])) {
$this->addUsingAlias(ImportTableMap::POSITION, $position['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportTableMap::POSITION, $position, $comparison);
}
/**
* Filter the query on the handle_class column
*
* Example usage:
* <code>
* $query->filterByHandleClass('fooValue'); // WHERE handle_class = 'fooValue'
* $query->filterByHandleClass('%fooValue%'); // WHERE handle_class LIKE '%fooValue%'
* </code>
*
* @param string $handleClass The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByHandleClass($handleClass = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($handleClass)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $handleClass)) {
$handleClass = str_replace('*', '%', $handleClass);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(ImportTableMap::HANDLE_CLASS, $handleClass, $comparison);
}
/**
* Filter the query on the created_at column
*
* Example usage:
* <code>
* $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14'
* $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13'
* </code>
*
* @param mixed $createdAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByCreatedAt($createdAt = null, $comparison = null)
{
if (is_array($createdAt)) {
$useMinMax = false;
if (isset($createdAt['min'])) {
$this->addUsingAlias(ImportTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createdAt['max'])) {
$this->addUsingAlias(ImportTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportTableMap::CREATED_AT, $createdAt, $comparison);
}
/**
* Filter the query on the updated_at column
*
* Example usage:
* <code>
* $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14'
* $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13'
* </code>
*
* @param mixed $updatedAt The value to use as filter.
* Values can be integers (unix timestamps), DateTime objects, or strings.
* Empty strings are treated as NULL.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByUpdatedAt($updatedAt = null, $comparison = null)
{
if (is_array($updatedAt)) {
$useMinMax = false;
if (isset($updatedAt['min'])) {
$this->addUsingAlias(ImportTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updatedAt['max'])) {
$this->addUsingAlias(ImportTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(ImportTableMap::UPDATED_AT, $updatedAt, $comparison);
}
/**
* Filter the query by a related \Thelia\Model\ImportCategory object
*
* @param \Thelia\Model\ImportCategory|ObjectCollection $importCategory The related object(s) to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByImportCategory($importCategory, $comparison = null)
{
if ($importCategory instanceof \Thelia\Model\ImportCategory) {
return $this
->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategory->getId(), $comparison);
} elseif ($importCategory instanceof ObjectCollection) {
if (null === $comparison) {
$comparison = Criteria::IN;
}
return $this
->addUsingAlias(ImportTableMap::IMPORT_CATEGORY_ID, $importCategory->toKeyValue('PrimaryKey', 'Id'), $comparison);
} else {
throw new PropelException('filterByImportCategory() only accepts arguments of type \Thelia\Model\ImportCategory or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ImportCategory relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function joinImportCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ImportCategory');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ImportCategory');
}
return $this;
}
/**
* Use the ImportCategory relation ImportCategory object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ImportCategoryQuery A secondary query class using the current class as primary query
*/
public function useImportCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
{
return $this
->joinImportCategory($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ImportCategory', '\Thelia\Model\ImportCategoryQuery');
}
/**
* Filter the query by a related \Thelia\Model\ImportI18n object
*
* @param \Thelia\Model\ImportI18n|ObjectCollection $importI18n the related object to use as filter
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function filterByImportI18n($importI18n, $comparison = null)
{
if ($importI18n instanceof \Thelia\Model\ImportI18n) {
return $this
->addUsingAlias(ImportTableMap::ID, $importI18n->getId(), $comparison);
} elseif ($importI18n instanceof ObjectCollection) {
return $this
->useImportI18nQuery()
->filterByPrimaryKeys($importI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByImportI18n() only accepts arguments of type \Thelia\Model\ImportI18n or Collection');
}
}
/**
* Adds a JOIN clause to the query using the ImportI18n relation
*
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function joinImportI18n($relationAlias = null, $joinType = 'LEFT JOIN')
{
$tableMap = $this->getTableMap();
$relationMap = $tableMap->getRelation('ImportI18n');
// create a ModelJoin object for this join
$join = new ModelJoin();
$join->setJoinType($joinType);
$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
if ($previousJoin = $this->getPreviousJoin()) {
$join->setPreviousJoin($previousJoin);
}
// add the ModelJoin to the current object
if ($relationAlias) {
$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
$this->addJoinObject($join, $relationAlias);
} else {
$this->addJoinObject($join, 'ImportI18n');
}
return $this;
}
/**
* Use the ImportI18n relation ImportI18n object
*
* @see useQuery()
*
* @param string $relationAlias optional alias for the relation,
* to be used as main alias in the secondary query
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
*
* @return \Thelia\Model\ImportI18nQuery A secondary query class using the current class as primary query
*/
public function useImportI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinImportI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ImportI18n', '\Thelia\Model\ImportI18nQuery');
}
/**
* Exclude object from result
*
* @param ChildImport $import Object to remove from the list of results
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function prune($import = null)
{
if ($import) {
$this->addUsingAlias(ImportTableMap::ID, $import->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
/**
* Deletes all rows from the import table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public function doDeleteAll(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME);
}
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
$affectedRows += parent::doDeleteAll($con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
ImportTableMap::clearInstancePool();
ImportTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildImport or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildImport object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public function delete(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(ImportTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(ImportTableMap::DATABASE_NAME);
$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
ImportTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
ImportTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
// i18n behavior
/**
* Adds a JOIN clause to the query using the i18n relation
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function joinI18n($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
$relationName = $relationAlias ? $relationAlias : 'ImportI18n';
return $this
->joinImportI18n($relationAlias, $joinType)
->addJoinCondition($relationName, $relationName . '.Locale = ?', $locale);
}
/**
* Adds a JOIN clause to the query and hydrates the related I18n object.
* Shortcut for $c->joinI18n($locale)->with()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function joinWithI18n($locale = 'en_US', $joinType = Criteria::LEFT_JOIN)
{
$this
->joinI18n($locale, null, $joinType)
->with('ImportI18n');
$this->with['ImportI18n']->setIsWithOneToMany(false);
return $this;
}
/**
* Use the I18n relation query object
*
* @see useQuery()
*
* @param string $locale Locale to use for the join condition, e.g. 'fr_FR'
* @param string $relationAlias optional alias for the relation
* @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.
*
* @return ChildImportI18nQuery A secondary query class using the current class as primary query
*/
public function useI18nQuery($locale = 'en_US', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)
{
return $this
->joinI18n($locale, $relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'ImportI18n', '\Thelia\Model\ImportI18nQuery');
}
// timestampable behavior
/**
* Filter by the latest updated
*
* @param int $nbDays Maximum age of the latest update in days
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function recentlyUpdated($nbDays = 7)
{
return $this->addUsingAlias(ImportTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Filter by the latest created
*
* @param int $nbDays Maximum age of in days
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function recentlyCreated($nbDays = 7)
{
return $this->addUsingAlias(ImportTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Order by update date desc
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function lastUpdatedFirst()
{
return $this->addDescendingOrderByColumn(ImportTableMap::UPDATED_AT);
}
/**
* Order by update date asc
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function firstUpdatedFirst()
{
return $this->addAscendingOrderByColumn(ImportTableMap::UPDATED_AT);
}
/**
* Order by create date desc
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function lastCreatedFirst()
{
return $this->addDescendingOrderByColumn(ImportTableMap::CREATED_AT);
}
/**
* Order by create date asc
*
* @return ChildImportQuery The current query, for fluid interface
*/
public function firstCreatedFirst()
{
return $this->addAscendingOrderByColumn(ImportTableMap::CREATED_AT);
}
} // ImportQuery

View File

@@ -22,7 +22,7 @@ class Brand extends BaseBrand implements FileModelParentInterface
/**
* {@inheritDoc}
*/
protected function getRewrittenUrlViewName()
public function getRewrittenUrlViewName()
{
return 'brand';
}
@@ -81,7 +81,7 @@ class Brand extends BaseBrand implements FileModelParentInterface
*/
public function postDelete(ConnectionInterface $con = null)
{
$this->markRewritenUrlObsolete();
$this->markRewrittenUrlObsolete();
$this->dispatchEvent(TheliaEvents::AFTER_DELETEBRAND, new BrandEvent($this));
}

View File

@@ -31,7 +31,7 @@ class Category extends BaseCategory implements FileModelParentInterface
/**
* {@inheritDoc}
*/
protected function getRewrittenUrlViewName()
public function getRewrittenUrlViewName()
{
return 'category';
}
@@ -166,7 +166,7 @@ class Category extends BaseCategory implements FileModelParentInterface
*/
public function postDelete(ConnectionInterface $con = null)
{
$this->markRewritenUrlObsolete();
$this->markRewrittenUrlObsolete();
//delete all subcategories
$subCategories = CategoryQuery::findAllChild($this->getId());

View File

@@ -27,7 +27,7 @@ class Content extends BaseContent implements FileModelParentInterface
/**
* {@inheritDoc}
*/
protected function getRewrittenUrlViewName()
public function getRewrittenUrlViewName()
{
return 'content';
}
@@ -170,7 +170,7 @@ class Content extends BaseContent implements FileModelParentInterface
public function postDelete(ConnectionInterface $con = null)
{
$this->markRewritenUrlObsolete();
$this->markRewrittenUrlObsolete();
$this->dispatchEvent(TheliaEvents::AFTER_DELETECONTENT, new ContentEvent($this));
}

View File

@@ -0,0 +1,94 @@
<?php
namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\Export\DocumentsExportInterface;
use Thelia\ImportExport\Export\ExportHandler;
use Thelia\ImportExport\Export\ImagesExportInterface;
use Thelia\Model\Base\Export as BaseExport;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
class Export extends BaseExport
{
use PositionManagementTrait;
use ModelEventDispatcherTrait;
protected static $cache;
/**
* @param ContainerInterface $container
* @return \Thelia\ImportExport\Export\ExportHandler
* @throws \ErrorException
*/
public function getHandleClassInstance(ContainerInterface $container)
{
$class = $this->getHandleClass();
if ($class[0] !== "\\") {
$class = "\\" . $class;
}
if (!class_exists($class)) {
$this->delete();
throw new \ErrorException(
Translator::getInstance()->trans(
"The class \"%class\" doesn't exist",
[
"%class" => $class
]
)
);
}
$instance = new $class($container);
if (!$instance instanceof ExportHandler) {
$this->delete();
throw new \ErrorException(
Translator::getInstance()->trans(
"The class \"%class\" must extend %baseClass",
[
"%class" => $class,
"%baseClass" => "Thelia\\ImportExport\\Export\\ExportHandler",
]
)
);
}
return static::$cache = $instance;
}
public function hasImages(ContainerInterface $container)
{
if (static::$cache === null) {
$this->getHandleClassInstance($container);
}
return static::$cache instanceof ImagesExportInterface;
}
public function hasDocuments(ContainerInterface $container)
{
if (static::$cache === null) {
$this->getHandleClassInstance($container);
}
return static::$cache instanceof DocumentsExportInterface;
}
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
$this->setPosition($this->getNextPosition());
return true;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportCategory as BaseExportCategory;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
class ExportCategory extends BaseExportCategory
{
use PositionManagementTrait;
use ModelEventDispatcherTrait;
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportCategoryI18n as BaseExportCategoryI18n;
class ExportCategoryI18n extends BaseExportCategoryI18n
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportCategoryI18nQuery as BaseExportCategoryI18nQuery;
/**
* Skeleton subclass for performing query and update operations on the 'export_category_i18n' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ExportCategoryI18nQuery extends BaseExportCategoryI18nQuery
{
} // ExportCategoryI18nQuery

View File

@@ -0,0 +1,20 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportCategoryQuery as BaseExportCategoryQuery;
/**
* Skeleton subclass for performing query and update operations on the 'export_category' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ExportCategoryQuery extends BaseExportCategoryQuery
{
} // ExportCategoryQuery

View File

@@ -0,0 +1,10 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportI18n as BaseExportI18n;
class ExportI18n extends BaseExportI18n
{
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportI18nQuery as BaseExportI18nQuery;
/**
* Skeleton subclass for performing query and update operations on the 'export_i18n' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ExportI18nQuery extends BaseExportI18nQuery
{
} // ExportI18nQuery

View File

@@ -0,0 +1,20 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ExportQuery as BaseExportQuery;
/**
* Skeleton subclass for performing query and update operations on the 'export' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ExportQuery extends BaseExportQuery
{
} // ExportQuery

View File

@@ -20,7 +20,7 @@ class Folder extends BaseFolder implements FileModelParentInterface
/**
* {@inheritDoc}
*/
protected function getRewrittenUrlViewName()
public function getRewrittenUrlViewName()
{
return 'folder';
}
@@ -129,7 +129,7 @@ class Folder extends BaseFolder implements FileModelParentInterface
public function postDelete(ConnectionInterface $con = null)
{
$this->markRewritenUrlObsolete();
$this->markRewrittenUrlObsolete();
$this->dispatchEvent(TheliaEvents::AFTER_DELETEFOLDER, new FolderEvent($this));
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Thelia\Model;
use Exception;
use Propel\Runtime\Exception\ClassNotFoundException;
use Propel\Runtime\Propel;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Core\Translation\Translator;
use Thelia\ImportExport\Import\ImportHandler;
use Thelia\Model\Base\Import as BaseImport;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
class Import extends BaseImport
{
use PositionManagementTrait;
use ModelEventDispatcherTrait;
/**
* @param ContainerInterface $container
* @return ImportHandler
* @throws \ErrorException
*/
public function getHandleClassInstance(ContainerInterface $container)
{
$class = $this->getHandleClass();
if (!class_exists($class)) {
$this->delete();
throw new ClassNotFoundException(
Translator::getInstance()->trans(
"The class \"%class\" doesn't exist",
[
"%class" => $class
]
)
);
}
$instance = new $class($container);
if (!$instance instanceof ImportHandler) {
$this->delete();
throw new \ErrorException(
Translator::getInstance()->trans(
"The class \"%class\" must extend %baseClass",
[
"%class" => $class,
"%baseClass" => "Thelia\\ImportExport\\Import\\ImportHandler",
]
)
);
}
return $instance;
}
}

Some files were not shown because too many files have changed in this diff Show More