32 return 'b_tmp_export_tree';
40 'data_type' =>
'integer',
42 'autocomplete' =>
true,
46 'data_type' =>
'string',
48 'PARENT_CODE' => array(
49 'data_type' =>
'string',
52 'data_type' =>
'string',
56 'data_type' =>
'string',
59 'data_type' =>
'string',
62 'data_type' =>
'string',
66 'data_type' =>
'string',
69 'data_type' =>
'string',
72 'data_type' =>
'string',
75 'data_type' =>
'string',
78 'data_type' =>
'string',
81 'ALTERNATE_COORDS' => array(
82 'data_type' =>
'string',
84 'BOUNDED_WITH' => array(
85 'data_type' =>
'string',
95 'entityName' => get_called_class(),
96 'exactFields' => array(
97 'ID',
'CODE',
'PARENT_CODE',
'SYS_CODE',
'TYPE_CODE',
'FIAS_TYPE',
'NAME',
'LANGNAMES',
'EXTERNALS',
'LATITUDE',
'LONGITUDE',
'SOURCE'
99 'parameters' => array(
101 'autoIncrementFld' =>
'ID'
113 $this->exportOffset = $offset;
118 $this->codeIndex = array();
123 if(isset($this->codeIndex[$data[
'SYS_CODE']]))
126 $this->codeIndex[$data[
'SYS_CODE']] = $this->
formatCode($this->exportOffset);
128 $data[
'CODE'] = $this->codeIndex[$data[
'SYS_CODE']];
129 $data[
'PARENT_CODE'] = strlen($data[
'PARENT_SYS_CODE']) ? $this->codeIndex[$data[
'PARENT_SYS_CODE']] :
'';
131 unset($data[
'PARENT_SYS_CODE']);
133 if(is_array($data[
'LANGNAMES']))
134 $data[
'LANGNAMES'] = serialize($data[
'LANGNAMES']);
136 if(is_array($data[
'EXTERNALS']))
137 $data[
'EXTERNALS'] = serialize($data[
'EXTERNALS']);
139 $this->exportOffset++;
141 $this->inserter->insert($data);
146 $this->inserter->flush();
156 $res = static::getList(array(
'order' => array(
'ID' =>
'desc'),
'limit' => 1,
'select' => array(
'CODE')))->fetch();
166 public static function formatCode($value, $length = self::CODE_LENGTH)
168 if(strlen($value) >= $length)
171 $diff = abs($length - strlen($value));
173 for($i = 0; $i < $diff; $i++)
181 return static::getList(array(
'filter' => array(
192 $node = $this->
getByCode($nextCode)->fetch();
195 $nextCode = $node[
'PARENT_CODE'];
209 foreach ($this->exportPath as $item)
211 $res[] = $item[
'NAME'].
' ('.$item[
'TYPE_CODE'].
')';
214 return implode(
', ', $res);
217 public function walkInDeep($callbacks, $ignoreThisAndDeeper = array(), $startFrom =
'')
219 if(!is_callable($callbacks[
'ITEM']))
222 $this->exportPath = array();
223 $this->waklInDeepBundle($callbacks, $ignoreThisAndDeeper, $startFrom);
226 private function waklInDeepBundle($callbacks, $ignoreThisAndDeeper = array(), $parentCode =
'', $depth = 1)
228 if($depth > static::RECURSION_MAX_DEPTH)
231 $res = $this->getList(array(
'filter' => array(
'PARENT_CODE' => $parentCode)));
232 while($item = $res->fetch())
234 array_push($this->exportPath, $item);
237 if(call_user_func($callbacks[
'ITEM'], $item, $this) ===
false)
240 if(isset($ignoreThisAndDeeper[$item[
'TYPE_CODE']]))
244 $this->waklInDeepBundle($callbacks, $ignoreThisAndDeeper, $item[
'CODE'], $depth + 1);
246 array_pop($this->exportPath);
252 $dbConnection = Main\HttpApplication::getConnection();
254 $table = static::getTableName();
258 if(!$DB->query(
'select * from '.$table.
' where 1=0',
true))
260 $dbConnection->query(
'create table '.$table.
' (
262 ID int auto_increment not null primary key,
264 CODE varchar(100) not null,
265 PARENT_CODE varchar(100),
266 SYS_CODE varchar(100),
268 TYPE_CODE varchar(20),
269 FIAS_TYPE varchar(10),
271 NAME varchar(100) not null,
273 LANGNAMES varchar(300),
274 EXTERNALS varchar(200),
276 LATITUDE varchar(30),
277 LONGITUDE varchar(30),
279 ALTERNATE_COORDS varchar(100),
280 BOUNDED_WITH varchar(100),
291 $dbConnection = Main\HttpApplication::getConnection();
292 $table = static::getTableName();
296 $dbConnection->query(
'DROP INDEX IX_SALE_LOCATION_EXPORT_TREE_CODE ON '.$table);
304 $dbConnection->query(
'DROP INDEX IX_SALE_LOCATION_EXPORT_TREE_PARENT_CODE ON '.$table);
312 $dbConnection->query(
'DROP INDEX IX_SALE_LOCATION_EXPORT_TREE_TYPE_CODE ON '.$table);
321 $dbConnection = Main\HttpApplication::getConnection();
322 $table = static::getTableName();
326 $dbConnection->query(
'CREATE INDEX IX_SALE_LOCATION_EXPORT_TREE_CODE ON '.$table.
' (CODE)');
334 $dbConnection->query(
'CREATE INDEX IX_SALE_LOCATION_EXPORT_TREE_PARENT_CODE ON '.$table.
' (PARENT_CODE)');
342 $dbConnection->query(
'CREATE INDEX IX_SALE_LOCATION_EXPORT_TREE_TYPE_CODE ON '.$table.
' (TYPE_CODE)');
351 Main\HttpApplication::getConnection()->query(
'truncate table '.static::getTableName());
356 Main\HttpApplication::getConnection()->query(
'alter table '.static::getTableName().
' '.($way ?
'enable' :
'disable').
' keys');
359 public function output($data, $important =
true)
366 $data = ob_get_contents();
369 file_put_contents($_SERVER[
'DOCUMENT_ROOT'].
'/output.txt', $data.PHP_EOL, FILE_APPEND);