Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
recipiententry.php
1<?php
3
4use Bitrix\Crm\Timeline;
5use Bitrix\Crm\Timeline\Entity\TimelineTable;
8
13class RecipientEntry extends Timeline\TimelineEntry
14{
22 public static function create(array $params)
23 {
24 $entityTypeId = isset($params['ENTITY_TYPE_ID']) ? (int)$params['ENTITY_TYPE_ID'] : 0;
25 if($entityTypeId <= 0)
26 {
27 throw new Main\ArgumentException('Entity type ID must be greater than zero.', 'entityTypeID');
28 }
29
30 $entityId = isset($params['ENTITY_ID']) ? (int)$params['ENTITY_ID'] : 0;
31 if($entityId <= 0)
32 {
33 throw new Main\ArgumentException('Entity ID must be greater than zero.', 'entityID');
34 }
35
36 $typeCategoryId = isset($params['TYPE_CATEGORY_ID']) ? $params['TYPE_CATEGORY_ID'] : 0;
37 if(!$typeCategoryId)
38 {
39 throw new Main\ArgumentException('Type category ID must not be empty.', 'typeCategoryId');
40 }
41
42 $authorId = isset($params['AUTHOR_ID']) ? (int) $params['AUTHOR_ID'] : 0;
43 if(!is_int($authorId))
44 {
45 $authorId = (int) $authorId;
46 }
47
48 if($authorId <= 0)
49 {
50 throw new Main\ArgumentException('Author ID must be greater than zero.', 'authorID');
51 }
52
53 $created = (isset($params['CREATED']) && ($params['CREATED'] instanceof DateTime)) ? $params['CREATED'] : new DateTime();
54 $settings = isset($params['SETTINGS']) && is_array($params['SETTINGS']) ? $params['SETTINGS'] : array();
55
56 $result = TimelineTable::add(
57 array(
58 'TYPE_ID' => Timeline\TimelineType::SENDER,
59 'TYPE_CATEGORY_ID' => $typeCategoryId,
60 'CREATED' => $created,
61 'AUTHOR_ID' => $authorId,
62 'SETTINGS' => $settings,
63 'ASSOCIATED_ENTITY_TYPE_ID' => $entityTypeId,
64 'ASSOCIATED_ENTITY_ID' => $entityId
65 )
66 );
67
68 if(!$result->isSuccess())
69 {
70 return 0;
71 }
72 $id = $result->getId();
73
74 $bindings = isset($params['BINDINGS']) && is_array($params['BINDINGS']) ? $params['BINDINGS'] : array();
75 if(empty($bindings))
76 {
77 $bindings[] = array('ENTITY_TYPE_ID' => $entityTypeId, 'ENTITY_ID' => $entityId);
78 }
79 self::registerBindings($id, $bindings);
80
81 return $id;
82 }
90 public static function createMulti(array $parameters)
91 {
92 $ids = [];
93 foreach ($parameters as $params)
94 {
95 $ids[] = self::create($params);
96 }
97
98 return $ids;
99 }
100}
static createMulti(array $parameters)
static create(array $params)