This commit is contained in:
Franck Allimant
2013-10-31 16:46:20 +01:00
11 changed files with 459 additions and 301 deletions

View File

@@ -9,6 +9,18 @@
<default key="_controller">Thelia\Controller\Admin\AdminController::indexAction</default>
</route>
<!-- home -->
<route id="admin.home.view" path="/admin/home">
<default key="_controller">Thelia\Controller\Admin\HomeController::defaultAction</default>
</route>
<route id="admin.home.stats" path="/admin/home/stats">
<default key="_controller">Thelia\Controller\Admin\HomeController::loadStatsAjaxAction</default>
</route>
<!-- end home -->
<!-- Route to the administration login page -->
<route id="admin.login" path="/admin/login">
<default key="_controller">Thelia\Controller\Admin\SessionController::showLoginAction</default>

View File

@@ -0,0 +1,62 @@
<?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">
<parameters>
<parameter key="translation.loader.php.class">Symfony\Component\Translation\Loader\PhpFileLoader</parameter>
<parameter key="translation.loader.yml.class">Symfony\Component\Translation\Loader\YamlFileLoader</parameter>
<parameter key="translation.loader.xliff.class">Symfony\Component\Translation\Loader\XliffFileLoader</parameter>
<parameter key="translation.loader.po.class">Symfony\Component\Translation\Loader\PoFileLoader</parameter>
<parameter key="translation.loader.mo.class">Symfony\Component\Translation\Loader\MoFileLoader</parameter>
<parameter key="translation.loader.qt.class">Symfony\Component\Translation\Loader\QtFileLoader</parameter>
<parameter key="translation.loader.csv.class">Symfony\Component\Translation\Loader\CsvFileLoader</parameter>
<parameter key="translation.loader.res.class">Symfony\Component\Translation\Loader\IcuResFileLoader</parameter>
<parameter key="translation.loader.dat.class">Symfony\Component\Translation\Loader\IcuDatFileLoader</parameter>
<parameter key="translation.loader.ini.class">Symfony\Component\Translation\Loader\IniFileLoader</parameter>
</parameters>
<services>
<service id="translation.loader.php" class="%translation.loader.php.class%">
<tag name="translation.loader" alias="php" />
</service>
<service id="translation.loader.yml" class="%translation.loader.yml.class%">
<tag name="translation.loader" alias="yml" legacy-alias="yaml" />
</service>
<service id="translation.loader.xliff" class="%translation.loader.xliff.class%">
<tag name="translation.loader" alias="xlf" legacy-alias="xliff" />
</service>
<service id="translation.loader.po" class="%translation.loader.po.class%">
<tag name="translation.loader" alias="po" />
</service>
<service id="translation.loader.mo" class="%translation.loader.mo.class%">
<tag name="translation.loader" alias="mo" />
</service>
<service id="translation.loader.qt" class="%translation.loader.qt.class%">
<tag name="translation.loader" alias="ts" />
</service>
<service id="translation.loader.csv" class="%translation.loader.csv.class%">
<tag name="translation.loader" alias="csv" />
</service>
<service id="translation.loader.res" class="%translation.loader.res.class%">
<tag name="translation.loader" alias="res" />
</service>
<service id="translation.loader.dat" class="%translation.loader.res.class%">
<tag name="translation.loader" alias="dat" />
</service>
<service id="translation.loader.ini" class="%translation.loader.ini.class%">
<tag name="translation.loader" alias="ini" />
</service>
</services>
</config>

View File

@@ -0,0 +1,102 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Security\AccessManager;
use Thelia\Model\CustomerQuery;
use Thelia\Model\OrderQuery;
class HomeController extends BaseAdminController
{
const RESOURCE_CODE = "admin.home";
public function defaultAction()
{
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
// Render the edition template.
return $this->render('home');
}
public function loadStatsAjaxAction()
{
$data = new \stdClass();
$data->title = "Stats on " . $this->getRequest()->query->get('month', date('m')) . "/" . $this->getRequest()->query->get('year', date('Y'));
/* sales */
$saleSeries = new \stdClass();
$saleSeries->color = $this->getRequest()->query->get('sales_color', '#adadad');
$saleSeries->data = OrderQuery::getSaleStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* new customers */
$newCustomerSeries = new \stdClass();
$newCustomerSeries->color = $this->getRequest()->query->get('customers_color', '#f39922');
$newCustomerSeries->data = CustomerQuery::getNewCustomersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* orders */
$orderSeries = new \stdClass();
$orderSeries->color = $this->getRequest()->query->get('orders_color', '#5cb85c');
$orderSeries->data = OrderQuery::getOrdersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* first order */
$firstOrderSeries = new \stdClass();
$firstOrderSeries->color = $this->getRequest()->query->get('first_orders_color', '#5bc0de');
$firstOrderSeries->data = OrderQuery::getFirstOrdersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y'))
);
/* cancelled orders */
$cancelledOrderSeries = new \stdClass();
$cancelledOrderSeries->color = $this->getRequest()->query->get('cancelled_orders_color', '#d9534f');
$cancelledOrderSeries->data = OrderQuery::getOrdersStats(
$this->getRequest()->query->get('month', date('m')),
$this->getRequest()->query->get('year', date('Y')),
array(5)
);
$data->series = array(
$saleSeries,
$newCustomerSeries,
$orderSeries,
$firstOrderSeries,
$cancelledOrderSeries,
);
$json = json_encode($data);
return $this->jsonResponse($json);
}
}

View File

@@ -31,6 +31,7 @@ use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterParserPluginPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterRouterPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterCouponConditionPass;
use Thelia\Core\DependencyInjection\Compiler\TranslatorPass;
/**
* First Bundle use in Thelia
@@ -63,6 +64,9 @@ class TheliaBundle extends Bundle
->addCompilerPass(new RegisterParserPluginPass())
->addCompilerPass(new RegisterRouterPass())
->addCompilerPass(new RegisterCouponPass())
->addCompilerPass(new RegisterCouponConditionPass());
->addCompilerPass(new RegisterCouponConditionPass())
->addCompilerPass(new TranslatorPass())
;
}
}

View File

@@ -24,6 +24,7 @@
namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
@@ -49,8 +50,11 @@ class TranslatorPass implements CompilerPassInterface
$translator = $container->getDefinition('thelia.translator');
foreach($container->findTaggedServiceIds('translator.loader') as $id => $attributes) {
foreach($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
$translator->addMethodCall('addLoader', array($attributes[0]['alias'], new Reference($id)));
if (isset($attributes[0]['legacy-alias'])) {
$translator->addMethodCall('addLoader', array($attributes[0]['legacy-alias'], new Reference($id)));
}
}
}
}

View File

@@ -47,6 +47,7 @@ use Thelia\Config\DatabaseConfiguration;
use Thelia\Config\DefinePropel;
use Thelia\Core\TheliaContainerBuilder;
use Thelia\Core\DependencyInjection\Loader\XmlFileLoader;
use Thelia\Model\ConfigQuery;
use Symfony\Component\Config\FileLocator;
use Propel\Runtime\Propel;
@@ -122,7 +123,8 @@ class Thelia extends Kernel
if (defined("THELIA_INSTALL_MODE") === false) {
$modules = \Thelia\Model\ModuleQuery::getActivated();
$translator = $container->getDefinition('thelia.translator');
$dirs = array();
foreach ($modules as $module) {
try {
@@ -138,10 +140,38 @@ class Thelia extends Kernel
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
$loader->load("config.xml");
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) {
$dirs[] = $dir;
}
} catch (\InvalidArgumentException $e) {
// FIXME: process module configuration exception
}
}
//Load translation from templates
//admin template
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
$dirs[] = $dir;
}
//front template
$template = ConfigQuery::getActiveTemplate();
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
$dirs[] = $dir;
}
if ($dirs) {
$finder = Finder::create()
->files()
->depth(0)
->in($dirs);
foreach ($finder as $file) {
list($locale, $format) = explode('.', $file->getBaseName(), 2);
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
}
}
}
}

View File

@@ -2,6 +2,7 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Model\Base\CustomerQuery as BaseCustomerQuery;
@@ -21,4 +22,20 @@ class CustomerQuery extends BaseCustomerQuery {
{
return self::create()->findOneByEmail($email);
}
public static function getNewCustomersStats($month, $year)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayCustomers = self::create()
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL)
->count();
$stats[] = array($day-1, $dayCustomers);
}
return $stats;
}
} // CustomerQuery

View File

@@ -3,6 +3,7 @@
namespace Thelia\Model;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\Join;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Thelia\Model\Base\OrderQuery as BaseOrderQuery;
@@ -54,4 +55,71 @@ class OrderQuery extends BaseOrderQuery
return $obj;
}
public static function getSaleStats($month, $year)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayAmount = 0;
foreach(self::create()
->filterByStatusId(array(2,3,4), Criteria::IN)
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL)
->find() as $dayOrders) {
$dayAmount += $dayOrders->getTotalAmount();
}
$stats[] = array($day-1, $dayAmount);
}
return $stats;
}
public static function getOrdersStats($month, $year, $status = null)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayOrdersQuery = self::create()
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL);
if(null !== $status) {
$dayOrdersQuery->filterByStatusId($status, Criteria::IN);
}
$dayOrders = $dayOrdersQuery->count();
$stats[] = array($day-1, $dayOrders);
}
return $stats;
}
public static function getFirstOrdersStats($month, $year)
{
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$stats = array();
for($day=1; $day<=$numberOfDay; $day++) {
$dayOrdersQuery = self::create('matching_order')
->filterByCreatedAt(sprintf("%s-%s-%s 00:00:00", $year, $month, $day), Criteria::GREATER_EQUAL)
->filterByCreatedAt(sprintf("%s-%s-%s 23:59:59", $year, $month, $day), Criteria::LESS_EQUAL);
$otherOrderJoin = new Join();
$otherOrderJoin->addExplicitCondition(OrderTableMap::TABLE_NAME, 'CUSTOMER_ID', 'matching_order', OrderTableMap::TABLE_NAME, 'CUSTOMER_ID', 'other_order');
$otherOrderJoin->setJoinType(Criteria::LEFT_JOIN);
$dayOrdersQuery->addJoinObject($otherOrderJoin, 'other_order_join')
->addJoinCondition('other_order_join', '`matching_order`.`ID` <> `other_order`.`ID`')
->addJoinCondition('other_order_join', '`matching_order`.`CREATED_AT` > `other_order`.`CREATED_AT`');
$dayOrdersQuery->where('ISNULL(`other_order`.`ID`)');
$dayOrders = $dayOrdersQuery->count();
$stats[] = array($day-1, $dayOrders);
}
return $stats;
}
} // OrderQuery