Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userindex.php
1<?php
2namespace Bitrix\Main;
3
7
8Loc::loadMessages(__FILE__);
9
35class UserIndexTable extends Main\Entity\DataManager
36{
42 public static function getTableName()
43 {
44 return 'b_user_index';
45 }
46
53 public static function getMap()
54 {
55 return array(
56 'USER_ID' => array(
57 'data_type' => 'integer',
58 'primary' => true,
59 ),
60 'SEARCH_USER_CONTENT' => array(
61 'data_type' => 'text',
62 ),
63 'SEARCH_ADMIN_CONTENT' => array(
64 'data_type' => 'text',
65 ),
66 'SEARCH_DEPARTMENT_CONTENT' => array(
67 'data_type' => 'text',
68 ),
69 'NAME' => array(
70 'data_type' => 'string'
71 ),
72 'SECOND_NAME' => array(
73 'data_type' => 'string'
74 ),
75 'LAST_NAME' => array(
76 'data_type' => 'string'
77 ),
78 'WORK_POSITION' => array(
79 'data_type' => 'string'
80 ),
81 'UF_DEPARTMENT_NAME' => array(
82 'data_type' => 'string'
83 ),
84 );
85 }
86
87 protected static function getMergeFields()
88 {
89 return array('USER_ID');
90 }
91
92 public static function merge(array $data)
93 {
94 global $DB;
95
96 $result = new Entity\AddResult();
97
98 $helper = Application::getConnection()->getSqlHelper();
99 $insertData = $data;
100 $updateData = $data;
101 $mergeFields = static::getMergeFields();
102
103 foreach ($mergeFields as $field)
104 {
105 unset($updateData[$field]);
106 }
107
108 if (isset($updateData['SEARCH_USER_CONTENT']))
109 {
110 $value = $DB->forSql($updateData['SEARCH_USER_CONTENT']);
111 $encryptedValue = sha1($updateData['SEARCH_USER_CONTENT']);
112 $updateData['SEARCH_USER_CONTENT'] = new \Bitrix\Main\DB\SqlExpression("case when " . $helper->getSha1Function(static::getTableName().".SEARCH_USER_CONTENT") . " = '{$encryptedValue}' then ".static::getTableName().".SEARCH_USER_CONTENT else '{$value}' end");
113 }
114
115 if (isset($updateData['SEARCH_DEPARTMENT_CONTENT']))
116 {
117 $value = $DB->forSql($updateData['SEARCH_DEPARTMENT_CONTENT']);
118 $encryptedValue = sha1($updateData['SEARCH_DEPARTMENT_CONTENT']);
119 $updateData['SEARCH_DEPARTMENT_CONTENT'] = new \Bitrix\Main\DB\SqlExpression("case when " . $helper->getSha1Function(static::getTableName().".SEARCH_DEPARTMENT_CONTENT") ." = '{$encryptedValue}' then ".static::getTableName().".SEARCH_DEPARTMENT_CONTENT else '{$value}' end");
120 }
121
122 if (isset($updateData['SEARCH_ADMIN_CONTENT']))
123 {
124 $value = $DB->forSql($updateData['SEARCH_ADMIN_CONTENT']);
125 $encryptedValue = sha1($updateData['SEARCH_ADMIN_CONTENT']);
126 $updateData['SEARCH_ADMIN_CONTENT'] = new \Bitrix\Main\DB\SqlExpression("case when " . $helper->getSha1Function(static::getTableName().".SEARCH_ADMIN_CONTENT") . " = '{$encryptedValue}' then ".static::getTableName().".SEARCH_ADMIN_CONTENT else '{$value}' end");
127 }
128
129 $merge = $helper->prepareMerge(
130 static::getTableName(),
131 static::getMergeFields(),
132 $insertData,
133 $updateData
134 );
135
136 if ($merge[0] != "")
137 {
138 Application::getConnection()->query($merge[0]);
139 $id = Application::getConnection()->getInsertedId();
140 $result->setId($id);
141 $result->setData($data);
142 }
143 else
144 {
145 $result->addError(new Error('Error constructing query'));
146 }
147
148 return $result;
149 }
150}
static getConnection($name="")
static loadMessages($file)
Definition loc.php:64
static merge(array $data)
Definition userindex.php:92