Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
timemanentry.php
1<?php
2
4
8use Bitrix\Timeman\Model\Worktime\Record\WorktimeRecordTable;
9
10Loc::loadMessages(__FILE__);
11
12final class TimemanEntry extends Provider
13{
14 public const PROVIDER_ID = 'TIMEMAN_ENTRY';
15 public const CONTENT_TYPE_ID = 'TIMEMAN_ENTRY';
16
17 public static function getId(): string
18 {
19 return static::PROVIDER_ID;
20 }
21
22 public function getEventId(): array
23 {
24 return [ 'timeman_entry' ];
25 }
26
27 public function getType(): string
28 {
30 }
31
32 public function getCommentProvider(): Provider
33 {
34 return new ForumPost();
35 }
36
37 public function initSourceFields()
38 {
39 static $cache = [];
40
41 $timemanEntryId = $this->entityId;
42
43 if ($timemanEntryId <= 0)
44 {
45 return;
46 }
47
48 if (isset($cache[$timemanEntryId]))
49 {
50 $timemanEntry = $cache[$timemanEntryId];
51 }
52 elseif (Loader::includeModule('timeman'))
53 {
54 $res = WorktimeRecordTable::getList([
55 'filter' => [
56 'ID' => $timemanEntryId
57 ],
58 'select' => [ 'ID', 'USER_ID', 'DATE_START', 'APPROVED_BY' ]
59 ]);
60 $timemanEntry = $res->fetch();
61 $cache[$timemanEntryId] = $timemanEntry;
62 }
63
64 if (!empty($timemanEntry))
65 {
66 $this->setSourceFields($timemanEntry);
67
68 $userName = '';
69 $res = \CUser::getById($timemanEntry['USER_ID']);
70 if ($userFields = $res->fetch())
71 {
72 $userName = \CUser::formatName(
73 \CSite::getNameFormat(),
74 $userFields,
75 true,
76 false
77 );
78 }
79
80 $this->setSourceTitle(Loc::getMessage('SONET_LIVEFEED_TIMEMAN_ENTRY_TITLE', [
81 '#USER_NAME#' => $userName,
82 '#DATE#' => FormatDate('j F', makeTimeStamp($timemanEntry['DATE_START']))
83 ]));
84 }
85 else
86 {
87 $this->setSourceTitle($this->getUnavailableTitle());
88 }
89 }
90
91 public function getPinnedDescription(): string
92 {
93 $result = '';
94
95 if (empty($this->sourceFields))
96 {
97 $this->initSourceFields();
98 }
99
100 $timemanEntry = $this->getSourceFields();
101 if (empty($timemanEntry))
102 {
103 return $result;
104 }
105
106 return (string)Loc::getMessage((int)$timemanEntry['APPROVED_BY'] <= 0 ? 'SONET_LIVEFEED_TIMEMAN_ENTRY_PINNED_DESCRIPTION' : 'SONET_LIVEFEED_TIMEMAN_ENTRY_PINNED_DESCRIPTION2');
107 }
108
109 public static function canRead($params): bool
110 {
111 return true;
112 }
113
114 protected function getPermissions(array $post): string
115 {
117 }
118
119 public function getLiveFeedUrl(): string
120 {
121 $pathToLogEntry = '';
122
123 $logId = $this->getLogId();
124 if ($logId)
125 {
126 $pathToLogEntry = Option::get('socialnetwork', 'log_entry_page', '', $this->getSiteId());
127 if (!empty($pathToLogEntry))
128 {
129 $pathToLogEntry = \CComponentEngine::makePathFromTemplate($pathToLogEntry, [ 'log_id' => $logId ]);
130 }
131 }
132 return $pathToLogEntry;
133 }
134}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
Definition forumpost.php:22
initSourceFields()
getCommentProvider()
const CONTENT_TYPE_ID
getPermissions(array $post)
getType()
getLiveFeedUrl()
getEventId()
static canRead($params)
static getId()
const PROVIDER_ID
getPinnedDescription()