Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
querydata.php
1<?php
10
16
17Loc::loadMessages(__FILE__);
18
24{
33 public static function getUnionizedQuery(array $queries, $dataTypeId = null, PageNavigation $nav = null)
34 {
35 foreach ($queries as $query)
36 {
37 self::prepare($query, $dataTypeId);
38 }
39
40 $query = array_pop($queries);
41 foreach ($queries as $unionQuery)
42 {
43 $query->unionAll($unionQuery);
44 }
45
46 if ($nav)
47 {
48 if (empty($queries))
49 {
50 $query->setOffset($nav->getOffset());
51 $query->setLimit($nav->getLimit());
52 }
53 else
54 {
55 $query->setUnionOffset($nav->getOffset());
56 $query->setUnionLimit($nav->getLimit());
57 }
58 }
59
60 return $query;
61 }
62
69 public static function getUnionizedData(Entity\Query $query)
70 {
71 return self::exec($query);
72 }
73
74 private static function prepare(Entity\Query $query, $dataTypeId = null)
75 {
76 $fields = self::getSelectFields();
77 foreach ($fields as $alias => $field)
78 {
79 if (is_numeric($alias))
80 {
81 $alias = '';
82 }
83
84 $query->addGroup('ID');
85 $query->addSelect($field, $alias);
86 }
87
88 return Helper::prepareQuery($query, $dataTypeId);
89 }
90
91 private static function exec(Entity\Query $query)
92 {
93 $result = $query->exec();
94 $result->addFetchDataModifier(
95 function ($data)
96 {
97 {
98 if (isset($data['EMAIL_MAILING']) && $data['EMAIL_MAILING'])
99 {
100 $data['EMAIL'] = $data['EMAIL_MAILING'];
101 }
102 elseif (isset($data['EMAIL_HOME']) && $data['EMAIL_HOME'])
103 {
104 $data['EMAIL'] = $data['EMAIL_HOME'];
105 }
106 else if (isset($data['EMAIL_WORK']) && $data['EMAIL_WORK'])
107 {
108 $data['EMAIL'] = $data['EMAIL_WORK'];
109 }
110 }
111
112 {
113 if (isset($data['PHONE_MAILING']) && $data['PHONE_MAILING'])
114 {
115 $data['PHONE'] = $data['PHONE_MAILING'];
116 }
117 elseif (isset($data['PHONE_MOBILE']) && $data['PHONE_MOBILE'])
118 {
119 $data['PHONE'] = $data['PHONE_MOBILE'];
120 }
121 else if (isset($data['PHONE_WORK']) && $data['PHONE_WORK'])
122 {
123 $data['PHONE'] = $data['PHONE_WORK'];
124 }
125 }
126
127 return $data;
128 }
129 );
130
131 return $result;
132 }
133
141 public static function getData(Entity\Query $query, $dataTypeId = null)
142 {
143 self::prepare($query, $dataTypeId);
144 return self::exec($query);
145 }
146
147 protected static function getSelectFields($dataTypeId = null)
148 {
149 $fields = array();
150
151 $map = array(
152 Recipient\Type::EMAIL => array('EMAIL'), //array('EMAIL_HOME', 'EMAIL_WORK'),
153 Recipient\Type::PHONE => array('PHONE'), //array('PHONE_WORK', 'PHONE_MOBILE'),
154 Recipient\Type::IM => array('IM' => 'IMOL'),
155 Recipient\Type::CRM_CONTACT_ID => array('CRM_CONTACT_ID'),
156 Recipient\Type::CRM_COMPANY_ID => array('CRM_COMPANY_ID'),
157 );
158 if ($dataTypeId)
159 {
160 if (isset($map[$dataTypeId]))
161 {
162 $fields = $map[$dataTypeId];
163 }
164 }
165 else
166 {
167 $fields = call_user_func_array('array_merge', array_values($map));
168 }
169
170 return $fields;
171 }
172}
static loadMessages($file)
Definition loc.php:64
static prepareQuery(Entity\Query $query, $dataTypeId=null, $entityDbName=null, $entityName=null)
Definition helper.php:268
static getData(Entity\Query $query, $dataTypeId=null)
static getUnionizedQuery(array $queries, $dataTypeId=null, PageNavigation $nav=null)
Definition querydata.php:33