|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Twig\Extension; |
|
5
|
|
|
|
|
6
|
|
|
use Twig\TwigFunction; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ChamiloExtension. |
|
10
|
|
|
* |
|
11
|
|
|
* @package Chamilo\CoreBundle\Twig\Extension |
|
12
|
|
|
*/ |
|
13
|
|
|
class ChamiloExtension extends \Twig_Extension |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @return array |
|
17
|
|
|
*/ |
|
18
|
|
|
public function getFilters() |
|
19
|
|
|
{ |
|
20
|
|
|
return [ |
|
21
|
|
|
new \Twig_SimpleFilter('var_dump', 'var_dump'), |
|
22
|
|
|
new \Twig_SimpleFilter('icon', 'Template::get_icon_path'), |
|
23
|
|
|
new \Twig_SimpleFilter('api_get_local_time', 'api_get_local_time'), |
|
24
|
|
|
]; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getFunctions() |
|
31
|
|
|
{ |
|
32
|
|
|
return [ |
|
33
|
|
|
new TwigFunction('chamilo_page_title_get', [$this, 'getChamiloPageTitle']), |
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getChamiloPageTitle(): string |
|
38
|
|
|
{ |
|
39
|
|
|
$urlPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
|
40
|
|
|
$urlPath = rtrim($urlPath, '/'); |
|
41
|
|
|
$parts = explode('/', $urlPath); |
|
42
|
|
|
$title = end($parts); |
|
43
|
|
|
|
|
44
|
|
|
$titleList = []; |
|
45
|
|
|
$titleList[] = 'OFAJ'; // api_get_setting('Institution'); |
|
46
|
|
|
$titleList[] = 'PARKUR'; // api_get_setting('siteName'); |
|
47
|
|
|
$titleList[] = ucfirst(str_replace('-', ' ', $title)); // Page title |
|
48
|
|
|
|
|
49
|
|
|
$titleString = ''; |
|
50
|
|
|
for ($i = 0; $i < count($titleList); $i++) { |
|
|
|
|
|
|
51
|
|
|
$titleString .= $titleList[$i]; |
|
52
|
|
|
if (isset($titleList[$i + 1])) { |
|
53
|
|
|
$item = trim($titleList[$i + 1]); |
|
54
|
|
|
if (!empty($item)) { |
|
55
|
|
|
$titleString .= ' - '; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $titleString; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the name of the extension. |
|
65
|
|
|
* |
|
66
|
|
|
* @return string The extension name |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getName() |
|
69
|
|
|
{ |
|
70
|
|
|
return 'chamilo_extension'; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: