Initial commit

This commit is contained in:
2020-01-27 08:56:08 +01:00
commit b7525048d6
27129 changed files with 3409855 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<div class="general-block-decorator">
<div class="row">
<div class="col-md-12 title title-without-tabs">
{intl l='Edit your analytics configuration.' d="googleuniversalanalytics.ai"}
</div>
<div class="form-container">
<div class="col-md-12">
{form name="GUA.config"}
<form method="POST" action="{url path="/admin/module/GoogleUniversalAnalytics/save"}" {form_enctype form=$form} class="clearfix">
{form_hidden_fields form=$form}
{form_field form=$form field='tracking_id'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" value="{$value}">
</div>
{/form_field}
<button type="submit" value="save" class="form-submit-button btn btn-sm btn-default" title="{intl d='googleuniversalanalytics.ai' l='Save'}">{intl d='googleuniversalanalytics.ai' l='Save'}</button>
</form>
{/form}
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,27 @@
<?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">
<forms>
<form name="GUA.config" class="GoogleUniversalAnalytics\Form\ConfigForm" />
</forms>
<hooks>
<hook id="UniversalAnalytics.hook.order.invoice" class="GoogleUniversalAnalytics\Hook\Client" scope="request">
<tag name="hook.event_listener" event="order-invoice.after-javascript-include" method="insertTag" />
</hook>
</hooks>
<services>
<service id="UniversalAnalytics.order.create" class="GoogleUniversalAnalytics\EventListeners\OrderListener" scope="request">
<argument type="service" id="request" />
<tag name="kernel.event_subscriber"/>
</service>
<service id="UniversalAnalytics.order.updateStatus" class="GoogleUniversalAnalytics\EventListeners\TrackingListener">
<tag name="kernel.event_subscriber"/>
</service>
</services>
</config>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module>
<fullnamespace>GoogleUniversalAnalytics\GoogleUniversalAnalytics</fullnamespace>
<descriptive locale="en_US">
<title>Google Universal Analytics integration</title>
<description>Save all</description>
</descriptive>
<descriptive locale="fr_FR">
<title>Intégration de Google Universal Analytics</title>
</descriptive>
<version>2.1.3</version>
<author>
<name>Manuel Raynaud</name>
<email>manu@thelia.net</email>
</author>
<type>classic</type>
<thelia>2.1.0</thelia>
<stability>other</stability>
</module>

View File

@@ -0,0 +1,15 @@
<?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="UniversalAnalytics.ClientId.save" path="/UniversalAnalytics/ClientId">
<default key="_controller">GoogleUniversalAnalytics\Controller\Client::saveAction</default>
</route>
<route id="UniversalAnalytics.config.save" path="admin/module/GoogleUniversalAnalytics/save" methods="post">
<default key="_controller">GoogleUniversalAnalytics\Controller\ConfigController::saveAction</default>
</route>
</routes>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia" namespace="GoogleUniversalAnalytics\Model">
<table name="UniversalAnalytics_transaction">
<column name="id" primaryKey="true" autoIncrement="true" required="true" type="INTEGER" />
<column name="clientId" type="VARCHAR" size="255" />
<column name="order_id" type="INTEGER" />
<column name="used" type="INTEGER" default="0"/>
</table>
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
</database>

View File

@@ -0,0 +1,22 @@
# 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;
-- ---------------------------------------------------------------------
-- UniversalAnalytics_transaction
-- ---------------------------------------------------------------------
DROP TABLE IF EXISTS `UniversalAnalytics_transaction`;
CREATE TABLE `UniversalAnalytics_transaction`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`clientId` VARCHAR(255),
`order_id` INTEGER,
`used` INTEGER DEFAULT 0,
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,34 @@
<?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 GoogleUniversalAnalytics\Controller;
use GoogleUniversalAnalytics\GoogleUniversalAnalytics;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\HttpFoundation\Response;
/**
* Class Client
* @package GoogleUniversalAnalytics\Controller
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class Client extends BaseFrontController
{
public function saveAction()
{
$clientId = $this->getRequest()->query->get('clientId');
$this->getSession()->set(GoogleUniversalAnalytics::ANALYTICS_UA, $clientId);
return Response::create();
}
}

View File

@@ -0,0 +1,66 @@
<?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 GoogleUniversalAnalytics\Controller;
use GoogleUniversalAnalytics\Form\ConfigForm;
use GoogleUniversalAnalytics\GoogleUniversalAnalytics;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
/**
* Class ConfigController
* @package GoogleUniversalAnalytics\Controller
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class ConfigController extends BaseAdminController
{
public function saveAction()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, ['googleuniversalanalytics'], AccessManager::UPDATE)) {
return $response;
}
$form = new ConfigForm($this->getRequest());
$error_message = null;
$response = null;
try {
$vform = $this->validateForm($form);
ConfigQuery::write(GoogleUniversalAnalytics::ANALYTICS_UA, $vform->get('tracking_id')->getData(), 1, 1);
$response = RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/GoogleUniversalAnalytics'));
} catch (\Exception $e) {
$error_message = $this->createStandardFormValidationErrorMessage($e);
}
if (null !== $error_message) {
$this->setupFormErrorContext(
'carousel upload',
$error_message,
$form
);
$response = $this->render(
"module-configure",
[
'module_code' => 'Carousel'
]
);
}
return $response;
}
}

View File

@@ -0,0 +1,85 @@
<?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 GoogleUniversalAnalytics\EventListeners;
use GoogleUniversalAnalytics\GoogleUniversalAnalytics;
use GoogleUniversalAnalytics\Model\UniversalanalyticsTransaction;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Request;
/**
* Class OrderListener
* @package GoogleUniversalAnalytics\EventListeners
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class OrderListener implements EventSubscriberInterface
{
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function saveTransaction(OrderEvent $event)
{
$clientId = $this->request->getSession()->get(GoogleUniversalAnalytics::ANALYTICS_UA);
if (null !== $clientId) {
$order = $event->getPlacedOrder();
$universalAnalytics = new UniversalanalyticsTransaction();
$universalAnalytics
->setClientid($clientId)
->setOrderId($order->getId())
->save();
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
$events = [
TheliaEvents::ORDER_PAY => 'saveTransaction',
];
if (defined("Thelia\\Core\\Event\\TheliaEvents::ORDER_CREATE_MANUAL")) {
$events[TheliaEvents::ORDER_CREATE_MANUAL] = 'saveTransaction';
}
return $events;
}
}

View File

@@ -0,0 +1,125 @@
<?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 GoogleUniversalAnalytics\EventListeners;
use GoogleUniversalAnalytics\GoogleUniversalAnalytics;
use GoogleUniversalAnalytics\Measurement\Item;
use GoogleUniversalAnalytics\Measurement\Transaction;
use GoogleUniversalAnalytics\Model\UniversalanalyticsTransactionQuery;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
/**
* Class TrackingListener
* @package GoogleUniversalAnalytics\EventListeners
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class TrackingListener implements EventSubscriberInterface
{
/**
* Send a transaction and all items to Google Universal Analytics
*
* @param OrderEvent $event
*/
public function track(OrderEvent $event)
{
$order = $event->getOrder();
if ($order->isPaid()) {
$transactionInstance = UniversalanalyticsTransactionQuery::create()
->filterByUsed(0)
->filterByOrderId($order->getId())
->findOne()
;
if (null !== $transactionInstance) {
$clientId = $transactionInstance->getClientid();
$tax = 0;
$currency = $order->getCurrency()->getCode();
$ref = $order->getRef();
$transaction = new Transaction();
$status = $transaction
->add('cid', $clientId)
->add('ti', $ref)
->add('tr', $order->getTotalAmount($tax, false))
->add('tt', $tax)
->add('ts', $order->getPostage())
->add('cu', $currency)
->send()
;
Tlog::getInstance()->addInfo('transaction : ' . print_r($transaction->getData(), true));
Tlog::getInstance()->addInfo('status : ' . $status);
foreach ($order->getOrderProducts() as $product) {
$taxes = $product->getOrderProductTaxes();
$productTax = 0;
foreach ($taxes as $tax) {
$productTax += $product->getWasInPromo() ? $tax->getPromoAmount() : $tax->getAmount();
}
$item = new Item();
$price = $product->getWasInPromo() ? $product->getPromoPrice() : $product->getPrice();
$price += $productTax;
$status = $item->add('cid', $clientId)
->add('ti', $ref)
->add('in', $product->getTitle())
->add('iq', $product->getQuantity())
->add('ic', $product->getProductRef())
->add('cu', $currency)
->add('ip', $price)
->send()
;
Tlog::getInstance()->addInfo('item : ' . print_r($item->getData(), true));
Tlog::getInstance()->addInfo('status : ' . $status);
}
$transactionInstance
->setUsed(1)
->save();
}
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
*
* @return array The event names to listen to
*
* @api
*/
public static function getSubscribedEvents()
{
return [
TheliaEvents::ORDER_UPDATE_STATUS => 'track',
];
}
}

View File

@@ -0,0 +1,71 @@
<?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 GoogleUniversalAnalytics\Form;
use GoogleUniversalAnalytics\GoogleUniversalAnalytics;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
use Thelia\Model\ConfigQuery;
/**
* Class ConfigForm
* @package GoogleUniversalAnalytics\Form
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class ConfigForm extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder->add(
'tracking_id',
'text',
[
'data' => ConfigQuery::read(GoogleUniversalAnalytics::ANALYTICS_UA, ''),
'label' => Translator::getInstance()->trans("Tracking Code"),
'label_attr' => array(
'for' => "trackingcode"
),
]
);
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "GUA_config";
}
}

View File

@@ -0,0 +1,41 @@
<?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 GoogleUniversalAnalytics;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Install\Database;
use Thelia\Model\ConfigQuery;
use Thelia\Module\BaseModule;
class GoogleUniversalAnalytics extends BaseModule
{
const ANALYTICS_UA = 'analytics_UA';
/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
*/
public function postActivation(ConnectionInterface $con = null)
{
if (null === ConfigQuery::read(self::ANALYTICS_UA)) {
ConfigQuery::write(self::ANALYTICS_UA, '', 1, 1);
}
$database = new Database($con);
$database->insertSql(null, array(__DIR__ . '/Config/thelia.sql'));
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace GoogleUniversalAnalytics\Hook;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
/**
* Class Client
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class Client extends BaseHook
{
public function insertTag(HookRenderEvent $event)
{
$event->add($this->render("analytics-client.html"));
}
}

View File

@@ -0,0 +1,4 @@
<?php
return array(
// 'an english string' => 'The displayed english string',
);

View File

@@ -0,0 +1,4 @@
<?php
return array(
// 'an english string' => 'La traduction française de la chaine',
);

View File

@@ -0,0 +1,61 @@
<?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 GoogleUniversalAnalytics\Measurement;
use GoogleUniversalAnalytics\GoogleUniversalAnalytics;
use Thelia\Model\ConfigQuery;
/**
* Class BaseMeasurement
* @package GoogleUniversalAnalytics\Measurement
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class BaseMeasurement
{
const ANALYTICS_URL = "https://ssl.google-analytics.com/collect";
protected $data = [];
public function __construct()
{
$this->data['v'] = 1;
$this->data['tid'] = ConfigQuery::read(GoogleUniversalAnalytics::ANALYTICS_UA);
}
public function add($key, $value)
{
$this->data[$key] = $value;
return $this;
}
public function getData()
{
return $this->data;
}
public function send()
{
$ch = curl_init(self::ANALYTICS_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->getData()));
curl_setopt($ch, CURLOPT_USERAGENT, "Thelia GoogleUniversalAnalytics");
$result = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $http_status;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace GoogleUniversalAnalytics\Measurement;
/**
* Class Item
* @package GoogleUniversalAnalytics\Measurement
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class Item extends BaseMeasurement
{
public function __construct()
{
parent::__construct();
$this->data['t'] = 'item';
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace GoogleUniversalAnalytics\Measurement;
/**
* Class Transaction
* @package GoogleUniversalAnalytics\Measurement
* @author manuel raynaud <mraynaud@openstudio.fr>
*/
class Transaction extends BaseMeasurement
{
public function __construct()
{
parent::__construct();
$this->data['t'] = 'transaction';
}
}

View File

@@ -0,0 +1,467 @@
<?php
namespace GoogleUniversalAnalytics\Model\Base;
use \Exception;
use \PDO;
use GoogleUniversalAnalytics\Model\UniversalanalyticsTransaction as ChildUniversalanalyticsTransaction;
use GoogleUniversalAnalytics\Model\UniversalanalyticsTransactionQuery as ChildUniversalanalyticsTransactionQuery;
use GoogleUniversalAnalytics\Model\Map\UniversalanalyticsTransactionTableMap;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
/**
* Base class that represents a query for the 'UniversalAnalytics_transaction' table.
*
*
*
* @method ChildUniversalanalyticsTransactionQuery orderById($order = Criteria::ASC) Order by the id column
* @method ChildUniversalanalyticsTransactionQuery orderByClientid($order = Criteria::ASC) Order by the clientId column
* @method ChildUniversalanalyticsTransactionQuery orderByOrderId($order = Criteria::ASC) Order by the order_id column
* @method ChildUniversalanalyticsTransactionQuery orderByUsed($order = Criteria::ASC) Order by the used column
*
* @method ChildUniversalanalyticsTransactionQuery groupById() Group by the id column
* @method ChildUniversalanalyticsTransactionQuery groupByClientid() Group by the clientId column
* @method ChildUniversalanalyticsTransactionQuery groupByOrderId() Group by the order_id column
* @method ChildUniversalanalyticsTransactionQuery groupByUsed() Group by the used column
*
* @method ChildUniversalanalyticsTransactionQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method ChildUniversalanalyticsTransactionQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
* @method ChildUniversalanalyticsTransactionQuery innerJoin($relation) Adds a INNER JOIN clause to the query
*
* @method ChildUniversalanalyticsTransaction findOne(ConnectionInterface $con = null) Return the first ChildUniversalanalyticsTransaction matching the query
* @method ChildUniversalanalyticsTransaction findOneOrCreate(ConnectionInterface $con = null) Return the first ChildUniversalanalyticsTransaction matching the query, or a new ChildUniversalanalyticsTransaction object populated from the query conditions when no match is found
*
* @method ChildUniversalanalyticsTransaction findOneById(int $id) Return the first ChildUniversalanalyticsTransaction filtered by the id column
* @method ChildUniversalanalyticsTransaction findOneByClientid(string $clientId) Return the first ChildUniversalanalyticsTransaction filtered by the clientId column
* @method ChildUniversalanalyticsTransaction findOneByOrderId(int $order_id) Return the first ChildUniversalanalyticsTransaction filtered by the order_id column
* @method ChildUniversalanalyticsTransaction findOneByUsed(int $used) Return the first ChildUniversalanalyticsTransaction filtered by the used column
*
* @method array findById(int $id) Return ChildUniversalanalyticsTransaction objects filtered by the id column
* @method array findByClientid(string $clientId) Return ChildUniversalanalyticsTransaction objects filtered by the clientId column
* @method array findByOrderId(int $order_id) Return ChildUniversalanalyticsTransaction objects filtered by the order_id column
* @method array findByUsed(int $used) Return ChildUniversalanalyticsTransaction objects filtered by the used column
*
*/
abstract class UniversalanalyticsTransactionQuery extends ModelCriteria
{
/**
* Initializes internal state of \GoogleUniversalAnalytics\Model\Base\UniversalanalyticsTransactionQuery 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 = '\\GoogleUniversalAnalytics\\Model\\UniversalanalyticsTransaction', $modelAlias = null)
{
parent::__construct($dbName, $modelName, $modelAlias);
}
/**
* Returns a new ChildUniversalanalyticsTransactionQuery object.
*
* @param string $modelAlias The alias of a model in the query
* @param Criteria $criteria Optional Criteria to build the query from
*
* @return ChildUniversalanalyticsTransactionQuery
*/
public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \GoogleUniversalAnalytics\Model\UniversalanalyticsTransactionQuery) {
return $criteria;
}
$query = new \GoogleUniversalAnalytics\Model\UniversalanalyticsTransactionQuery();
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 ChildUniversalanalyticsTransaction|array|mixed the result, formatted by the current formatter
*/
public function findPk($key, $con = null)
{
if ($key === null) {
return null;
}
if ((null !== ($obj = UniversalanalyticsTransactionTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) {
// the object is already in the instance pool
return $obj;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection(UniversalanalyticsTransactionTableMap::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 ChildUniversalanalyticsTransaction A model object, or null if the key is not found
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, CLIENTID, ORDER_ID, USED FROM UniversalAnalytics_transaction 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 ChildUniversalanalyticsTransaction();
$obj->hydrate($row);
UniversalanalyticsTransactionTableMap::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 ChildUniversalanalyticsTransaction|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 ChildUniversalanalyticsTransactionQuery The current query, for fluid interface
*/
public function filterByPrimaryKey($key)
{
return $this->addUsingAlias(UniversalanalyticsTransactionTableMap::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 ChildUniversalanalyticsTransactionQuery The current query, for fluid interface
*/
public function filterByPrimaryKeys($keys)
{
return $this->addUsingAlias(UniversalanalyticsTransactionTableMap::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 ChildUniversalanalyticsTransactionQuery 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(UniversalanalyticsTransactionTableMap::ID, $id['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($id['max'])) {
$this->addUsingAlias(UniversalanalyticsTransactionTableMap::ID, $id['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(UniversalanalyticsTransactionTableMap::ID, $id, $comparison);
}
/**
* Filter the query on the clientId column
*
* Example usage:
* <code>
* $query->filterByClientid('fooValue'); // WHERE clientId = 'fooValue'
* $query->filterByClientid('%fooValue%'); // WHERE clientId LIKE '%fooValue%'
* </code>
*
* @param string $clientid 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 ChildUniversalanalyticsTransactionQuery The current query, for fluid interface
*/
public function filterByClientid($clientid = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($clientid)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $clientid)) {
$clientid = str_replace('*', '%', $clientid);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(UniversalanalyticsTransactionTableMap::CLIENTID, $clientid, $comparison);
}
/**
* Filter the query on the order_id column
*
* Example usage:
* <code>
* $query->filterByOrderId(1234); // WHERE order_id = 1234
* $query->filterByOrderId(array(12, 34)); // WHERE order_id IN (12, 34)
* $query->filterByOrderId(array('min' => 12)); // WHERE order_id > 12
* </code>
*
* @param mixed $orderId 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 ChildUniversalanalyticsTransactionQuery The current query, for fluid interface
*/
public function filterByOrderId($orderId = null, $comparison = null)
{
if (is_array($orderId)) {
$useMinMax = false;
if (isset($orderId['min'])) {
$this->addUsingAlias(UniversalanalyticsTransactionTableMap::ORDER_ID, $orderId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($orderId['max'])) {
$this->addUsingAlias(UniversalanalyticsTransactionTableMap::ORDER_ID, $orderId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(UniversalanalyticsTransactionTableMap::ORDER_ID, $orderId, $comparison);
}
/**
* Filter the query on the used column
*
* Example usage:
* <code>
* $query->filterByUsed(1234); // WHERE used = 1234
* $query->filterByUsed(array(12, 34)); // WHERE used IN (12, 34)
* $query->filterByUsed(array('min' => 12)); // WHERE used > 12
* </code>
*
* @param mixed $used 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 ChildUniversalanalyticsTransactionQuery The current query, for fluid interface
*/
public function filterByUsed($used = null, $comparison = null)
{
if (is_array($used)) {
$useMinMax = false;
if (isset($used['min'])) {
$this->addUsingAlias(UniversalanalyticsTransactionTableMap::USED, $used['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($used['max'])) {
$this->addUsingAlias(UniversalanalyticsTransactionTableMap::USED, $used['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(UniversalanalyticsTransactionTableMap::USED, $used, $comparison);
}
/**
* Exclude object from result
*
* @param ChildUniversalanalyticsTransaction $universalanalyticsTransaction Object to remove from the list of results
*
* @return ChildUniversalanalyticsTransactionQuery The current query, for fluid interface
*/
public function prune($universalanalyticsTransaction = null)
{
if ($universalanalyticsTransaction) {
$this->addUsingAlias(UniversalanalyticsTransactionTableMap::ID, $universalanalyticsTransaction->getId(), Criteria::NOT_EQUAL);
}
return $this;
}
/**
* Deletes all rows from the UniversalAnalytics_transaction 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(UniversalanalyticsTransactionTableMap::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).
UniversalanalyticsTransactionTableMap::clearInstancePool();
UniversalanalyticsTransactionTableMap::clearRelatedInstancePool();
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
return $affectedRows;
}
/**
* Performs a DELETE on the database, given a ChildUniversalanalyticsTransaction or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or ChildUniversalanalyticsTransaction 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(UniversalanalyticsTransactionTableMap::DATABASE_NAME);
}
$criteria = $this;
// Set the correct dbName
$criteria->setDbName(UniversalanalyticsTransactionTableMap::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();
UniversalanalyticsTransactionTableMap::removeInstanceFromPool($criteria);
$affectedRows += ModelCriteria::delete($con);
UniversalanalyticsTransactionTableMap::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
} // UniversalanalyticsTransactionQuery

View File

@@ -0,0 +1,426 @@
<?php
namespace GoogleUniversalAnalytics\Model\Map;
use GoogleUniversalAnalytics\Model\UniversalanalyticsTransaction;
use GoogleUniversalAnalytics\Model\UniversalanalyticsTransactionQuery;
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;
/**
* This class defines the structure of the 'UniversalAnalytics_transaction' 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 UniversalanalyticsTransactionTableMap extends TableMap
{
use InstancePoolTrait;
use TableMapTrait;
/**
* The (dot-path) name of this class
*/
const CLASS_NAME = 'GoogleUniversalAnalytics.Model.Map.UniversalanalyticsTransactionTableMap';
/**
* The default database name for this class
*/
const DATABASE_NAME = 'thelia';
/**
* The table name for this class
*/
const TABLE_NAME = 'UniversalAnalytics_transaction';
/**
* The related Propel class for this table
*/
const OM_CLASS = '\\GoogleUniversalAnalytics\\Model\\UniversalanalyticsTransaction';
/**
* A class that can be returned by this tableMap
*/
const CLASS_DEFAULT = 'GoogleUniversalAnalytics.Model.UniversalanalyticsTransaction';
/**
* The total number of columns
*/
const NUM_COLUMNS = 4;
/**
* 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 = 4;
/**
* the column name for the ID field
*/
const ID = 'UniversalAnalytics_transaction.ID';
/**
* the column name for the CLIENTID field
*/
const CLIENTID = 'UniversalAnalytics_transaction.CLIENTID';
/**
* the column name for the ORDER_ID field
*/
const ORDER_ID = 'UniversalAnalytics_transaction.ORDER_ID';
/**
* the column name for the USED field
*/
const USED = 'UniversalAnalytics_transaction.USED';
/**
* 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', 'Clientid', 'OrderId', 'Used', ),
self::TYPE_STUDLYPHPNAME => array('id', 'clientid', 'orderId', 'used', ),
self::TYPE_COLNAME => array(UniversalanalyticsTransactionTableMap::ID, UniversalanalyticsTransactionTableMap::CLIENTID, UniversalanalyticsTransactionTableMap::ORDER_ID, UniversalanalyticsTransactionTableMap::USED, ),
self::TYPE_RAW_COLNAME => array('ID', 'CLIENTID', 'ORDER_ID', 'USED', ),
self::TYPE_FIELDNAME => array('id', 'clientId', 'order_id', 'used', ),
self::TYPE_NUM => array(0, 1, 2, 3, )
);
/**
* 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, 'Clientid' => 1, 'OrderId' => 2, 'Used' => 3, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'clientid' => 1, 'orderId' => 2, 'used' => 3, ),
self::TYPE_COLNAME => array(UniversalanalyticsTransactionTableMap::ID => 0, UniversalanalyticsTransactionTableMap::CLIENTID => 1, UniversalanalyticsTransactionTableMap::ORDER_ID => 2, UniversalanalyticsTransactionTableMap::USED => 3, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'CLIENTID' => 1, 'ORDER_ID' => 2, 'USED' => 3, ),
self::TYPE_FIELDNAME => array('id' => 0, 'clientId' => 1, 'order_id' => 2, 'used' => 3, ),
self::TYPE_NUM => array(0, 1, 2, 3, )
);
/**
* 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('UniversalAnalytics_transaction');
$this->setPhpName('UniversalanalyticsTransaction');
$this->setClassName('\\GoogleUniversalAnalytics\\Model\\UniversalanalyticsTransaction');
$this->setPackage('GoogleUniversalAnalytics.Model');
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addColumn('CLIENTID', 'Clientid', 'VARCHAR', false, 255, null);
$this->addColumn('ORDER_ID', 'OrderId', 'INTEGER', false, null, null);
$this->addColumn('USED', 'Used', 'INTEGER', false, null, 0);
} // initialize()
/**
* Build the RelationMap objects for this table relationships
*/
public function buildRelations()
{
} // buildRelations()
/**
* 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 ? UniversalanalyticsTransactionTableMap::CLASS_DEFAULT : UniversalanalyticsTransactionTableMap::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 (UniversalanalyticsTransaction object, last column rank)
*/
public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM)
{
$key = UniversalanalyticsTransactionTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType);
if (null !== ($obj = UniversalanalyticsTransactionTableMap::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 + UniversalanalyticsTransactionTableMap::NUM_HYDRATE_COLUMNS;
} else {
$cls = UniversalanalyticsTransactionTableMap::OM_CLASS;
$obj = new $cls();
$col = $obj->hydrate($row, $offset, false, $indexType);
UniversalanalyticsTransactionTableMap::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 = UniversalanalyticsTransactionTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType());
if (null !== ($obj = UniversalanalyticsTransactionTableMap::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;
UniversalanalyticsTransactionTableMap::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(UniversalanalyticsTransactionTableMap::ID);
$criteria->addSelectColumn(UniversalanalyticsTransactionTableMap::CLIENTID);
$criteria->addSelectColumn(UniversalanalyticsTransactionTableMap::ORDER_ID);
$criteria->addSelectColumn(UniversalanalyticsTransactionTableMap::USED);
} else {
$criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.CLIENTID');
$criteria->addSelectColumn($alias . '.ORDER_ID');
$criteria->addSelectColumn($alias . '.USED');
}
}
/**
* 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(UniversalanalyticsTransactionTableMap::DATABASE_NAME)->getTable(UniversalanalyticsTransactionTableMap::TABLE_NAME);
}
/**
* Add a TableMap instance to the database for this tableMap class.
*/
public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(UniversalanalyticsTransactionTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(UniversalanalyticsTransactionTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new UniversalanalyticsTransactionTableMap());
}
}
/**
* Performs a DELETE on the database, given a UniversalanalyticsTransaction or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or UniversalanalyticsTransaction 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(UniversalanalyticsTransactionTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \GoogleUniversalAnalytics\Model\UniversalanalyticsTransaction) { // 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(UniversalanalyticsTransactionTableMap::DATABASE_NAME);
$criteria->add(UniversalanalyticsTransactionTableMap::ID, (array) $values, Criteria::IN);
}
$query = UniversalanalyticsTransactionQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) { UniversalanalyticsTransactionTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) { UniversalanalyticsTransactionTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
}
/**
* Deletes all rows from the UniversalAnalytics_transaction 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 UniversalanalyticsTransactionQuery::create()->doDeleteAll($con);
}
/**
* Performs an INSERT on the database, given a UniversalanalyticsTransaction or Criteria object.
*
* @param mixed $criteria Criteria or UniversalanalyticsTransaction 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(UniversalanalyticsTransactionTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from UniversalanalyticsTransaction object
}
if ($criteria->containsKey(UniversalanalyticsTransactionTableMap::ID) && $criteria->keyContainsValue(UniversalanalyticsTransactionTableMap::ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.UniversalanalyticsTransactionTableMap::ID.')');
}
// Set the correct dbName
$query = UniversalanalyticsTransactionQuery::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;
}
} // UniversalanalyticsTransactionTableMap
// This is the static code needed to register the TableMap for this table with the main Propel class.
//
UniversalanalyticsTransactionTableMap::buildTableMap();

View File

@@ -0,0 +1,10 @@
<?php
namespace GoogleUniversalAnalytics\Model;
use GoogleUniversalAnalytics\Model\Base\UniversalanalyticsTransaction as BaseUniversalanalyticsTransaction;
class UniversalanalyticsTransaction extends BaseUniversalanalyticsTransaction
{
}

View File

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

View File

@@ -0,0 +1,28 @@
# Google Universal Analytics
This module uses the Google Measurement Protocol and add ecommerce information in your google analytics account.
It only works if you have enabled the Google Universal Analytics.
For each new order paid, the module send to Analytics a new transaction and all items attached to this transaction.
## Installation
If you are using Thelia 2.0.* please download from branch 2.0 or tag 2.0.*.
If you are using Thelia 2.1.* please download from branch master or tag 2.1.*
Following which version of the module you use, the integration is different. Read carefully the good readme.
- Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is GoogleUniversalAnalytics
- Activate it in your Thelia administration panel, then click on "configure" and enter your Analytics id (UA-XXXXX-X) and save it.
## Integration
No integration needed, the hook ```order-invoice.after-javascript-include``` is used
This script must be placed after the google analytics code.
## Usage
The ecommerce option must be activated in your view parameter in your Analytics account.

View File

@@ -0,0 +1,18 @@
{
"name": "thelia/google-universal-analytics",
"type": "thelia-module",
"description": "Google Universal Analytics integration for ecommerce tracking ",
"license": "LGPL-3.0+",
"authors": [
{
"name": "Manuel Raynaud",
"email": "manu@thelia.net"
}
],
"require": {
"thelia/installer": "~1.0"
},
"extra": {
"installer-name": "GoogleUniversalAnalytics"
}
}

View File

@@ -0,0 +1,36 @@
<script>
if (typeof ga=="undefined") {
var js;
var html_doc = document.getElementsByTagName('head').item(0);
js = document.createElement('script');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', "//www.google-analytics.com/analytics.js");
html_doc.appendChild(js);
// onscript ready IE
js.onreadystatechange = function () {
ga('create', '{config key='analytics_UA'}', 'auto');
initGaTracker();
};
// onscript ready else
js.onload = function () {
ga('create', '{config key='analytics_UA'}', 'auto');
initGaTracker();
}
} else {
initGaTracker();
}
function initGaTracker() {
ga(function(tracker) {
clientId = tracker.get('clientId');
$.ajax({
'url': "{url path='/UniversalAnalytics/ClientId'}",
'data': {
'clientId': clientId
}
});
});
}
</script>