Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dealadd.php
1<?php
3
4
8
9class DealAdd extends Base
10 implements INamingEntity
11{
12 public function adds(array $params)
13 {
14 $contact = new RefreshClient\Contact();
15 $contact->refresh($params);
16
17 $company = new RefreshClient\Company();
18 $company->refresh($params);
19
21 /*foreach ($company->getCollection() as $company)
22 {
23 if($company->hasError())
24 {
26 }
27 }*/
28
29 $listFields = static::prepareFields($params);
30 $deal = new Batchable\Deal();
31 $deal
32 ->init($listFields)
33 ->adds();
34
35 $activity = new ActivityAdd();
36 $activity->adds($activity::prepareFields($params));
37 }
38
39 static public function prepareFields($params)
40 {
41 $userCollection = Batchable\Client::getUserCollectionFromOrderList($params);
42
43 $result = [];
45 foreach ($userCollection as $item)
46 {
47 foreach ($params as $index=>$param)
48 {
49 if($index == $item->getInternalIndex())
50 {
51 if($item->getEntity()->getType() == User\EntityType::TYPE_I)
52 {
53 $result[$index] = [
54 //'ID' => $param['ID'],
55 'TITLE' => static::getNamingEntity($param),
56 'CONTACT_ID' => static::getDestinationEntityId($item),
57 'PRICE' => $param['PRICE'],
58 'CURRENCY' => $param['CURRENCY']
59 ];
60 }
61 elseif($item->getEntity()->getType() == User\EntityType::TYPE_E)
62 {
63 $result[$index] = [
64 //'ID' => $param['ID'],
65 'TITLE' => static::getNamingEntity($param),
66 'COMPANY_ID' => static::getDestinationEntityId($item),
67 'PRICE' => $param['PRICE'],
68 'CURRENCY' => $param['CURRENCY']
69 ];
70 }
71 }
72 }
73 }
74 return $result;
75 }
76
77 static protected function getDestinationEntityId(User\Container\Item $item)
78 {
79 $client = static::resolveClient($item->getEntity()->getType());
80 $relation = static::loadRelation($item->getEntity()->getId(), $client->getSrcEntityTypeId(), $client->getDstEntityTypeId());
81
82 return ($relation instanceof Relation) ? $relation->getDestinationEntityId():0;
83 }
84
85 static protected function resolveClient($userTypeId)
86 {
87 if(User\EntityType::isDefined($userTypeId))
88 {
89 if($userTypeId == User\EntityType::TYPE_I)
90 {
91 return new Batchable\Contact();
92 }
93 elseif($userTypeId == User\EntityType::TYPE_E)
94 {
95 return new Batchable\Company();
96 }
97 }
98 throw new \Bitrix\Main\NotSupportedException("UserTypeId : '".$userTypeId."' is not supported in current context");
99 }
100
101 static public function getNamingEntity(array $fields)
102 {
103 return 'new Deal by order: '.$fields['ID'];
104 }
105}
static getDestinationEntityId(User\Container\Item $item)
Definition dealadd.php:77