Merge branch 'master' into template
Conflicts: core/lib/Thelia/Core/Event/TheliaEvents.php core/lib/Thelia/Model/Base/Module.php core/lib/Thelia/Model/Base/ModuleQuery.php core/lib/Thelia/Model/Map/ModuleTableMap.php install/thelia.sql local/config/schema.xml
This commit is contained in:
94
core/lib/Thelia/Core/Event/CachedFileEvent.php
Normal file
94
core/lib/Thelia/Core/Event/CachedFileEvent.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
class CachedFileEvent extends ActionEvent
|
||||
{
|
||||
/**
|
||||
* @var string The complete file name (with path) of the source file
|
||||
*/
|
||||
protected $source_filepath = null;
|
||||
/**
|
||||
* @var string The target subdirectory in the cache
|
||||
*/
|
||||
protected $cache_subdirectory = null;
|
||||
|
||||
/**
|
||||
* @var string The absolute URL of the cached file (in the web space)
|
||||
*/
|
||||
protected $file_url = null;
|
||||
|
||||
/**
|
||||
* @var string The absolute path of the cached file
|
||||
*/
|
||||
protected $cache_filepath = null;
|
||||
|
||||
public function getFileUrl()
|
||||
{
|
||||
return $this->file_url;
|
||||
}
|
||||
|
||||
public function setFileUrl($file_url)
|
||||
{
|
||||
$this->file_url = $file_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCacheFilepath()
|
||||
{
|
||||
return $this->cache_filepath;
|
||||
}
|
||||
|
||||
public function setCacheFilepath($cache_filepath)
|
||||
{
|
||||
$this->cache_filepath = $cache_filepath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSourceFilepath()
|
||||
{
|
||||
return $this->source_filepath;
|
||||
}
|
||||
|
||||
public function setSourceFilepath($source_filepath)
|
||||
{
|
||||
$this->source_filepath = $source_filepath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCacheSubdirectory()
|
||||
{
|
||||
return $this->cache_subdirectory;
|
||||
}
|
||||
|
||||
public function setCacheSubdirectory($cache_subdirectory)
|
||||
{
|
||||
$this->cache_subdirectory = $cache_subdirectory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,7 @@ class CategoryCreateEvent extends CategoryEvent
|
||||
protected $title;
|
||||
protected $parent;
|
||||
protected $locale;
|
||||
|
||||
public function __construct($title, $parent, $locale)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->parent = $parent;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
protected $visible;
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
@@ -71,4 +65,16 @@ class CategoryCreateEvent extends CategoryEvent
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVisible()
|
||||
{
|
||||
return $this->visible;
|
||||
}
|
||||
|
||||
public function setVisible($visible)
|
||||
{
|
||||
$this->visible = $visible;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
28
core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php
Normal file
28
core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
class CategoryToggleVisibilityEvent extends CategoryEvent
|
||||
{
|
||||
}
|
||||
@@ -32,7 +32,6 @@ class CategoryUpdateEvent extends CategoryCreateEvent
|
||||
protected $postscriptum;
|
||||
|
||||
protected $url;
|
||||
protected $visibility;
|
||||
protected $parent;
|
||||
|
||||
public function __construct($category_id)
|
||||
@@ -100,18 +99,6 @@ class CategoryUpdateEvent extends CategoryCreateEvent
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVisibility()
|
||||
{
|
||||
return $this->visibility;
|
||||
}
|
||||
|
||||
public function setVisibility($visibility)
|
||||
{
|
||||
$this->visibility = $visibility;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
|
||||
67
core/lib/Thelia/Core/Event/DocumentEvent.php
Normal file
67
core/lib/Thelia/Core/Event/DocumentEvent.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
class DocumentEvent extends CachedFileEvent
|
||||
{
|
||||
protected $document_path;
|
||||
protected $document_url;
|
||||
|
||||
/**
|
||||
* @return the document file path
|
||||
*/
|
||||
public function getDocumentPath()
|
||||
{
|
||||
return $this->document_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $document_path the document file path
|
||||
*/
|
||||
public function setDocumentPath($document_path)
|
||||
{
|
||||
$this->document_path = $document_path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the document URL
|
||||
*/
|
||||
public function getDocumentUrl()
|
||||
{
|
||||
return $this->document_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $document_url the document URL
|
||||
*/
|
||||
public function setDocumentUrl($document_url)
|
||||
{
|
||||
$this->document_url = $document_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,22 +23,8 @@
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
class ImageEvent extends ActionEvent
|
||||
class ImageEvent extends CachedFileEvent
|
||||
{
|
||||
/**
|
||||
* @var string The complete file name (with path) of the source image
|
||||
*/
|
||||
protected $source_filepath = null;
|
||||
/**
|
||||
* @var string The target subdirectory in the image cache
|
||||
*/
|
||||
protected $cache_subdirectory = null;
|
||||
|
||||
/**
|
||||
* @var string The absolute URL of the cached image (in the web space)
|
||||
*/
|
||||
protected $file_url = null;
|
||||
|
||||
/**
|
||||
* @var string The absolute path of the cached image file
|
||||
*/
|
||||
@@ -121,6 +107,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setCategory($category)
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidth()
|
||||
@@ -131,6 +119,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeight()
|
||||
@@ -141,6 +131,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setHeight($height)
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResizeMode()
|
||||
@@ -151,6 +143,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setResizeMode($resize_mode)
|
||||
{
|
||||
$this->resize_mode = $resize_mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBackgroundColor()
|
||||
@@ -161,6 +155,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setBackgroundColor($background_color)
|
||||
{
|
||||
$this->background_color = $background_color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEffects()
|
||||
@@ -171,6 +167,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setEffects(array $effects)
|
||||
{
|
||||
$this->effects = $effects;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRotation()
|
||||
@@ -181,46 +179,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setRotation($rotation)
|
||||
{
|
||||
$this->rotation = $rotation;
|
||||
}
|
||||
|
||||
public function getFileUrl()
|
||||
{
|
||||
return $this->file_url;
|
||||
}
|
||||
|
||||
public function setFileUrl($file_url)
|
||||
{
|
||||
$this->file_url = $file_url;
|
||||
}
|
||||
|
||||
public function getCacheFilepath()
|
||||
{
|
||||
return $this->cache_filepath;
|
||||
}
|
||||
|
||||
public function setCacheFilepath($cache_filepath)
|
||||
{
|
||||
$this->cache_filepath = $cache_filepath;
|
||||
}
|
||||
|
||||
public function getSourceFilepath()
|
||||
{
|
||||
return $this->source_filepath;
|
||||
}
|
||||
|
||||
public function setSourceFilepath($source_filepath)
|
||||
{
|
||||
$this->source_filepath = $source_filepath;
|
||||
}
|
||||
|
||||
public function getCacheSubdirectory()
|
||||
{
|
||||
return $this->cache_subdirectory;
|
||||
}
|
||||
|
||||
public function setCacheSubdirectory($cache_subdirectory)
|
||||
{
|
||||
$this->cache_subdirectory = $cache_subdirectory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuality()
|
||||
@@ -231,6 +191,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setQuality($quality)
|
||||
{
|
||||
$this->quality = $quality;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOriginalFileUrl()
|
||||
@@ -241,6 +203,8 @@ class ImageEvent extends ActionEvent
|
||||
public function setOriginalFileUrl($original_file_url)
|
||||
{
|
||||
$this->original_file_url = $original_file_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCacheOriginalFilepath()
|
||||
@@ -251,5 +215,7 @@ class ImageEvent extends ActionEvent
|
||||
public function setCacheOriginalFilepath($cache_original_filepath)
|
||||
{
|
||||
$this->cache_original_filepath = $cache_original_filepath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
52
core/lib/Thelia/Core/Event/MailTransporterEvent.php
Normal file
52
core/lib/Thelia/Core/Event/MailTransporterEvent.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event;
|
||||
|
||||
|
||||
/**
|
||||
* Class MailTransporterEvent
|
||||
* @package Thelia\Core\Event
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class MailTransporterEvent extends ActionEvent {
|
||||
/**
|
||||
* @var \Swift_Transport
|
||||
*/
|
||||
protected $transporter;
|
||||
|
||||
public function setMailerTransporter(\Swift_Transport $transporter)
|
||||
{
|
||||
$this->transporter = $transporter;
|
||||
}
|
||||
|
||||
public function getTransporter()
|
||||
{
|
||||
return $this->transporter;
|
||||
}
|
||||
|
||||
public function hasTransporter()
|
||||
{
|
||||
return null !== $this->transporter;
|
||||
}
|
||||
}
|
||||
@@ -145,50 +145,21 @@ final class TheliaEvents
|
||||
|
||||
// -- END ADDRESS MANAGEMENT ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sent once the category creation form has been successfully validated, and before category insertion in the database.
|
||||
*/
|
||||
const BEFORE_CREATECATEGORY = "action.before_createcategory";
|
||||
// -- Categories management -----------------------------------------------
|
||||
|
||||
/**
|
||||
* Create, change or delete a category
|
||||
*/
|
||||
const CATEGORY_CREATE = "action.createCategory";
|
||||
const CATEGORY_UPDATE = "action.updateCategory";
|
||||
const CATEGORY_DELETE = "action.deleteCategory";
|
||||
|
||||
/**
|
||||
* Toggle category visibility
|
||||
*/
|
||||
const CATEGORY_CREATE = "action.createCategory";
|
||||
const CATEGORY_UPDATE = "action.updateCategory";
|
||||
const CATEGORY_DELETE = "action.deleteCategory";
|
||||
const CATEGORY_TOGGLE_VISIBILITY = "action.toggleCategoryVisibility";
|
||||
const CATEGORY_UPDATE_POSITION = "action.updateCategoryPosition";
|
||||
|
||||
/**
|
||||
* Change category position
|
||||
*/
|
||||
const CATEGORY_CHANGE_POSITION = "action.updateCategoryPosition";
|
||||
|
||||
/**
|
||||
* Sent just after a successful insert of a new category in the database.
|
||||
*/
|
||||
const BEFORE_CREATECATEGORY = "action.before_createcategory";
|
||||
const AFTER_CREATECATEGORY = "action.after_createcategory";
|
||||
/**
|
||||
* Sent befonre deleting a category
|
||||
*/
|
||||
const BEFORE_DELETECATEGORY = "action.before_deletecategory";
|
||||
|
||||
/**
|
||||
* Sent just after a successful delete of a category from the database.
|
||||
*/
|
||||
const BEFORE_DELETECATEGORY = "action.before_deletecategory";
|
||||
const AFTER_DELETECATEGORY = "action.after_deletecategory";
|
||||
|
||||
/**
|
||||
* Sent just before a successful change of a category in the database.
|
||||
*/
|
||||
const BEFORE_UPDATECATEGORY = "action.before_updateCategory";
|
||||
|
||||
/**
|
||||
* Sent just after a successful change of a category in the database.
|
||||
*/
|
||||
const AFTER_UPDATECATEGORY = "action.after_updateCategory";
|
||||
|
||||
/**
|
||||
@@ -230,6 +201,11 @@ final class TheliaEvents
|
||||
*/
|
||||
const IMAGE_PROCESS = "action.processImage";
|
||||
|
||||
/**
|
||||
* Sent on document processing
|
||||
*/
|
||||
const DOCUMENT_PROCESS = "action.processDocument";
|
||||
|
||||
/**
|
||||
* Sent on image cache clear request
|
||||
*/
|
||||
@@ -437,4 +413,9 @@ final class TheliaEvents
|
||||
const BEFORE_DELETEFEATURE_AV = "action.before_deleteFeatureAv";
|
||||
const AFTER_DELETEFEATURE_AV = "action.after_deleteFeatureAv";
|
||||
|
||||
/**
|
||||
* sent when system find a mailer transporter.
|
||||
*/
|
||||
const MAILTRANSPORTER_CONFIG = 'action.mailertransporter.config';
|
||||
|
||||
}
|
||||
|
||||
@@ -173,6 +173,22 @@ class Category extends BaseI18nLoop
|
||||
$loopResult = new LoopResult($categories);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
|
||||
// Find previous and next category
|
||||
$previous = CategoryQuery::create()
|
||||
->filterByParent($category->getParent())
|
||||
->filterByPosition($category->getPosition(), Criteria::LESS_THAN)
|
||||
->orderByPosition(Criteria::DESC)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$next = CategoryQuery::create()
|
||||
->filterByParent($category->getParent())
|
||||
->filterByPosition($category->getPosition(), Criteria::GREATER_THAN)
|
||||
->orderByPosition(Criteria::ASC)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
/*
|
||||
* no cause pagination lost :
|
||||
* if ($this->getNotEmpty() && $category->countAllProducts() == 0) continue;
|
||||
@@ -193,7 +209,13 @@ class Category extends BaseI18nLoop
|
||||
->set("PRODUCT_COUNT", $category->countChild())
|
||||
->set("VISIBLE", $category->getVisible() ? "1" : "0")
|
||||
->set("POSITION", $category->getPosition())
|
||||
;
|
||||
|
||||
->set("HAS_PREVIOUS", $previous != null ? 1 : 0)
|
||||
->set("HAS_NEXT" , $next != null ? 1 : 0)
|
||||
|
||||
->set("PREVIOUS", $previous != null ? $previous->getId() : -1)
|
||||
->set("NEXT" , $next != null ? $next->getId() : -1)
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class CategoryTree extends BaseI18nLoop
|
||||
}
|
||||
|
||||
// changement de rubrique
|
||||
protected function buildCategoryTree($parent, $visible, $level, $max_level, array $exclude, LoopResult &$loopResult)
|
||||
protected function buildCategoryTree($parent, $visible, $level, $max_level, $exclude, LoopResult &$loopResult)
|
||||
{
|
||||
if ($level > $max_level) return;
|
||||
|
||||
@@ -73,7 +73,7 @@ class CategoryTree extends BaseI18nLoop
|
||||
|
||||
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
|
||||
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
if ($exclude != null) $search->filterById($exclude, Criteria::NOT_IN);
|
||||
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
|
||||
|
||||
277
core/lib/Thelia/Core/Template/Loop/Document.php
Normal file
277
core/lib/Thelia/Core/Template/Loop/Document.php
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
use Thelia\Core\Template\Element\BaseI18nLoop;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Core\Event\DocumentEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type\EnumListType;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Type\EnumType;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* The document loop
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Document extends BaseI18nLoop
|
||||
{
|
||||
public $timestampable = true;
|
||||
|
||||
/**
|
||||
* @var array Possible document sources
|
||||
*/
|
||||
protected $possible_sources = array('category', 'product', 'folder', 'content');
|
||||
|
||||
/**
|
||||
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection
|
||||
*/
|
||||
protected function getArgDefinitions()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntListTypeArgument('exclude'),
|
||||
new Argument(
|
||||
'order',
|
||||
new TypeCollection(
|
||||
new EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random'))
|
||||
),
|
||||
'manual'
|
||||
),
|
||||
Argument::createIntTypeArgument('lang'),
|
||||
|
||||
Argument::createIntTypeArgument('category'),
|
||||
Argument::createIntTypeArgument('product'),
|
||||
Argument::createIntTypeArgument('folder'),
|
||||
Argument::createIntTypeArgument('content'),
|
||||
|
||||
new Argument(
|
||||
'source',
|
||||
new TypeCollection(
|
||||
new EnumType($this->possible_sources)
|
||||
)
|
||||
),
|
||||
Argument::createIntTypeArgument('source_id')
|
||||
);
|
||||
|
||||
// Add possible document sources
|
||||
foreach ($this->possible_sources as $source) {
|
||||
$collection->addArgument(Argument::createIntTypeArgument($source));
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically create the search query, and set the proper filter and order
|
||||
*
|
||||
* @param string $source a valid source identifier (@see $possible_sources)
|
||||
* @param int $object_id the source object ID
|
||||
* @return ModelCriteria the propel Query object
|
||||
*/
|
||||
protected function createSearchQuery($source, $object_id)
|
||||
{
|
||||
$object = ucfirst($source);
|
||||
|
||||
$queryClass = sprintf("\Thelia\Model\%sDocumentQuery", $object);
|
||||
$filterMethod = sprintf("filterBy%sId", $object);
|
||||
|
||||
// xxxDocumentQuery::create()
|
||||
$method = new \ReflectionMethod($queryClass, 'create');
|
||||
$search = $method->invoke(null); // Static !
|
||||
|
||||
// $query->filterByXXX(id)
|
||||
if (! is_null($object_id)) {
|
||||
$method = new \ReflectionMethod($queryClass, $filterMethod);
|
||||
$method->invoke($search, $object_id);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
// Results ordering
|
||||
foreach ($orders as $order) {
|
||||
switch ($order) {
|
||||
case "alpha":
|
||||
$search->addAscendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
case "alpha-reverse":
|
||||
$search->addDescendingOrderByColumn('i18n_TITLE');
|
||||
break;
|
||||
case "manual-reverse":
|
||||
$search->orderByPosition(Criteria::DESC);
|
||||
break;
|
||||
case "manual":
|
||||
$search->orderByPosition(Criteria::ASC);
|
||||
break;
|
||||
case "random":
|
||||
$search->clearOrderByColumns();
|
||||
$search->addAscendingOrderByColumn('RAND()');
|
||||
break(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically create the search query, and set the proper filter and order
|
||||
*
|
||||
* @param string $object_type (returned) the a valid source identifier (@see $possible_sources)
|
||||
* @param string $object_id (returned) the ID of the source object
|
||||
* @return ModelCriteria the propel Query object
|
||||
*/
|
||||
protected function getSearchQuery(&$object_type, &$object_id)
|
||||
{
|
||||
$search = null;
|
||||
|
||||
// Check form source="product" source_id="123" style arguments
|
||||
$source = $this->getSource();
|
||||
|
||||
if (! is_null($source)) {
|
||||
|
||||
$source_id = $this->getSourceId();
|
||||
$id = $this->getId();
|
||||
|
||||
// echo "source = ".$this->getSource().", id=".$source_id." - ".$this->getArg('source_id')->getValue()."<br />";
|
||||
|
||||
if (is_null($source_id) && is_null($id)) {
|
||||
throw new \InvalidArgumentException("If 'source' argument is specified, 'id' or 'source_id' argument should be specified");
|
||||
}
|
||||
|
||||
$search = $this->createSearchQuery($source, $source_id);
|
||||
|
||||
$object_type = $source;
|
||||
$object_id = $source_id;
|
||||
} else {
|
||||
// Check for product="id" folder="id", etc. style arguments
|
||||
foreach ($this->possible_sources as $source) {
|
||||
|
||||
$argValue = intval($this->getArgValue($source));
|
||||
|
||||
if ($argValue > 0) {
|
||||
|
||||
$search = $this->createSearchQuery($source, $argValue);
|
||||
|
||||
$object_type = $source;
|
||||
$object_id = $argValue;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($search == null)
|
||||
throw new \InvalidArgumentException(sprintf("Unable to find document source. Valid sources are %s", implode(',', $this->possible_sources)));
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown $pagination
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
// Select the proper query to use, and get the object type
|
||||
$object_type = $object_id = null;
|
||||
|
||||
$search = $this->getSearchQuery($object_type, $object_id);
|
||||
|
||||
/* manage translations */
|
||||
$locale = $this->configureI18nProcessing($search);
|
||||
|
||||
$id = $this->getId();
|
||||
|
||||
if (! is_null($id)) {
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
$exclude = $this->getExclude();
|
||||
if (!is_null($exclude))
|
||||
$search->filterById($exclude, Criteria::NOT_IN);
|
||||
|
||||
// Create document processing event
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
// echo "sql=".$search->toString();
|
||||
|
||||
$results = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult($results);
|
||||
|
||||
foreach ($results as $result) {
|
||||
|
||||
// Create document processing event
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
// Put source document file path
|
||||
$source_filepath = sprintf("%s%s/%s/%s",
|
||||
THELIA_ROOT,
|
||||
ConfigQuery::read('documents_library_path', 'local/media/documents'),
|
||||
$object_type,
|
||||
$result->getFile()
|
||||
);
|
||||
|
||||
$event->setSourceFilepath($source_filepath);
|
||||
$event->setCacheSubdirectory($object_type);
|
||||
|
||||
try {
|
||||
// Dispatch document processing event
|
||||
$this->dispatcher->dispatch(TheliaEvents::DOCUMENT_PROCESS, $event);
|
||||
|
||||
$loopResultRow = new LoopResultRow($loopResult, $result, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$loopResultRow
|
||||
->set("ID" , $result->getId())
|
||||
->set("LOCALE" ,$locale)
|
||||
->set("DOCUMENT_URL" , $event->getFileUrl())
|
||||
->set("DOCUMENT_PATH" , $event->getCacheFilepath())
|
||||
->set("ORIGINAL_DOCUMENT_PATH", $source_filepath)
|
||||
->set("TITLE" , $result->getVirtualColumn('i18n_TITLE'))
|
||||
->set("CHAPO" , $result->getVirtualColumn('i18n_CHAPO'))
|
||||
->set("DESCRIPTION" , $result->getVirtualColumn('i18n_DESCRIPTION'))
|
||||
->set("POSTSCRIPTUM" , $result->getVirtualColumn('i18n_POSTSCRIPTUM'))
|
||||
->set("POSITION" , $result->getPosition())
|
||||
->set("OBJECT_TYPE" , $object_type)
|
||||
->set("OBJECT_ID" , $object_id)
|
||||
;
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Ignore the result and log an error
|
||||
Tlog::getInstance()->addError("Failed to process document in document loop: ", $this->args);
|
||||
}
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -123,8 +123,10 @@ class Image extends BaseI18nLoop
|
||||
$search = $method->invoke(null); // Static !
|
||||
|
||||
// $query->filterByXXX(id)
|
||||
$method = new \ReflectionMethod($queryClass, $filterMethod);
|
||||
$method->invoke($search, $object_id);
|
||||
if (! is_null($object_id)) {
|
||||
$method = new \ReflectionMethod($queryClass, $filterMethod);
|
||||
$method->invoke($search, $object_id);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
@@ -171,11 +173,12 @@ class Image extends BaseI18nLoop
|
||||
if (! is_null($source)) {
|
||||
|
||||
$source_id = $this->getSourceId();
|
||||
$id = $this->getId();
|
||||
|
||||
// echo "source = ".$this->getSource().", id=".$source_id." - ".$this->getArg('source_id')->getValue()."<br />";
|
||||
//echo "source = ".$this->getSource()."source_id=$source_id, id=$id<br />";
|
||||
|
||||
if (is_null($source_id)) {
|
||||
throw new \InvalidArgumentException("'source_id' argument cannot be null if 'source' argument is specified.");
|
||||
if (is_null($source_id) && is_null($id)) {
|
||||
throw new \InvalidArgumentException("If 'source' argument is specified, 'id' or 'source_id' argument should be specified");
|
||||
}
|
||||
|
||||
$search = $this->createSearchQuery($source, $source_id);
|
||||
@@ -259,14 +262,13 @@ class Image extends BaseI18nLoop
|
||||
|
||||
}
|
||||
|
||||
// echo "sql=".$search->toString();
|
||||
//echo "sql=".$search->toString();
|
||||
|
||||
$results = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult($results);
|
||||
|
||||
foreach ($results as $result) {
|
||||
|
||||
// Create image processing event
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
@@ -282,7 +284,7 @@ class Image extends BaseI18nLoop
|
||||
// Put source image file path
|
||||
$source_filepath = sprintf("%s%s/%s/%s",
|
||||
THELIA_ROOT,
|
||||
ConfigQuery::read('documents_library_path', 'local/media/images'),
|
||||
ConfigQuery::read('images_library_path', 'local/media/images'),
|
||||
$object_type,
|
||||
$result->getFile()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user