Back-office : on affiche le prix TTC et plus HT

This commit is contained in:
2021-05-31 16:48:14 +02:00
parent a990a8c123
commit d399a29705
1813 changed files with 4386 additions and 118961 deletions

View File

@@ -0,0 +1,39 @@
<?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">
<services>
<service id="sitemap.listener" class="Sitemap\EventListeners\EventManager" scope="request">
<tag name="kernel.event_subscriber"/>
<argument type="service" id="request"/>
</service>
</services>
<hooks>
<hook id="sitemap.hook" class="Sitemap\Hook\SitemapHook" scope="request">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfig" />
</hook>
<hook id="sitemap.product_edit.hook" class="Sitemap\Hook\SitemapHook" scope="request">
<tag name="hook.event_listener" event="product.modification.form-right.bottom" type="back" method="onProductEditRightColumnBottom" />
</hook>
<hook id="sitemap.category_edit.hook" class="Sitemap\Hook\SitemapHook" scope="request">
<tag name="hook.event_listener" event="category.modification.form-right.bottom" type="back" method="onCategoryEditRightColumnBottom" />
</hook>
<hook id="sitemap.content_edit.hook" class="Sitemap\Hook\SitemapHook" scope="request">
<tag name="hook.event_listener" event="content.modification.form-right.bottom" type="back" method="onContentEditRightColumnBottom" />
</hook>
<hook id="sitemap.folder_edit.hook" class="Sitemap\Hook\SitemapHook" scope="request">
<tag name="hook.event_listener" event="folder.modification.form-right.bottom" type="back" method="onFolderEditRightColumnBottom" />
</hook>
<hook id="sitemap.brand_edit.hook" class="Sitemap\Hook\SitemapHook" scope="request">
<tag name="hook.event_listener" event="brand.modification.form-right.bottom" type="back" method="onBrandEditRightColumnBottom" />
</hook>
</hooks>
<forms>
<form name="sitemap_config_form" class="Sitemap\Form\SitemapConfigForm" />
</forms>
</config>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
<fullnamespace>Sitemap\Sitemap</fullnamespace>
<descriptive locale="en_US">
<title>Create sitemap and sitemap image files more quickly</title>
</descriptive>
<descriptive locale="fr_FR">
<title>Génère les fichiers sitemap et sitemap image plus rapidement</title>
</descriptive>
<languages>
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.5.0</version>
<authors>
<author>
<name>Etienne Perriere</name>
<email>eperriere@openstudio.fr</email>
</author>
</authors>
<type>classic</type>
<thelia>2.1.0</thelia>
<stability>beta</stability>
</module>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="sitemap.process" path="/sitemap">
<default key="_controller">Sitemap\Controller\SitemapController::generateAction</default>
</route>
<route id="sitemap.image.process" path="/sitemap-image">
<default key="_controller">Sitemap\Controller\SitemapController::generateImageAction</default>
</route>
<route id="sitemap.configuration.default" path="/admin/module/Sitemap" methods="get">
<default key="_controller">Sitemap:SitemapConfig:default</default>
</route>
<route id="sitemap.configuration.save" path="/admin/module/Sitemap" methods="post">
<default key="_controller">Sitemap:SitemapConfig:save</default>
</route>
</routes>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../core/vendor/propel/propel/resources/xsd/database.xsd" >
<table name="sitemap_priority" namespace="Sitemap\Model">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="value" type="FLOAT" />
<column name="source" size="64" type="VARCHAR" />
<column name="source_id" type="INTEGER" />
<behavior name="timestampable" />
</table>
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
</database>

View File

@@ -0,0 +1,2 @@
# Sqlfile -> Database map
thelia.sql=thelia

View File

@@ -0,0 +1,24 @@
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;
-- ---------------------------------------------------------------------
-- sitemap_priority
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `sitemap_priority`;
CREATE TABLE `sitemap_priority`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`value` FLOAT,
`source` VARCHAR(64),
`source_id` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -0,0 +1,24 @@
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;
-- ---------------------------------------------------------------------
-- sitemap_priority
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `sitemap_priority`;
CREATE TABLE `sitemap_priority`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`value` FLOAT,
`source` VARCHAR(64),
`source_id` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -0,0 +1,107 @@
<?php
namespace Sitemap\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Event\SitemapEvent;
use Sitemap\Model\SitemapPriorityQuery;
use Sitemap\Sitemap;
use Thelia\Model\Map\BrandTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\RewritingUrl;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Tools\URL;
/**
* Class BrandSitemapTrait
* @package Sitemap\Controller
* @author Damien Foulhoux <dfoulhoux@openstudio.fr>
*/
trait BrandSitemapTrait
{
/**
* Get brands
*
* @param $sitemap
* @param $locale
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function setSitemapBrands(&$sitemap, $locale)
{
// Prepare query - get brands URL
$query = RewritingUrlQuery::create()
->filterByView('brand')
->filterByRedirected(null)
->filterByViewLocale($locale);
// Join with visible brands
self::addJoinBrands($query);
// Get brands last update
$query->withColumn(BrandTableMap::UPDATED_AT, 'BRAND_UPDATE_AT');
// Execute query
$results = $query->find();
// For each result, hydrate XML file
/** @var RewritingUrl $result */
foreach ($results as $result) {
$sitemapEvent = new SitemapEvent(
$result,
URL::getInstance()->absoluteUrl($result->getUrl()),
date('c', strtotime($result->getVirtualColumn('BRAND_UPDATE_AT')))
);
$this->getDispatcher()->dispatch(SitemapEvent::SITEMAP_EVENT, $sitemapEvent);
if (!$sitemapEvent->isHide()){
// Open new sitemap line & set brand URL & update date
$sitemapPriority = SitemapPriorityQuery::create()
->filterBySource($result->getView())
->filterBySourceId($result->getViewId())
->findOne();
$sitemapPriorityValue = ($sitemapPriority === null) ? Sitemap::getConfigValue('default_priority_brand_value', SiteMap::DEFAULT_PRIORITY_BRAND_VALUE) : $sitemapPriority->getValue();
$sitemap[] = '
<url>
<loc>'.$sitemapEvent->getLoc().'</loc>
<lastmod>'.$sitemapEvent->getLastmod().'</lastmod>
<priority>'.$sitemapPriorityValue.'</priority>
<changefreq>'.Sitemap::getConfigValue('default_update_frequency', SiteMap::DEFAULT_FREQUENCY_UPDATE).'</changefreq>
</url>';
}
}
}
/**
* Join brands and their URLs
*
* @param RewritingUrlQuery $query
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function addJoinBrands(RewritingUrlQuery &$query)
{
// Join RewritingURL with brand to have only visible brands
$join = new Join();
$join->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
BrandTableMap::TABLE_NAME,
'ID',
null
);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'brandJoin');
// Get only visible products
$query->addJoinCondition('brandJoin', BrandTableMap::VISIBLE.' = 1');
}
}

View File

@@ -0,0 +1,150 @@
<?php
namespace Sitemap\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Event\SitemapEvent;
use Sitemap\Model\SitemapPriorityQuery;
use Sitemap\Sitemap;
use Thelia\Model\Map\CategoryTableMap;
use Thelia\Model\Map\ProductCategoryTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\RewritingUrl;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Tools\URL;
/**
* Trait CategorySitemapTrait
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
trait CategorySitemapTrait
{
/**
* Get categories
*
* @param $sitemap
* @param $locale
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function setSitemapCategories(&$sitemap, $locale)
{
// Prepare query - get categories URL
$query = RewritingUrlQuery::create()
->filterByView('category')
->filterByRedirected(null)
->filterByViewLocale($locale);
// Join with visible categories
self::addJoinCategory($query, $locale);
if (Sitemap::getConfigValue('exclude_empty_category') == 1) {
self::addJoinCategoryCheckNotEmpty($query);
}
// Get categories last update
$query->withColumn(CategoryTableMap::UPDATED_AT, 'CATEGORY_UPDATE_AT');
// Execute query
$results = $query->find();
// For each result, hydrate XML file
/** @var RewritingUrl $result */
foreach ($results as $result) {
$sitemapEvent = new SitemapEvent(
$result,
URL::getInstance()->absoluteUrl($result->getUrl()),
date('c', strtotime($result->getVirtualColumn('CATEGORY_UPDATE_AT')))
);
$this->getDispatcher()->dispatch(SitemapEvent::SITEMAP_EVENT, $sitemapEvent);
if (!$sitemapEvent->isHide()) {
// Open new sitemap line & set category URL & update date
$sitemapPriority = SitemapPriorityQuery::create()
->filterBySource($result->getView())
->filterBySourceId($result->getViewId())
->findOne();
$sitemapPriorityValue = ($sitemapPriority === null) ? Sitemap::getConfigValue('default_priority_category_value', SiteMap::DEFAULT_PRIORITY_CATEGORY_VALUE) : $sitemapPriority->getValue();
$sitemap[] = '
<url>
<loc>' . $sitemapEvent->getLoc() . '</loc>
<lastmod>' . $sitemapEvent->getLastmod() . '</lastmod>
<priority>'.$sitemapPriorityValue.'</priority>
<changefreq>'.Sitemap::getConfigValue('default_update_frequency', SiteMap::DEFAULT_FREQUENCY_UPDATE).'</changefreq>
</url>';
}
}
}
/**
* Join categories and their URLs
*
* @param RewritingUrlQuery $query
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function addJoinCategory(RewritingUrlQuery &$query)
{
// Join RewritingURL with Category to have only visible categories
$join = new Join();
$join->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
CategoryTableMap::TABLE_NAME,
'ID',
null
);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'categoryJoin');
// Get only visible categories
$query->addJoinCondition('categoryJoin', CategoryTableMap::VISIBLE.' = 1');
}
/**
* Join categories and their URLs
*
* @param Criteria $query
*/
protected function addJoinCategoryCheckNotEmpty(Criteria &$query)
{
$categoryChildJoin = new Join();
$categoryChildJoin->addExplicitCondition(
CategoryTableMap::TABLE_NAME,
'ID',
null,
CategoryTableMap::TABLE_NAME,
'PARENT',
'category_category_child'
);
$categoryChildJoin->setJoinType(Criteria::LEFT_JOIN);
$query->addJoinObject($categoryChildJoin, 'categoryCategoryChildJoin');
$productChildJoin = new Join();
$productChildJoin->addExplicitCondition(
CategoryTableMap::TABLE_NAME,
'ID',
null,
ProductCategoryTableMap::TABLE_NAME,
'CATEGORY_ID',
'category_product_child'
);
$productChildJoin->setJoinType(Criteria::LEFT_JOIN);
$query->addJoinObject($productChildJoin, 'categoryProductChildJoin');
$query->where('(category_category_child.id IS NOT NULL || category_product_child.product_id IS NOT NULL)');
$query->addGroupByColumn('ID');
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace Sitemap\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Event\SitemapEvent;
use Sitemap\Model\SitemapPriorityQuery;
use Sitemap\Sitemap;
use Thelia\Model\Map\ContentTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\RewritingUrl;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Tools\URL;
/**
* Class ContentSitemapTrait
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
trait ContentSitemapTrait
{
/**
* Get contents
*
* @param $sitemap
* @param $locale
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function setSitemapContents(&$sitemap, $locale)
{
// Prepare query - get contents URL
$query = RewritingUrlQuery::create()
->filterByView('content')
->filterByRedirected(null)
->filterByViewLocale($locale);
// Join with visible contents
self::addJoinContent($query);
// Get contents last update
$query->withColumn(ContentTableMap::UPDATED_AT, 'CONTENT_UPDATE_AT');
// Execute query
$results = $query->find();
// For each result, hydrate XML file
/** @var RewritingUrl $result */
foreach ($results as $result) {
$sitemapEvent = new SitemapEvent(
$result,
URL::getInstance()->absoluteUrl($result->getUrl()),
date('c', strtotime($result->getVirtualColumn('CONTENT_UPDATE_AT')))
);
$this->getDispatcher()->dispatch(SitemapEvent::SITEMAP_EVENT, $sitemapEvent);
if (!$sitemapEvent->isHide()){
// Open new sitemap line & set brand URL & update date
$sitemapPriority = SitemapPriorityQuery::create()
->filterBySource($result->getView())
->filterBySourceId($result->getViewId())
->findOne();
$sitemapPriorityValue = ($sitemapPriority === null) ? Sitemap::getConfigValue('default_priority_folder_value', SiteMap::DEFAULT_PRIORITY_FOLDER_VALUE) : $sitemapPriority->getValue();
$sitemap[] = '
<url>
<loc>'.$sitemapEvent->getLoc().'</loc>
<lastmod>'.$sitemapEvent->getLastmod().'</lastmod>
<priority>'.$sitemapPriorityValue.'</priority>
<changefreq>'.Sitemap::getConfigValue('default_update_frequency', SiteMap::DEFAULT_FREQUENCY_UPDATE).'</changefreq>
</url>';
}
}
}
/**
* Join contents and their URLs
*
* @param RewritingUrlQuery $query
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function addJoinContent(RewritingUrlQuery &$query)
{
// Join RewritingURL with Content to have only visible contents
$join = new Join();
$join->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
ContentTableMap::TABLE_NAME,
'ID',
null
);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'contentJoin');
// Get only visible products
$query->addJoinCondition('contentJoin', ContentTableMap::VISIBLE.' = 1');
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace Sitemap\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Event\SitemapEvent;
use Sitemap\Model\SitemapPriorityQuery;
use Sitemap\Sitemap;
use Thelia\Model\Map\ContentFolderTableMap;
use Thelia\Model\Map\FolderTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\RewritingUrl;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Tools\URL;
/**
* Class FolderSitemapTrait
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
trait FolderSitemapTrait
{
/**
* Get folders
*
* @param $sitemap
* @param $locale
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function setSitemapFolders(&$sitemap, $locale)
{
// Prepare query - get folders URL
$query = RewritingUrlQuery::create()
->filterByView('folder')
->filterByRedirected(null)
->filterByViewLocale($locale);
// Join with visible folders
self::addJoinFolder($query);
if (Sitemap::getConfigValue('exclude_empty_folder') == 1) {
self::addJoinFolderCheckNotEmpty($query);
}
// Get folders last update
$query->withColumn(FolderTableMap::UPDATED_AT, 'FOLDER_UPDATE_AT');
// Execute query
$results = $query->find();
// For each result, hydrate XML file
/** @var RewritingUrl $result */
foreach ($results as $result) {
$sitemapEvent = new SitemapEvent(
$result,
URL::getInstance()->absoluteUrl($result->getUrl()),
date('c', strtotime($result->getVirtualColumn('FOLDER_UPDATE_AT')))
);
$this->getDispatcher()->dispatch(SitemapEvent::SITEMAP_EVENT, $sitemapEvent);
if (!$sitemapEvent->isHide()){
// Open new sitemap line & set brand URL & update date
$sitemapPriority = SitemapPriorityQuery::create()
->filterBySource($result->getView())
->filterBySourceId($result->getViewId())
->findOne();
$sitemapPriorityValue = ($sitemapPriority === null) ? Sitemap::getConfigValue('default_priority_folder_value', SiteMap::DEFAULT_PRIORITY_FOLDER_VALUE) : $sitemapPriority->getValue();
$sitemap[] = '
<url>
<loc>'.$sitemapEvent->getLoc().'</loc>
<lastmod>'.$sitemapEvent->getLastmod().'</lastmod>
<priority>'.$sitemapPriorityValue.'</priority>
<changefreq>'.Sitemap::getConfigValue('default_update_frequency', SiteMap::DEFAULT_FREQUENCY_UPDATE).'</changefreq>
</url>';
}
}
}
/**
* Join folders and their URLs
*
* @param RewritingUrlQuery $query
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function addJoinFolder(RewritingUrlQuery &$query)
{
// Join RewritingURL with Folder to have only visible folders
$join = new Join();
$join->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
FolderTableMap::TABLE_NAME,
'ID',
null
);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'folderJoin');
// Get only visible folders
$query->addJoinCondition('folderJoin', FolderTableMap::VISIBLE.' = 1');
}
protected function addJoinFolderCheckNotEmpty(Criteria &$query)
{
$folderChildJoin = new Join();
$folderChildJoin->addExplicitCondition(
FolderTableMap::TABLE_NAME,
'ID',
null,
FolderTableMap::TABLE_NAME,
'PARENT',
'folder_folder_child'
);
$folderChildJoin->setJoinType(Criteria::LEFT_JOIN);
$query->addJoinObject($folderChildJoin, 'folderFolderChildJoin');
$contentChildJoin = new Join();
$contentChildJoin->addExplicitCondition(
FolderTableMap::TABLE_NAME,
'ID',
null,
ContentFolderTableMap::TABLE_NAME,
'FOLDER_ID',
'folder_content_child'
);
$contentChildJoin->setJoinType(Criteria::LEFT_JOIN);
$query->addJoinObject($contentChildJoin, 'folderContentChildJoin');
$query->where('(folder_folder_child.id IS NOT NULL || folder_content_child.content_id IS NOT NULL)');
$query->addGroupByColumn('ID');
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Sitemap\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Sitemap;
use Thelia\Model\Map\ProductI18nTableMap;
use Thelia\Model\Map\ProductImageTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\RewritingUrl;
use Thelia\Model\RewritingUrlQuery;
/**
* Class ProductImageTrait
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
trait ProductImageTrait
{
protected function setSitemapProductImages(&$sitemap, $locale)
{
// Change timeout for this script
ini_set('max_execution_time', Sitemap::getConfigValue('timeout', 30));
// Prepare query - get products URL
$query = RewritingUrlQuery::create()
->filterByView('product')
->filterByRedirected(null)
->filterByViewLocale($locale);
// Join with visible products
self::addJoinProductI18n($query);
// Get products title & image file name
$query->withColumn(ProductI18nTableMap::TITLE, 'PRODUCT_TITLE');
$query->addDescendingOrderByColumn(ProductImageTableMap::POSITION);
$query->addGroupByColumn(RewritingUrlTableMap::VIEW_ID);
$query->withColumn(ProductImageTableMap::FILE, 'PRODUCT_FILE');
// Execute query
$results = $query->find();
// Get image generation configuration values
$configValues = [];
$configValues['width'] = Sitemap::getConfigValue('width');
$configValues['height'] = Sitemap::getConfigValue('height');
$configValues['quality'] = Sitemap::getConfigValue('quality', 75);
$configValues['rotation'] = Sitemap::getConfigValue('rotation', 0);
$configValues['resizeMode'] = Sitemap::getConfigValue('resize_mode', \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS);
$configValues['bgColor'] = Sitemap::getConfigValue('background_color');
$configValues['allowZoom'] = Sitemap::getConfigValue('allow_zoom', false);
// For each result, hydrate XML file
/** @var RewritingUrl $result */
foreach ($results as $result) {
// Generate image data
$this->generateSitemapImage('product', $result, $configValues, $sitemap);
}
}
/**
* Join products and their URLs
*
* @param RewritingUrlQuery $query
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function addJoinProductI18n(RewritingUrlQuery &$query)
{
// Join RewritingURL with Product to have only visible products
$join = new Join();
$join->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
ProductTableMap::TABLE_NAME,
'ID',
null
);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'productJoin');
$query->addJoinCondition('productJoin', ProductTableMap::VISIBLE.' = 1');
// Join RewritingURL with ProductI18n to have product title for it's image
$joinI18n = new Join();
$joinI18n->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
ProductI18nTableMap::TABLE_NAME,
'ID',
null
);
$joinI18n->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_LOCALE',
null,
ProductI18nTableMap::TABLE_NAME,
'LOCALE',
null
);
$joinI18n->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($joinI18n);
// Join RewritingURL with ProductImage to have image file
$joinImage = new Join();
$joinImage->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
ProductImageTableMap::TABLE_NAME,
'PRODUCT_ID',
null
);
$joinImage->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($joinImage, 'productImageJoin');
$query->addJoinCondition('productImageJoin', ProductImageTableMap::VISIBLE.' = 1');
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Sitemap\Controller;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Event\SitemapEvent;
use Sitemap\Model\SitemapPriorityQuery;
use Sitemap\Sitemap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\Map\RewritingUrlTableMap;
use Thelia\Model\RewritingUrl;
use Thelia\Model\RewritingUrlQuery;
use Thelia\Tools\URL;
/**
* Trait ProductSitemapTrait
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
trait ProductSitemapTrait
{
/**
* Get products
*
* @param $sitemap
* @param $locale
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function setSitemapProducts(&$sitemap, $locale)
{
// Prepare query - get products URL
$query = RewritingUrlQuery::create()
->filterByView('product')
->filterByRedirected(null)
->filterByViewLocale($locale);
// Join with visible products
self::addJoinProduct($query);
// Get products last update
$query->withColumn(ProductTableMap::UPDATED_AT, 'PRODUCT_UPDATE_AT');
// Execute query
$results = $query->find();
// For each result, hydrate XML file
/** @var RewritingUrl $result */
foreach ($results as $result) {
$sitemapEvent = new SitemapEvent(
$result,
URL::getInstance()->absoluteUrl($result->getUrl()),
date('c', strtotime($result->getVirtualColumn('PRODUCT_UPDATE_AT')))
);
$this->getDispatcher()->dispatch(SitemapEvent::SITEMAP_EVENT, $sitemapEvent);
if (!$sitemapEvent->isHide()){
// Open new sitemap line & set brand URL & update date
$sitemapPriority = SitemapPriorityQuery::create()
->filterBySource($result->getView())
->filterBySourceId($result->getViewId())
->findOne();
$sitemapPriorityValue = ($sitemapPriority === null) ? Sitemap::getConfigValue('default_priority_product_value', SiteMap::DEFAULT_PRIORITY_PRODUCT_VALUE) : $sitemapPriority->getValue();
$sitemap[] = '
<url>
<loc>'.$sitemapEvent->getLoc().'</loc>
<lastmod>'.$sitemapEvent->getLastmod().'</lastmod>
<priority>'.$sitemapPriorityValue.'</priority>
<changefreq>'.Sitemap::getConfigValue('default_update_frequency', SiteMap::DEFAULT_FREQUENCY_UPDATE).'</changefreq>
</url>';
}
}
}
/**
* Join products and their URLs
*
* @param RewritingUrlQuery $query
*
* @throws \Propel\Runtime\Exception\PropelException
*/
protected function addJoinProduct(RewritingUrlQuery &$query)
{
// Join RewritingURL with Product to have only visible products
$join = new Join();
$join->addExplicitCondition(
RewritingUrlTableMap::TABLE_NAME,
'VIEW_ID',
null,
ProductTableMap::TABLE_NAME,
'ID',
null
);
$join->setJoinType(Criteria::INNER_JOIN);
$query->addJoinObject($join, 'productJoin');
// Get only visible products
$query->addJoinCondition('productJoin', ProductTableMap::VISIBLE.' = 1');
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace Sitemap\Controller;
use Sitemap\Sitemap;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Exception\FormValidationException;
/**
* Class SitemapConfigController
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class SitemapConfigController extends BaseAdminController
{
public function defaultAction()
{
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["sitemap"], AccessManager::VIEW)) {
return $response;
}
// Get resize mode name
switch (Sitemap::getConfigValue('resize_mode')) {
case 1:
$resizeMode = 'borders';
break;
case 2:
$resizeMode = 'crop';
break;
case 3:
$resizeMode = 'none';
break;
default:
$resizeMode = '';
break;
}
// Build form
$form = $this->createForm(
"sitemap_config_form",
'form',
[
'timeout' => Sitemap::getConfigValue('timeout'),
'width' => Sitemap::getConfigValue('width'),
'height' => Sitemap::getConfigValue('height'),
'quality' => Sitemap::getConfigValue('quality'),
'rotation' => Sitemap::getConfigValue('rotation'),
'resize_mode' => $resizeMode,
'background_color' => Sitemap::getConfigValue('background_color'),
'allow_zoom' => Sitemap::getConfigValue('allow_zoom'),
'exclude_empty_category' => Sitemap::getConfigValue('exclude_empty_category'),
'exclude_empty_folder' => Sitemap::getConfigValue('exclude_empty_folder'),
'default_priority_homepage_value' => Sitemap::getConfigValue('default_priority_homepage_value'),
'default_priority_brand_value' => Sitemap::getConfigValue('default_priority_brand_value'),
'default_priority_category_value' => Sitemap::getConfigValue('default_priority_category_value'),
'default_priority_product_value' => Sitemap::getConfigValue('default_priority_product_value'),
'default_priority_folder_value' => Sitemap::getConfigValue('default_priority_folder_value'),
'default_update_frequency' => Sitemap::getConfigValue('default_update_frequency')
]
);
$this->getParserContext()->addForm($form);
return $this->render("sitemap-configuration");
}
/**
* Save data
*
* @return mixed|\Thelia\Core\HttpFoundation\Response
*/
public function saveAction()
{
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["sitemap"], AccessManager::UPDATE)) {
return $response;
}
$baseForm = $this->createForm("sitemap_config_form");
$errorMessage = null;
// Get current edition language locale
$locale = $this->getCurrentEditionLocale();
try {
$form = $this->validateForm($baseForm);
$data = $form->getData();
$excludeEmptyCategory = $data['exclude_empty_category'] == 1;
$excludeEmptyFolder = $data['exclude_empty_folder'] == 1;
// Get resize mode
switch ($data["resize_mode"]) {
case 'none':
$resizeMode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
break;
case 'crop':
$resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
break;
case 'borders':
default:
$resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
break;
}
// Save data
Sitemap::setConfigValue('timeout', $data['timeout']);
Sitemap::setConfigValue('width', $data['width']);
Sitemap::setConfigValue('height', $data['height']);
Sitemap::setConfigValue('quality', $data['quality']);
Sitemap::setConfigValue('rotation', $data['rotation']);
Sitemap::setConfigValue('resize_mode', $resizeMode);
Sitemap::setConfigValue('background_color', $data['background_color']);
Sitemap::setConfigValue('allow_zoom', $data['allow_zoom']);
Sitemap::setConfigValue('exclude_empty_category', $excludeEmptyCategory);
Sitemap::setConfigValue('exclude_empty_folder', $excludeEmptyFolder);
Sitemap::setConfigValue('default_priority_homepage_value', $data['default_priority_homepage_value']);
Sitemap::setConfigValue('default_priority_brand_value', $data['default_priority_brand_value']);
Sitemap::setConfigValue('default_priority_category_value', $data['default_priority_category_value']);
Sitemap::setConfigValue('default_priority_product_value', $data['default_priority_product_value']);
Sitemap::setConfigValue('default_priority_folder_value', $data['default_priority_folder_value']);
Sitemap::setConfigValue('default_update_frequency', $data['default_update_frequency']);
} catch (FormValidationException $ex) {
// Invalid data entered
$errorMessage = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], Sitemap::DOMAIN_NAME, $locale);
}
if (null !== $errorMessage) {
// Mark the form as with error
$baseForm->setErrorMessage($errorMessage);
// Send the form and the error to the parser
$this->getParserContext()
->addForm($baseForm)
->setGeneralError($errorMessage)
;
} else {
$this->getParserContext()
->set("success", true)
;
}
return $this->defaultAction();
}
}

View File

@@ -0,0 +1,284 @@
<?php
namespace Sitemap\Controller;
use Doctrine\Common\Cache\FilesystemCache;
use Sitemap\Event\SitemapEndEvent;
use Sitemap\Event\SitemapEvent;
use Sitemap\Sitemap;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Image\ImageEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
use Thelia\Model\RewritingUrl;
use Thelia\Tools\URL;
/**
* Class SitemapController
* @package Sitemap\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class SitemapController extends BaseFrontController
{
use CategorySitemapTrait;
use ProductSitemapTrait;
use FolderSitemapTrait;
use ContentSitemapTrait;
use BrandSitemapTrait;
use ProductImageTrait;
/** Folder name for sitemap cache */
const SITEMAP_CACHE_DIR = "sitemap";
/** Key prefix for sitemap cache */
const SITEMAP_CACHE_KEY = "sitemap";
/** Folder name for sitemap image cache */
const SITEMAP_IMAGE_CACHE_DIR = "sitemap-image";
/** Key prefix for sitemap image cache */
const SITEMAP_IMAGE_CACHE_KEY = "sitemap-image";
protected $useFallbackTemplate = true;
/**
* Generate sitemap
*/
public function generateAction()
{
return $this->generateSitemap(self::SITEMAP_CACHE_KEY, self::SITEMAP_CACHE_DIR);
}
/**
* Generate sitemap image
*/
public function generateImageAction()
{
return $this->generateSitemap(self::SITEMAP_IMAGE_CACHE_KEY, self::SITEMAP_IMAGE_CACHE_DIR);
}
/**
* Check if cached sitemap can be used or generate a new one and cache it
*
* @param $cacheKey
* @param $cacheDirName
* @return Response
*/
public function generateSitemap($cacheKey, $cacheDirName)
{
// Get and check locale
$locale = $this->getSession()->getLang()->getLocale();
if ("" !== $locale) {
if (! $this->checkLang($locale)){
$this->pageNotFound();
}
}
// Get sitemap cache information
$sitemapContent = false;
$cacheDir = $this->getCacheDir($cacheDirName);
$cacheKey .= $locale;
$cacheExpire = intval(ConfigQuery::read("sitemap_ttl", '7200')) ?: 7200;
$cacheDriver = new FilesystemCache($cacheDir);
// Check if sitemap has to be deleted
if (!($this->checkAdmin() && "" !== $this->getRequest()->query->get("flush", ""))){
// Get cached sitemap
$sitemapContent = $cacheDriver->fetch($cacheKey);
} else {
$cacheDriver->delete($cacheKey);
}
// If not in cache, generate and cache it
if (false === $sitemapContent){
// Check if we generate the standard sitemap or the sitemap image
switch ($cacheDirName) {
// Image
case self::SITEMAP_IMAGE_CACHE_DIR:
$sitemap = $this->hydrateSitemapImage($locale);
break;
// Standard
case self::SITEMAP_CACHE_DIR:
default:
$sitemap = $this->hydrateSitemap($locale);
break;
}
$sitemapContent = implode("\n", $sitemap);
// Save cache
$cacheDriver->save($cacheKey, $sitemapContent, $cacheExpire);
}
// Render
$response = new Response();
$response->setContent($sitemapContent);
$response->headers->set('Content-Type', 'application/xml');
return $response;
}
/* ------------------ */
/**
* Build sitemap array
*
* @param $locale
* @return array
*/
protected function hydrateSitemap($locale)
{
// Begin sitemap
$sitemap = ['<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated on : '. date('Y-m-d H:i:s') .' -->
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>'.URL::getInstance()->getIndexPage().'</loc>
<priority>'.Sitemap::getConfigValue('default_priority_homepage_value', SiteMap::DEFAULT_PRIORITY_HOME_VALUE).'</priority>
<changefreq>'.Sitemap::getConfigValue('default_update_frequency', SiteMap::DEFAULT_FREQUENCY_UPDATE).'</changefreq>
</url>'
];
// Hydrate sitemap
$this->setSitemapCategories($sitemap, $locale);
$this->setSitemapProducts($sitemap, $locale);
$this->setSitemapFolders($sitemap, $locale);
$this->setSitemapContents($sitemap, $locale);
$this->setSitemapBrands($sitemap, $locale);
$event = new SitemapEndEvent();
$event->setSitemap($sitemap);
$this->getDispatcher()->dispatch(SitemapEvent::SITEMAP_END_EVENT, $event);
$sitemap = $event->getSitemap();
// End sitemap
$sitemap[] = "\t".'</urlset>';
return $sitemap;
}
/**
* Build sitemap image array
*
* @param $locale
* @return array
*/
protected function hydrateSitemapImage($locale)
{
// Begin sitemap image
$sitemap = ['<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated on : '. date('Y-m-d H:i:s') .' -->
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>'.URL::getInstance()->getIndexPage().'</loc>
</url>'
];
// Hydrate sitemap image
$this->setSitemapProductImages($sitemap, $locale);
// End sitemap image
$sitemap[] = "\t".'</urlset>';
return $sitemap;
}
/* ------------------ */
/**
* @param $type
* @param RewritingUrl $result
* @param $configValues
* @param $sitemap
*/
protected function generateSitemapImage($type, $result, $configValues, &$sitemap)
{
$event = new ImageEvent();
$event
->setWidth($configValues['width'])
->setHeight($configValues['height'])
->setQuality($configValues['quality'])
->setRotation($configValues['rotation'])
->setResizeMode($configValues['resizeMode'])
->setBackgroundColor($configValues['bgColor'])
->setAllowZoom($configValues['allowZoom']);
// Put source image file path
$source_filepath = sprintf("%s%s/%s/%s",
THELIA_ROOT,
ConfigQuery::read('images_library_path', 'local/media/images'),
$type,
$result->getVirtualColumn('PRODUCT_FILE')
);
$event->setSourceFilepath($source_filepath);
$event->setCacheSubdirectory($type);
try {
// Dispatch image processing event
$this->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
// New sitemap image entry
$sitemap[] = '
<url>
<loc>'.URL::getInstance()->absoluteUrl($result->getUrl()).'</loc>
<image:image>
<image:loc>'.$event->getFileUrl().'</image:loc>
<image:title>'.htmlspecialchars($result->getVirtualColumn('PRODUCT_TITLE')).'</image:title>
</image:image>
</url>';
} catch (\Exception $ex) {
}
}
/* ------------------ */
/**
* @param $locale
* @return bool true if the language is used, otherwise false
*/
protected function checkLang($locale)
{
// Load locales
$locale = LangQuery::create()
->findOneByLocale($locale);
return (null !== $locale);
}
/**
* Get the cache directory for sitemap
*
* @param $cacheDirName
* @return mixed|string
*/
protected function getCacheDir($cacheDirName)
{
$cacheDir = $this->container->getParameter("kernel.cache_dir");
$cacheDir = rtrim($cacheDir, '/');
$cacheDir .= '/' . $cacheDirName . '/';
return $cacheDir;
}
/**
* Check if current user has ADMIN role
*
* @return bool
*/
protected function checkAdmin(){
return $this->getSecurityContext()->hasAdminUser();
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Sitemap\Event;
use Thelia\Core\Event\ActionEvent;
class SitemapEndEvent extends ActionEvent
{
protected $sitemap;
/**
* @return mixed
*/
public function getSitemap()
{
return $this->sitemap;
}
/**
* @param mixed $sitemap
*/
public function setSitemap($sitemap)
{
$this->sitemap = $sitemap;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Sitemap\Event;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\RewritingUrl;
class SitemapEvent extends ActionEvent
{
const SITEMAP_EVENT = 'sitemap_event';
const SITEMAP_END_EVENT = 'sitemap_end_event';
/** @var RewritingUrl */
protected $rewritingUrl;
/** @var string */
protected $loc;
/** @var string */
protected $lastmod;
/** @var boolean */
protected $hide;
public function __construct(RewritingUrl $rewritingUrl = null, $loc = "", $lastmod = "", $hide = false)
{
$this->rewritingUrl = $rewritingUrl;
$this->loc = $loc;
$this->lastmod = $lastmod;
$this->hide = $hide;
}
/**
* @return RewritingUrl
*/
public function getRewritingUrl()
{
return $this->rewritingUrl;
}
/**
* @param RewritingUrl $rewritingUrl
*/
public function setRewritingUrl($rewritingUrl)
{
$this->rewritingUrl = $rewritingUrl;
}
/**
* @return null
*/
public function getLoc()
{
return $this->loc;
}
/**
* @param null $loc
*/
public function setLoc($loc)
{
$this->loc = $loc;
}
/**
* @return null
*/
public function getLastmod()
{
return $this->lastmod;
}
/**
* @param null $lastmod
*/
public function setLastmod($lastmod)
{
$this->lastmod = $lastmod;
}
/**
* @return bool
*/
public function isHide()
{
return $this->hide;
}
/**
* @param bool $hide
*/
public function setHide($hide)
{
$this->hide = $hide;
}
}

View File

@@ -0,0 +1,208 @@
<?php
/*************************************************************************************/
/* */
/* Copyright (c) Franck Allimant, CQFDev */
/* email : thelia@cqfdev.fr */
/* web : http://www.cqfdev.fr */
/* */
/* For the full copyright and license information, please view the LICENSE */
/* file that was distributed with this source code. */
/* */
/*************************************************************************************/
namespace Sitemap\EventListeners;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Sitemap\Model\Base\SitemapPriority;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Sitemap\Model\Map\SitemapPriorityTableMap;
use Sitemap\Model\SitemapPriorityQuery;
use Sitemap\Sitemap;
use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\Brand\BrandDeleteEvent;
use Thelia\Core\Event\Brand\BrandEvent;
use Thelia\Core\Event\Category\CategoryDeleteEvent;
use Thelia\Core\Event\Category\CategoryEvent;
use Thelia\Core\Event\Content\ContentDeleteEvent;
use Thelia\Core\Event\Content\ContentEvent;
use Thelia\Core\Event\File\FileCreateOrUpdateEvent;
use Thelia\Core\Event\Folder\FolderDeleteEvent;
use Thelia\Core\Event\Folder\FolderEvent;
use Thelia\Core\Event\Loop\LoopExtendsArgDefinitionsEvent;
use Thelia\Core\Event\Loop\LoopExtendsBuildModelCriteriaEvent;
use Thelia\Core\Event\Product\ProductDeleteEvent;
use Thelia\Core\Event\Product\ProductEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\TheliaFormEvent;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Map\BrandDocumentTableMap;
use Thelia\Model\Map\BrandImageTableMap;
use Thelia\Model\Map\BrandTableMap;
use Thelia\Model\Map\CategoryDocumentTableMap;
use Thelia\Model\Map\CategoryImageTableMap;
use Thelia\Model\Map\CategoryTableMap;
use Thelia\Model\Map\ContentDocumentTableMap;
use Thelia\Model\Map\ContentImageTableMap;
use Thelia\Model\Map\ContentTableMap;
use Thelia\Model\Map\FolderDocumentTableMap;
use Thelia\Model\Map\FolderImageTableMap;
use Thelia\Model\Map\FolderTableMap;
use Thelia\Model\Map\ProductDocumentTableMap;
use Thelia\Model\Map\ProductImageTableMap;
use Thelia\Model\Map\ProductSaleElementsProductImageTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Tools\URL;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;
class EventManager implements EventSubscriberInterface
{
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public static function getSubscribedEvents()
{
return [
TheliaEvents::PRODUCT_DELETE => [ 'deleteProduct' ],
TheliaEvents::CATEGORY_DELETE => [ 'deleteCategory' ],
TheliaEvents::CONTENT_DELETE => [ 'deleteContent' ],
TheliaEvents::FOLDER_DELETE => [ 'deleteFolder' ],
TheliaEvents::BRAND_DELETE => [ 'deleteBrand' ],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_product_creation" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_product_modification" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_content_creation" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_content_modification" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_category_creation" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_category_modification" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_folder_creation" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_folder_modification" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_brand_creation" => ['addFieldToForm', 128],
TheliaEvents::FORM_BEFORE_BUILD . ".thelia_brand_modification" => ['addFieldToForm', 128],
TheliaEvents::PRODUCT_UPDATE => ['processProductFields', 100],
TheliaEvents::PRODUCT_CREATE => ['processProductFields', 100],
TheliaEvents::CATEGORY_CREATE => ['processCategoryFields', 100],
TheliaEvents::CATEGORY_UPDATE => ['processCategoryFields', 100],
TheliaEvents::CONTENT_CREATE => ['processContentFields', 100],
TheliaEvents::CONTENT_UPDATE => ['processContentFields', 100],
TheliaEvents::FOLDER_CREATE => ['processFolderFields', 100],
TheliaEvents::FOLDER_UPDATE => ['processFolderFields', 100],
TheliaEvents::BRAND_CREATE => ['processBrandFields', 100],
TheliaEvents::BRAND_UPDATE => ['processBrandFields', 100],
];
}
public function addFieldToForm(TheliaFormEvent $event)
{
$event->getForm()->getFormBuilder()->add(
'sitemapPriority',
'text',
[
'required' => false,
'label' => Translator::getInstance()->trans(
'Sitemap priority',
[],
Sitemap::DOMAIN_NAME
),
'label_attr' => [
'help' => Translator::getInstance()->trans(
'Enter a decimal number between 0 and 1 that will define the importance of the page.',
[],
Sitemap::DOMAIN_NAME
)
]
]
);
}
public function processSitemap(ActionEvent $event, $source, $sourceId)
{
// Utilise le principe NON DOCUMENTE qui dit que si une form bindée à un event trouve
// un champ absent de l'event, elle le rend accessible à travers une méthode magique.
// (cf. ActionEvent::bindForm())
$sitemapPriority = SitemapPriorityQuery::create()
->filterBySource($source)
->filterBySourceId($sourceId)
->findOneOrCreate();
$sitemapValue = $event->sitemapPriority;
if (!empty($sitemapValue) && $sitemapPriority->getValue() !== $sitemapValue) {
$sitemapPriority
->setValue($sitemapValue)->save();
}
}
public function processProductFields(ProductEvent $event)
{
if ($event->hasProduct()) {
$this->processSitemap($event, 'product', $event->getProduct()->getId());
}
}
public function processCategoryFields(CategoryEvent $event)
{
if ($event->hasCategory()) {
$this->processSitemap($event, 'category', $event->getCategory()->getId());
}
}
public function processFolderFields(FolderEvent $event)
{
if ($event->hasFolder()) {
$this->processSitemap($event, 'folder', $event->getFolder()->getId());
}
}
public function processContentFields(ContentEvent $event)
{
if ($event->hasContent()) {
$this->processSitemap($event, 'content', $event->getContent()->getId());
}
}
public function processBrandFields(BrandEvent $event)
{
if ($event->hasBrand()) {
$this->processSitemap($event, 'brand', $event->getBrand()->getId());
}
}
public function deleteProduct(ProductDeleteEvent $event)
{
SitemapPriorityQuery::create()->filterBySource('product')->filterBySourceId($event->getProductId())->delete();
}
public function deleteCategory(CategoryDeleteEvent $event)
{
SitemapPriorityQuery::create()->filterBySource('category')->filterBySourceId($event->getCategoryId())->delete();
}
public function deleteContent(ContentDeleteEvent $event)
{
SitemapPriorityQuery::create()->filterBySource('content')->filterBySourceId($event->getContentId())->delete();
}
public function deleteFolder(FolderDeleteEvent $event)
{
SitemapPriorityQuery::create()->filterBySource('folder')->filterBySourceId($event->getFolderId())->delete();
}
public function deleteBrand(BrandDeleteEvent $event)
{
SitemapPriorityQuery::create()->filterBySource('brand')->filterBySourceId($event->getBrandId())->delete();
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace Sitemap\Form;
use Thelia\Form\BaseForm;
/**
* Class SitemapConfigForm
* @package Sitemap\Form
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class SitemapConfigForm extends BaseForm
{
public function getName()
{
return 'sitemap_config_form';
}
/**
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add(
'timeout',
'number',
['label' => $this->translator->trans('Script timeout (in seconds) for images generation (default: 30)', [], 'sitemap')]
)
->add(
'width',
'text',
['label' => $this->translator->trans('Image width', [], 'sitemap')]
)
->add(
'height',
'text',
['label' => $this->translator->trans('Image height', [], 'sitemap')]
)
->add(
'quality',
'text',
['label' => $this->translator->trans('Image quality', [], 'sitemap')]
)
->add(
'rotation',
'text',
['label' => $this->translator->trans('Image rotation', [], 'sitemap')]
)
->add(
'resize_mode',
'text',
['label' => $this->translator->trans('Image resize mode ([borders] / crop / none)', [], 'sitemap')]
)
->add(
'background_color',
'text',
['label' => $this->translator->trans('Image background color', [], 'sitemap')]
)
->add(
'allow_zoom',
'text',
['label' => $this->translator->trans('Allow image zoom ([false] / true)', [], 'sitemap')]
)
->add(
'exclude_empty_category',
'text',
['label' => $this->translator->trans('Do not include empty categories', [], 'sitemap')]
)
->add(
'exclude_empty_folder',
'text',
['label' => $this->translator->trans('Do not include empty folders', [], 'sitemap')]
)
->add(
'default_priority_homepage_value',
'text',
['label' => $this->translator->trans('Default home page priority', [], 'sitemap')]
)
->add(
'default_priority_brand_value',
'text',
['label' => $this->translator->trans('Default brand page priority', [], 'sitemap')]
)
->add(
'default_priority_category_value',
'text',
['label' => $this->translator->trans('Default category page priority', [], 'sitemap')]
)
->add(
'default_priority_product_value',
'text',
['label' => $this->translator->trans('Default product page priority', [], 'sitemap')]
)
->add(
'default_priority_folder_value',
'text',
['label' => $this->translator->trans('Default folder page priority', [], 'sitemap')]
)
->add(
'default_update_frequency',
'text',
['label' => $this->translator->trans('Default page update frequency (always / hourly / daily / weekly / monthly / yearly / never)', [], 'sitemap')]
)
;
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace Sitemap\Hook;
use Sitemap\Model\SitemapPriority;
use Sitemap\Model\SitemapPriority as SitemapPriorityModel;
use Sitemap\Model\SitemapPriorityQuery;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
use Sitemap\Sitemap;
/**
* Class SitemapHook
* @package Sitemap\Hook
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class SitemapHook extends BaseHook
{
private function processFieldHook(HookRenderEvent $event, $sourceType, $sourceId)
{
$sitemap = SitemapPriorityQuery::create()
->filterBySource($sourceType)
->filterBySourceId($sourceId)
->findOne();
switch ($sourceType) {
case 'brand':
$sitemapConfigValue = Sitemap::getConfigValue('default_priority_brand_value', SiteMap::DEFAULT_PRIORITY_BRAND_VALUE);
break;
case 'category':
$sitemapConfigValue = Sitemap::getConfigValue('default_priority_category_value', SiteMap::DEFAULT_PRIORITY_CATEGORY_VALUE);
break;
case 'product':
$sitemapConfigValue = Sitemap::getConfigValue('default_priority_product_value', SiteMap::DEFAULT_PRIORITY_PRODUCT_VALUE);
break;
case 'folder':
case 'content':
default:
$sitemapConfigValue = Sitemap::getConfigValue('default_priority_folder_value', SiteMap::DEFAULT_PRIORITY_FOLDER_VALUE);
break;
}
$sitemapValue = (null === $sitemap || empty($sitemap->getValue())) ? $sitemapConfigValue : $sitemap->getValue();
$event->add(
$this->render(
"generic-sitemap-definition.html",
[
'sitemapPriority' => $sitemapValue
]
)
);
}
public function onModuleConfig(HookRenderEvent $event)
{
$event->add($this->render('sitemap-configuration.html'));
}
public function onProductEditRightColumnBottom(HookRenderEvent $event)
{
$this->processFieldHook($event, 'product', $event->getArgument('product_id'));
}
public function onCategoryEditRightColumnBottom(HookRenderEvent $event)
{
$this->processFieldHook($event, 'category', $event->getArgument('category_id'));
}
public function onContentEditRightColumnBottom(HookRenderEvent $event)
{
$this->processFieldHook($event, 'content', $event->getArgument('content_id'));
}
public function onFolderEditRightColumnBottom(HookRenderEvent $event)
{
$this->processFieldHook($event, 'folder', $event->getArgument('folder_id'));
}
public function onBrandEditRightColumnBottom(HookRenderEvent $event)
{
$this->processFieldHook($event, 'brand', $event->getArgument('brand_id'));
}
}

View File

@@ -0,0 +1,12 @@
<?php
return array(
'<b>Warning!</b> Only fill this input with a greater value than 30 if you have so many images that the sitemap-image can\'t be generated because of timeout.' => '<b>Warning!</b> Only fill this input with a greater value than 30 if you have so many images that the sitemap-image can\'t be generated because of timeout.',
'Configuration correctly saved' => 'Configuration correctly saved',
'Configure sitemap images' => 'Configure sitemap images',
'Depending on your server, this may have no effect.' => 'Depending on your server, this may have no effect.',
'Home' => 'Home',
'Modules' => 'Modules',
'Set the same information as in your product image loop' => 'Set the same information as in your product image loop',
'Sitemap images configuration' => 'Sitemap images configuration',
);

View File

@@ -0,0 +1,13 @@
<?php
return array(
'<b>Warning!</b> Only fill this input with a greater value than 30 if you have so many images that the sitemap-image can\'t be generated because of timeout.' => '<b>Attention !</b> Ne remplissez ce champ avec une valeur plus grande que 30 que si vous avez beaucoup d\'images et que le sitemap-image n\'arrive pas à se générer.',
'Configuration correctly saved' => 'Configuration sauvegardée avec succès',
'Configure sitemap' => 'Configurer le sitemap',
'Configure sitemap images' => 'Configurer les images du sitemap',
'Depending on your server, this may have no effect.' => 'En fonction de votre serveur, cela pourrait n\'avoir aucun effet.',
'Home' => 'Accueil',
'Modules' => 'Modules',
'Set the same information as in your product image loop' => 'Entrez les mêmes informations que dans la boucle image des produits',
'Sitemap images configuration' => 'Configuration des images du module Sitemap',
);

View File

@@ -0,0 +1,21 @@
<?php
return array(
'Allow image zoom ([false] / true)' => 'Allow image zoom ([false] / true)',
'Image background color' => 'Image background color',
'Image height' => 'Image height',
'Image quality' => 'Image quality',
'Image resize mode ([borders] / crop / none)' => 'Image resize mode ([borders] / crop / none)',
'Image rotation' => 'Image rotation',
'Image width' => 'Image width',
'Script timeout (in seconds) for images generation (default: 30)' => 'Script timeout (in seconds) for images generation (default: 30)',
'Sorry, an error occurred: %err' => 'Sorry, an error occurred: %err',
'Sitemap priority' => 'Sitemap priority',
'Default home page priority' => 'Default home page priority',
'Default folder page priority' => 'Default folder page priority',
'Default category page priority' => 'Default category page priority',
'Default product page priority' => 'Default product page priority',
'Default brand page priority' => 'Default brand page priority',
'Default page update frequency (always / hourly / daily / weekly / monthly / yearly / never)' => 'Default page update frequency (always / hourly / daily / weekly / monthly / yearly / never)',
'Enter a decimal number between 0 and 1 that will define the importance of the page.' => 'Enter a decimal number between 0 and 1 that will define the importance of the page.',
);

View File

@@ -0,0 +1,23 @@
<?php
return array(
'Allow image zoom ([false] / true)' => 'Autoriser le zoom des images ([false] / true)',
'Do not include empty categories' => 'Ne pas inclure les catégories vides',
'Do not include empty folders' => 'Ne pas inclure les dossiers vides',
'Image background color' => 'Couleur de fond des images',
'Image height' => 'Hauteur des images',
'Image quality' => 'Qualité des images',
'Image resize mode ([borders] / crop / none)' => 'Mode de redimensionnement des images ([borders] / crop / none)',
'Image rotation' => 'Rotation des images',
'Image width' => 'Largeur des images',
'Script timeout (in seconds) for images generation (default: 30)' => 'Temps maximum d\'exécution (en secondes) pour la génération des images (par défaut : 30)',
'Sorry, an error occurred: %err' => 'Désolé, une erreur s\'est produite : %err',
'Default home page priority' => 'Priorité par défaut des pages d\'accueil',
'Default folder page priority' => 'Priorité par défaut des pages dossiers',
'Default category page priority' => 'Priorité par défaut des pages catégories',
'Default product page priority' => 'Priorité par défaut des pages produits',
'Default brand page priority' => 'Priorité par défaut des pages marques',
'Default page update frequency (always / hourly / daily / weekly / monthly / yearly / never)' => 'Fréquence de mise à jour par défaut des pages (always / hourly / daily / weekly / monthly / yearly / never)',
'Sitemap priority' => 'Sitemap priorité',
'Enter a decimal number between 0 and 1 that will define the importance of the page.' => 'Indiquez un nombre décimal entre 0 et 1 qui définira l\'importance de la page.',
);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,627 @@
<?php
namespace Sitemap\Model\Base;
use \Exception;
use \PDO;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Sitemap\Model\SitemapPriority as ChildSitemapPriority;
use Sitemap\Model\SitemapPriorityQuery as ChildSitemapPriorityQuery;
use Sitemap\Model\Map\SitemapPriorityTableMap;
/**
* Base class that represents a query for the 'sitemap_priority' table.
*
*
*
* @method ChildSitemapPriorityQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildSitemapPriorityQuery orderByValue($order = Criteria::ASC) Order by the value column
* @method ChildSitemapPriorityQuery orderBySource($order = Criteria::ASC) Order by the source column
* @method ChildSitemapPriorityQuery orderBySourceId($order = Criteria::ASC) Order by the source_id column
* @method ChildSitemapPriorityQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildSitemapPriorityQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
* @method ChildSitemapPriorityQuery groupById() Group by the id column
* @method ChildSitemapPriorityQuery groupByValue() Group by the value column
* @method ChildSitemapPriorityQuery groupBySource() Group by the source column
* @method ChildSitemapPriorityQuery groupBySourceId() Group by the source_id column
* @method ChildSitemapPriorityQuery groupByCreatedAt() Group by the created_at column
* @method ChildSitemapPriorityQuery groupByUpdatedAt() Group by the updated_at column
*
* @method ChildSitemapPriorityQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildSitemapPriorityQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildSitemapPriorityQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildSitemapPriority findOne(ConnectionInterface $con = null) Return the first ChildSitemapPriority matching the query
* @method ChildSitemapPriority findOneOrCreate(ConnectionInterface $con = null) Return the first ChildSitemapPriority matching the query, or a new ChildSitemapPriority object populated from the query conditions when no match is found
*
* @method ChildSitemapPriority findOneById(int $id) Return the first ChildSitemapPriority filtered by the id column
* @method ChildSitemapPriority findOneByValue(double $value) Return the first ChildSitemapPriority filtered by the value column
* @method ChildSitemapPriority findOneBySource(string $source) Return the first ChildSitemapPriority filtered by the source column
* @method ChildSitemapPriority findOneBySourceId(int $source_id) Return the first ChildSitemapPriority filtered by the source_id column
* @method ChildSitemapPriority findOneByCreatedAt(string $created_at) Return the first ChildSitemapPriority filtered by the created_at column
* @method ChildSitemapPriority findOneByUpdatedAt(string $updated_at) Return the first ChildSitemapPriority filtered by the updated_at column
*
* @method array findById(int $id) Return ChildSitemapPriority objects filtered by the id column
* @method array findByValue(double $value) Return ChildSitemapPriority objects filtered by the value column
* @method array findBySource(string $source) Return ChildSitemapPriority objects filtered by the source column
* @method array findBySourceId(int $source_id) Return ChildSitemapPriority objects filtered by the source_id column
* @method array findByCreatedAt(string $created_at) Return ChildSitemapPriority objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildSitemapPriority objects filtered by the updated_at column
*
*/
abstract class SitemapPriorityQuery extends ModelCriteria
{
/**
* Initializes internal state of \Sitemap\Model\Base\SitemapPriorityQuery 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 = '\\Sitemap\\Model\\SitemapPriority', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildSitemapPriorityQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildSitemapPriorityQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \Sitemap\Model\SitemapPriorityQuery) {
return $criteria;
}
$query = new \Sitemap\Model\SitemapPriorityQuery();
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 ChildSitemapPriority|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = SitemapPriorityTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(SitemapPriorityTableMap::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 ChildSitemapPriority A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, VALUE, SOURCE, SOURCE_ID, CREATED_AT, UPDATED_AT FROM sitemap_priority 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 ChildSitemapPriority();
$obj->hydrate($row);
SitemapPriorityTableMap::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 ChildSitemapPriority|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 ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
return $this->addUsingAlias(SitemapPriorityTableMap::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 ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
return $this->addUsingAlias(SitemapPriorityTableMap::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 ChildSitemapPriorityQuery 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(SitemapPriorityTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(SitemapPriorityTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SitemapPriorityTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the value column
*
* Example usage:
* <code>
* $query->filterByValue(1234); // WHERE value = 1234
* $query->filterByValue(array(12, 34)); // WHERE value IN (12, 34)
* $query->filterByValue(array('min' => 12)); // WHERE value > 12
* </code>
*
* @param mixed $value 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 ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function filterByValue($value = null, $comparison = null)
{
if (is_array($value)) {
$useMinMax = false;
if (isset($value['min'])) {
$this->addUsingAlias(SitemapPriorityTableMap::VALUE, $value['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($value['max'])) {
$this->addUsingAlias(SitemapPriorityTableMap::VALUE, $value['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SitemapPriorityTableMap::VALUE, $value, $comparison);
}
/**
* Filter the query on the source column
*
* Example usage:
* <code>
* $query->filterBySource('fooValue'); // WHERE source = 'fooValue'
* $query->filterBySource('%fooValue%'); // WHERE source LIKE '%fooValue%'
* </code>
*
* @param string $source 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 ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function filterBySource($source = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($source)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $source)) {
$source = str_replace('*', '%', $source);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(SitemapPriorityTableMap::SOURCE, $source, $comparison);
}
/**
* Filter the query on the source_id column
*
* Example usage:
* <code>
* $query->filterBySourceId(1234); // WHERE source_id = 1234
* $query->filterBySourceId(array(12, 34)); // WHERE source_id IN (12, 34)
* $query->filterBySourceId(array('min' => 12)); // WHERE source_id > 12
* </code>
*
* @param mixed $sourceId 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 ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function filterBySourceId($sourceId = null, $comparison = null)
{
if (is_array($sourceId)) {
$useMinMax = false;
if (isset($sourceId['min'])) {
$this->addUsingAlias(SitemapPriorityTableMap::SOURCE_ID, $sourceId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($sourceId['max'])) {
$this->addUsingAlias(SitemapPriorityTableMap::SOURCE_ID, $sourceId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SitemapPriorityTableMap::SOURCE_ID, $sourceId, $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 ChildSitemapPriorityQuery 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(SitemapPriorityTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($createdAt['max'])) {
$this->addUsingAlias(SitemapPriorityTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SitemapPriorityTableMap::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 ChildSitemapPriorityQuery 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(SitemapPriorityTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($updatedAt['max'])) {
$this->addUsingAlias(SitemapPriorityTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(SitemapPriorityTableMap::UPDATED_AT, $updatedAt, $comparison);
}
/**
* Exclude object from result
*
* @param ChildSitemapPriority $sitemapPriority Object to remove from the list of results
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function prune($sitemapPriority = null)
{
if ($sitemapPriority) {
$this->addUsingAlias(SitemapPriorityTableMap::ID, $sitemapPriority->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
/**
* Deletes all rows from the sitemap_priority 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(SitemapPriorityTableMap::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).
SitemapPriorityTableMap::clearInstancePool();
SitemapPriorityTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildSitemapPriority or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildSitemapPriority 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(SitemapPriorityTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(SitemapPriorityTableMap::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();
SitemapPriorityTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
SitemapPriorityTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
// timestampable behavior
/**
* Filter by the latest updated
*
* @param int $nbDays Maximum age of the latest update in days
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function recentlyUpdated($nbDays = 7)
{
return $this->addUsingAlias(SitemapPriorityTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Filter by the latest created
*
* @param int $nbDays Maximum age of in days
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function recentlyCreated($nbDays = 7)
{
return $this->addUsingAlias(SitemapPriorityTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
}
/**
* Order by update date desc
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function lastUpdatedFirst()
{
return $this->addDescendingOrderByColumn(SitemapPriorityTableMap::UPDATED_AT);
}
/**
* Order by update date asc
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function firstUpdatedFirst()
{
return $this->addAscendingOrderByColumn(SitemapPriorityTableMap::UPDATED_AT);
}
/**
* Order by create date desc
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function lastCreatedFirst()
{
return $this->addDescendingOrderByColumn(SitemapPriorityTableMap::CREATED_AT);
}
/**
* Order by create date asc
*
* @return ChildSitemapPriorityQuery The current query, for fluid interface
*/
public function firstCreatedFirst()
{
return $this->addAscendingOrderByColumn(SitemapPriorityTableMap::CREATED_AT);
}
} // SitemapPriorityQuery

View File

@@ -0,0 +1,455 @@
<?php
namespace Sitemap\Model\Map;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\InstancePoolTrait;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\DataFetcher\DataFetcherInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Map\RelationMap;
use Propel\Runtime\Map\TableMap;
use Propel\Runtime\Map\TableMapTrait;
use Sitemap\Model\SitemapPriority;
use Sitemap\Model\SitemapPriorityQuery;
/**
* This class defines the structure of the 'sitemap_priority' table.
*
*
*
* This map class is used by Propel to do runtime db structure discovery.
* For example, the createSelectSql() method checks the type of a given column used in an
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
* (i.e. if it's a text column type).
*
*/
class SitemapPriorityTableMap extends TableMap
{
use InstancePoolTrait;
use TableMapTrait;
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'Sitemap.Model.Map.SitemapPriorityTableMap';
/**
* The default database name for this class
*/
const DATABASE_NAME = 'thelia';
/**
* The table name for this class
*/
const TABLE_NAME = 'sitemap_priority';
/**
* The related Propel class for this table
*/
const OM_CLASS = '\\Sitemap\\Model\\SitemapPriority';
/**
* A class that can be returned by this tableMap
*/
const CLASS_DEFAULT = 'Sitemap.Model.SitemapPriority';
/**
* The total number of columns
*/
const NUM_COLUMNS = 6;
/**
* The number of lazy-loaded columns
*/
const NUM_LAZY_LOAD_COLUMNS = 0;
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 6;
/**
* the column name for the ID field
*/
const ID = 'sitemap_priority.ID';
/**
* the column name for the VALUE field
*/
const VALUE = 'sitemap_priority.VALUE';
/**
* the column name for the SOURCE field
*/
const SOURCE = 'sitemap_priority.SOURCE';
/**
* the column name for the SOURCE_ID field
*/
const SOURCE_ID = 'sitemap_priority.SOURCE_ID';
/**
* the column name for the CREATED_AT field
*/
const CREATED_AT = 'sitemap_priority.CREATED_AT';
/**
* the column name for the UPDATED_AT field
*/
const UPDATED_AT = 'sitemap_priority.UPDATED_AT';
/**
* The default string format for model objects of the related table
*/
const DEFAULT_STRING_FORMAT = 'YAML';
/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'Value', 'Source', 'SourceId', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('id', 'value', 'source', 'sourceId', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(SitemapPriorityTableMap::ID, SitemapPriorityTableMap::VALUE, SitemapPriorityTableMap::SOURCE, SitemapPriorityTableMap::SOURCE_ID, SitemapPriorityTableMap::CREATED_AT, SitemapPriorityTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('ID', 'VALUE', 'SOURCE', 'SOURCE_ID', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('id', 'value', 'source', 'source_id', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
);
/**
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'Value' => 1, 'Source' => 2, 'SourceId' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'value' => 1, 'source' => 2, 'sourceId' => 3, 'createdAt' => 4, 'updatedAt' => 5, ),
self::TYPE_COLNAME => array(SitemapPriorityTableMap::ID => 0, SitemapPriorityTableMap::VALUE => 1, SitemapPriorityTableMap::SOURCE => 2, SitemapPriorityTableMap::SOURCE_ID => 3, SitemapPriorityTableMap::CREATED_AT => 4, SitemapPriorityTableMap::UPDATED_AT => 5, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'VALUE' => 1, 'SOURCE' => 2, 'SOURCE_ID' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ),
self::TYPE_FIELDNAME => array('id' => 0, 'value' => 1, 'source' => 2, 'source_id' => 3, 'created_at' => 4, 'updated_at' => 5, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
);
/**
* Initialize the table attributes and columns
* Relations are not initialized by this method since they are lazy loaded
*
* @return void
* @throws PropelException
*/
public function initialize()
{
// attributes
$this->setName('sitemap_priority');
$this->setPhpName('SitemapPriority');
$this->setClassName('\\Sitemap\\Model\\SitemapPriority');
$this->setPackage('Sitemap.Model');
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('VALUE', 'Value', 'FLOAT', false, null, null);
$this->addColumn('SOURCE', 'Source', 'VARCHAR', false, 64, null);
$this->addColumn('SOURCE_ID', 'SourceId', 'INTEGER', false, null, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
/**
* Build the RelationMap objects for this table relationships
*/
public function buildRelations()
{
} // buildRelations()
/**
*
* Gets the list of behaviors registered for this table
*
* @return array Associative array (name => parameters) of behaviors
*/
public function getBehaviors()
{
return array(
'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ),
);
} // getBehaviors()
/**
* Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
*
* For tables with a single-column primary key, that simple pkey value will be returned. For tables with
* a multi-column primary key, a serialize()d version of the primary key will be returned.
*
* @param array $row resultset row.
* @param int $offset The 0-based offset for reading from the resultset row.
* @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
*/
public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
// If the PK cannot be derived from the row, return NULL.
if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) {
return null;
}
return (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)];
}
/**
* Retrieves the primary key from the DB resultset row
* For tables with a single-column primary key, that simple pkey value will be returned. For tables with
* a multi-column primary key, an array of the primary key columns will be returned.
*
* @param array $row resultset row.
* @param int $offset The 0-based offset for reading from the resultset row.
* @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
*
* @return mixed The primary key of the row
*/
public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
return (int) $row[
$indexType == TableMap::TYPE_NUM
? 0 + $offset
: self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)
];
}
/**
* The class that the tableMap will make instances of.
*
* If $withPrefix is true, the returned path
* uses a dot-path notation which is translated into a path
* relative to a location on the PHP include_path.
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
*
* @param boolean $withPrefix Whether or not to return the path with the class name
* @return string path.to.ClassName
*/
public static function getOMClass($withPrefix = true)
{
return $withPrefix ? SitemapPriorityTableMap::CLASS_DEFAULT : SitemapPriorityTableMap::OM_CLASS;
}
/**
* Populates an object of the default type or an object that inherit from the default.
*
* @param array $row row returned by DataFetcher->fetch().
* @param int $offset The 0-based offset for reading from the resultset row.
* @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType().
One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return array (SitemapPriority object, last column rank)
*/
public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
$key = SitemapPriorityTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
if (null !== ($obj = SitemapPriorityTableMap::getInstanceFromPool($key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// $obj->hydrate($row, $offset, true); // rehydrate
$col = $offset + SitemapPriorityTableMap::NUM_HYDRATE_COLUMNS;
} else {
$cls = SitemapPriorityTableMap::OM_CLASS;
$obj = new $cls();
$col = $obj->hydrate($row, $offset, false, $indexType);
SitemapPriorityTableMap::addInstanceToPool($obj, $key);
}
return array($obj, $col);
}
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @param DataFetcherInterface $dataFetcher
* @return array
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(DataFetcherInterface $dataFetcher)
{
$results = array();
// set the class once to avoid overhead in the loop
$cls = static::getOMClass(false);
// populate the object(s)
while ($row = $dataFetcher->fetch()) {
$key = SitemapPriorityTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
if (null !== ($obj = SitemapPriorityTableMap::getInstanceFromPool($key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// $obj->hydrate($row, 0, true); // rehydrate
$results[] = $obj;
} else {
$obj = new $cls();
$obj->hydrate($row);
$results[] = $obj;
SitemapPriorityTableMap::addInstanceToPool($obj, $key);
} // if key exists
}
return $results;
}
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad="true" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param Criteria $criteria object containing the columns to add.
* @param string $alias optional table alias
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(SitemapPriorityTableMap::ID);
$criteria->addSelectColumn(SitemapPriorityTableMap::VALUE);
$criteria->addSelectColumn(SitemapPriorityTableMap::SOURCE);
$criteria->addSelectColumn(SitemapPriorityTableMap::SOURCE_ID);
$criteria->addSelectColumn(SitemapPriorityTableMap::CREATED_AT);
$criteria->addSelectColumn(SitemapPriorityTableMap::UPDATED_AT);
} else {
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.VALUE');
$criteria->addSelectColumn($alias . '.SOURCE');
$criteria->addSelectColumn($alias . '.SOURCE_ID');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}
}
/**
* Returns the TableMap related to this object.
* This method is not needed for general use but a specific application could have a need.
* @return TableMap
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getTableMap()
{
return Propel::getServiceContainer()->getDatabaseMap(SitemapPriorityTableMap::DATABASE_NAME)->getTable(SitemapPriorityTableMap::TABLE_NAME);
}
/**
* Add a TableMap instance to the database for this tableMap class.
*/
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(SitemapPriorityTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(SitemapPriorityTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new SitemapPriorityTableMap());
}
}
/**
* Performs a DELETE on the database, given a SitemapPriority or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or SitemapPriority 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 static function doDelete($values, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(SitemapPriorityTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \Sitemap\Model\SitemapPriority) { // it's a model object
// create criteria based on pk values
$criteria = $values->buildPkeyCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(SitemapPriorityTableMap::DATABASE_NAME);
$criteria->add(SitemapPriorityTableMap::ID, (array) $values, Criteria::IN);
}
$query = SitemapPriorityQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) { SitemapPriorityTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) { SitemapPriorityTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
}
/**
* Deletes all rows from the sitemap_priority table.
*
* @param ConnectionInterface $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
*/
public static function doDeleteAll(ConnectionInterface $con = null)
{
return SitemapPriorityQuery::create()->doDeleteAll($con);
}
/**
* Performs an INSERT on the database, given a SitemapPriority or Criteria object.
*
* @param mixed $criteria Criteria or SitemapPriority object containing data that is used to create the INSERT statement.
* @param ConnectionInterface $con the ConnectionInterface connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(SitemapPriorityTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from SitemapPriority object
}
if ($criteria->containsKey(SitemapPriorityTableMap::ID) && $criteria->keyContainsValue(SitemapPriorityTableMap::ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.SitemapPriorityTableMap::ID.')');
}
// Set the correct dbName
$query = SitemapPriorityQuery::create()->mergeWith($criteria);
try {
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
$con->beginTransaction();
$pk = $query->doInsert($con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $pk;
}
} // SitemapPriorityTableMap
// This is the static code needed to register the TableMap for this table with the main Propel class.
//
SitemapPriorityTableMap::buildTableMap();

View File

@@ -0,0 +1,10 @@
<?php
namespace Sitemap\Model;
use Sitemap\Model\Base\SitemapPriority as BaseSitemapPriority;
class SitemapPriority extends BaseSitemapPriority
{
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Sitemap\Model;
use Sitemap\Model\Base\SitemapPriorityQuery as BaseSitemapPriorityQuery;
/**
* Skeleton subclass for performing query and update operations on the 'sitemap_priority' 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 SitemapPriorityQuery extends BaseSitemapPriorityQuery
{
} // SitemapPriorityQuery

View File

@@ -0,0 +1,30 @@
# Sitemap
Generate sitemaps faster than Thelia default ones.
## Installation
### Manually
* Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is Sitemap.
* Activate it in your thelia administration panel
### Composer
Add it in your main thelia composer.json file
```
composer require thelia/sitemap-module:~1.4.0
```
## Usage
Configure the module with the same information as in you product image loop.
If you have a lot of products with images, change the timeout in the configuration. **However, be aware** that it may not work depending on your server.
The sitemap will be filled with all your categories, products, folders and contents URLs, depending on the language.
The sitemap-image will be filled with all your product images (1 by product) URLs, depending on the language.
The module will be used to generate sitemap when going on http://yourSite.com/sitemap and the sitemap-image on http://yourSite.com/sitemap-image.

View File

@@ -0,0 +1,72 @@
<?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 Sitemap;
use Propel\Runtime\Connection\ConnectionInterface;
use Sitemap\Model\SitemapPriority;
use Sitemap\Model\SitemapPriorityQuery;
use Symfony\Component\Finder\Finder;
use Thelia\Install\Database;
use Thelia\Module\BaseModule;
class Sitemap extends BaseModule
{
/** @var string */
const DOMAIN_NAME = 'sitemap';
const DEFAULT_PRIORITY_HOME_VALUE = 1;
const DEFAULT_PRIORITY_BRAND_VALUE = 0.6;
const DEFAULT_PRIORITY_CATEGORY_VALUE = 0.9;
const DEFAULT_PRIORITY_PRODUCT_VALUE = 0.8;
const DEFAULT_PRIORITY_FOLDER_VALUE = 0.6;
const DEFAULT_FREQUENCY_UPDATE = 'weekly';
public function postActivation(ConnectionInterface $con = null)
{
try {
SitemapPriorityQuery::create()->findOne();
} catch (\Exception $ex) {
$database = new Database($con->getWrappedConnection());
$database->insertSql(null, array(__DIR__ . '/Config/thelia.sql'));
}
}
public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
{
$finder = (new Finder)
->files()
->name('#.*?\.sql#')
->sortByName()
->in(__DIR__ . DS . 'Config' . DS . 'update' . DS . 'sql');
$database = new Database($con);
/** @var \Symfony\Component\Finder\SplFileInfo $updateSQLFile */
foreach ($finder as $updateSQLFile) {
if (version_compare($currentVersion, str_replace('.sql', '', $updateSQLFile->getFilename()), '<')) {
$database->insertSql(
null,
[
$updateSQLFile->getPathname()
]
);
}
}
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "thelia/sitemap-module",
"license": "LGPL-3.0+",
"type": "thelia-module",
"require": {
"thelia/installer": "~1.1"
},
"extra": {
"installer-name": "Sitemap"
}
}

View File

@@ -0,0 +1 @@
{render_form_field form=$form field="sitemapPriority" value=$sitemapPriority}

View File

@@ -0,0 +1,290 @@
{extends file="admin-layout.tpl"}
{block name="no-return-functions"}
{$admin_current_location = 'modules'}
{/block}
{block name="page-title"}{intl d="sitemap.bo.default" l='Sitemap images configuration'}{/block}
{block name="check-resource"}admin.module{/block}
{block name="check-access"}view{/block}
{block name="check-module"}Sitemap{/block}
{block name="main-content"}
<div class="container" id="wrapper">
<ul class="breadcrumb">
<li><a href="{url path='/admin'}">{intl l="Home" d="sitemap.bo.default"}</a></li>
<li><a href="{url path='/admin/modules'}">{intl l="Modules" d="sitemap.bo.default"}</a></li>
<li>{intl l="Sitemap images configuration" d="sitemap.bo.default"}</li>
</ul>
<div class="general-block-decorator">
<div class="row">
<div class="col-md-12">
{if $success}
<div class="alert alert-success">
{intl l="Configuration correctly saved" d="sitemap.bo.default"}
</div>
{/if}
{form name='sitemap_config_form'}
<form method="post" action="{url path='/admin/module/Sitemap'}">
{form_hidden_fields form=$form}
{include "includes/inner-form-toolbar.html" hide_flags=true close_url={url path='/admin/modules'}}
<div class="title title-without-tabs">
<h2>{intl l="Configure sitemap" d="sitemap.bo.default"}</h2>
</div>
{form_field form=$form field="exclude_empty_category"}
<div class="{if $error}has-error{/if}">
{form_error form=$form field="width"}
<span class="error">{$message}</span>
{/form_error}
<label for="{$name}">
<input type="checkbox" id="{$name}" name="{$name}" {if $value == 1}checked{/if} value="1"/>
{$label}
</label>
</div>
{/form_field}
{form_field form=$form field="exclude_empty_folder"}
<div class="{if $error}has-error{/if}">
{form_error form=$form field="width"}
<span class="error">{$message}</span>
{/form_error}
<label for="{$name}">
<input type="checkbox" id="{$name}" name="{$name}" {if $value == 1}checked{/if} value="1"/>
{$label}
</label>
</div>
{/form_field}
<div class="title title-without-tabs">
<h2>{intl l="Configure sitemap images" d="sitemap.bo.default"}</h2>
</div>
<div class="alert alert-warning">{intl l="Set the same information as in your product image loop" d="sitemap.bo.default"}.</div>
{form_field form=$form field="timeout"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="timeout"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<p>{intl l='<b>Warning!</b> Only fill this input with a greater value than 30 if you have so many images that the sitemap-image can\'t be generated because of timeout.' d='sitemap.bo.default'}</p>
<p>{intl l='Depending on your server, this may have no effect.' d="sitemap.bo.default"}</p>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="width"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="width"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="height"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="height"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="quality"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="quality"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="rotation"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="rotation"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="resize_mode"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="resize_mode"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="background_color"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="background_color"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="allow_zoom"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="allow_zoom"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="default_priority_homepage_value"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="default_priority_homepage_value"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="number" step="0.1" min="0" max="1" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="default_priority_brand_value"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="default_priority_brand_value"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="number" step="0.1" min="0" max="1" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="default_priority_category_value"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="default_priority_category_value"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="number" step="0.1" min="0" max="1" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="default_priority_product_value"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="default_priority_product_value"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="number" step="0.1" min="0" max="1" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="default_priority_folder_value"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="default_priority_folder_value"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="number" step="0.1" min="0" max="1" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="default_update_frequency"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="default_update_frequency"}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
</form>
{/form}
</div>
</div>
</div>
</div>
{/block}