forked from thelia-modules/Diaporamas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diaporama.php
70 lines (59 loc) · 2.54 KB
/
Diaporama.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
<?php
/*************************************************************************************/
/* This file is part of the "Diaporamas" Thelia 2 module. */
/* */
/* 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 Diaporamas\Model;
use Diaporamas\Model\Base\Diaporama as BaseDiaporama;
/**
* Class Diaporama
* @package Diaporamas\Model
*/
class Diaporama extends BaseDiaporama
{
const SHORTCODE_OPENING_TAG = '[£ ';
const SHORTCODE_CLOSING_TAG = ' £]';
const SHORTCODE_REGEX = '/^[\w\-]{1,32}$/';
const SHORTCODETAG_REGEX = '/\[£\s[\w\-]{1,32}\s£\]/';
const SHORTCODETAG_HTMLENTITIES_REGEX = '/\[(£|£)(\s| )+[\w\-]{1,32}(\s| )+(£|£)\]/';
/**
* Retrieving a diaporama with its shortcode
* @param string $shortcode Diaporama shortcode
* @return Diaporama|null The diaporama whose shortcode is [£ $shortcode £] if it exists, null otherwise.
*/
public static function getByShortcode($shortcode)
{
return DiaporamaQuery::create()->findOneByShortcode($shortcode);
}
/**
* Telling if a diaporama exists according to its shortcode
* @param string $shortcode Diaporama shortcode
* @return Diaporama|null true if the diaporama with the [£ $shortcode £] shortcode exists, false otherwise.
*/
public static function existsByShortcode($shortcode)
{
return DiaporamaQuery::create()->filterByShortcode($shortcode)->count() > 0;
}
/**
* Building the shortcode tag
* @return string [£shortcode£]
*/
public function getShortcodeTag()
{
return self::SHORTCODE_OPENING_TAG.$this->shortcode.self::SHORTCODE_CLOSING_TAG;
}
/**
* Retrieving diaporama's images
* @return array Diaporama's images.
*/
public function getImages()
{
return DiaporamaImageQuery::create()->findByDiaporamaId($this->getId());
}
}