Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
recent.php
1<?php
9
12use Bitrix\Main\Entity\ExpressionField;
13
16
17Loc::loadMessages(__FILE__);
18
23class Recent
24{
25 private static $maxCount = 4;
26 private static $cacheTtl = 3600;
27
36 public static function onPresetTemplateList($templateType = null, $templateId = null, $messageCode = null)
37 {
38 if($templateType)
39 {
40 return array();
41 }
42
43 if (!$templateId)
44 {
45 $templateId = null;
46 }
47
48 return self::getTemplates($messageCode);
49 }
50
51 private static function getTemplates($messageCode = null)
52 {
53 static $result = null;
54 if ($result !== null)
55 {
56 return $result;
57 }
58 $result = array();
59
60 $filter = array(
61 '!=TEMPLATE_TYPE' => null,
62 '!=TEMPLATE_ID' => null,
63 );
64 $userId = Security\User::current()->getId();
65 if ($userId)
66 {
67 $filter['=CREATED_BY'] = $userId;
68 }
69 if ($messageCode)
70 {
71 $filter['=MESSAGE_CODE'] = $messageCode;
72 }
73
74 $chains = Entity\Letter::getList(array(
75 'select' => array('TEMPLATE_TYPE', 'TEMPLATE_ID'),
76 'filter' => $filter,
77 'runtime' => array(new ExpressionField('MAX_ID', 'MAX(%s)', 'ID')),
78 'limit' => self::$maxCount + 1,
79 'cache' => array('ttl' => self::$cacheTtl),
80 'group' => array('TEMPLATE_TYPE', 'TEMPLATE_ID'),
81 'order' => array('MAX_ID' => 'DESC'),
82 ));
83 foreach ($chains as $chain)
84 {
85 $template = Selector::create()
86 ->withTypeId($chain['TEMPLATE_TYPE'])
87 ->withId($chain['TEMPLATE_ID'])
88 ->get();
89
90 if (!$template)
91 {
92 continue;
93 }
94
95 if ($template['TYPE'] === Type::getCode(Type::BASE) && $template['ID'] === 'empty')
96 {
97 continue;
98 }
99
100 $template['CATEGORY'] = Category::getCode(Category::RECENT);
101 $result[] = $template;
102
103 if (count($result) >= self::$maxCount)
104 {
105 break;
106 }
107 }
108
109 return $result;
110 }
111}
static loadMessages($file)
Definition loc.php:64
static onPresetTemplateList($templateType=null, $templateId=null, $messageCode=null)
Definition recent.php:36