-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShortCode.php
89 lines (77 loc) · 3.06 KB
/
ShortCode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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 ShortCode;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use ShortCode\Model\ShortCodeQuery;
use Thelia\Install\Database;
use Thelia\Module\BaseModule;
class ShortCode extends BaseModule
{
/** @var string */
const DOMAIN_NAME = 'shortcode';
public function preActivation(ConnectionInterface $con = null)
{
if (!$this->getConfigValue('is_initialized', false)) {
$database = new Database($con);
$database->insertSql(null, array(__DIR__ . '/Config/TheliaMain.sql'));
$this->setConfigValue('is_initialized', true);
}
return true;
}
/**
* Create a new ShortCode
* @param string $shortCodeName the name for call the ShortCode in template
* @param string $eventName the name of the event dispatched when shortcode is in template
* @throws PropelException
*/
public static function createNewShortCodeIfNotExist($shortCodeName, $eventName)
{
if (null === ShortCodeQuery::create()->findOneByTag($shortCodeName)) {
$shortCode = new \ShortCode\Model\ShortCode();
$shortCode->setTag($shortCodeName)
->setEvent($eventName)
->setActive(1)
->save();
}
}
/**
* Active a ShortCode by his name
* @param string $shortCodeName the name for call the ShortCode in template
* @throws PropelException
*/
public static function activateShortCode($shortCodeName)
{
$shortCode = ShortCodeQuery::create()
->filterByTag($shortCodeName)
->findOne();
if (null !== $shortCode) {
$shortCode->setActive(1)
->save();
}
}
/**
* Deactive a ShortCode by his name
* @param string $shortCodeName the name for call the ShortCode in template
* @throws PropelException
*/
public static function deactivateShortCode($shortCodeName)
{
$shortCode = ShortCodeQuery::create()
->filterByTag($shortCodeName)
->findOne();
if (null !== $shortCode) {
$shortCode->setActive(0)
->save();
}
}
}