123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- $unit_code = $argv[1];
- $api_key = $argv[2];
- processUnit($unit_code, 0);
- function createPersonBySubscriber($appointment) {
- static $setPersons = array();
- static $personId = 1;
- if (!isset($appointment['Subscriber'])) {
- return NULL;
- }
- $subscriber = $appointment['Subscriber'];
- if (!isset($subscriber['Key'])) {
- return NULL;
- }
- $key = $subscriber['Key'];
- if (isset($setPersons[$key])) {
- return $setPersons[$key]['id'];
- }
- /*
- [Subscriber] => Array
- (
- [Firstname] => Татьяна
- [Lastname] => Воропаева
- [Patronymic] => Михайловна
- [Key] => -19527
- [DisplayName] => Воропаева Т М
- [DisplayNameLatin] => Voropaeva T M
- [PhotoUrl] => /public/photos/oldvoip/19527-Voropaeva Tat'yana Mihaylovna.jpg
- )
- */
- $login = 'NULL';
- if (isset($subscriber['Login'])) {
- $login = '"'.$subscriber['Login'].'"';
- }
- $person = $subscriber;
- $person['id'] = $personId;
- if (substr($person['PhotoUrl'], 0, 1) == '/') {
- $person['PhotoUrl'] = 'https://voip.mephi.ru'.$person['PhotoUrl'];
- }
- print 'INSERT INTO `people` SET id='.$person['id'].', login='.$login.', `firstname`="'.$person['Firstname'].'", `lastname`="'.$person['Lastname'].'", `patronymic`="'.$person['Patronymic'].'", `photo_url`="'.$person['PhotoUrl'].'"'.", created_at=NOW(), updated_at=NOW();\n";
- $personId++;
- $setPersons[$key] = $person;
- return $person['id'];
- }
- function processUnit($unit_code, $parent_id) {
- global $api_key;
- static $unitId = 1;
- static $appointmentId = 1;
- $unit = json_decode(file_get_contents('https://voip.mephi.ru/units/'.$unit_code.'.json?renderFilter=unit_selected&apiKey='.$api_key.'&effectiveSecurityLevel=1024'), 1)['unit_selected'];
- /*
- [Unit] => Array
- (
- [ExtId] => -1568
- [CodeStr] => 01 250 05
- [Name] => Управления
- [Fullname] => Управления (Обнинский Институт Атомной Энергетики)
- [Shortname] => Управления
- [AccountCode] => 250
- [ParentsCodeStr] => 01 250 00
- [DontInflect] => 1
- [AppointmentsOrderStr] => -25200451
- [AppointmentsOrder] => Array
- (
- [0] => -25200451
- )
- [Code] => Array
- (
- [Maj] => 1
- [Mid] => 250
- [Min] => 5
- )
- )
- */
- //print_r($unit);
- $unit['id'] = $unitId++;
- $code = @$unit['Code']['Min'];
- if (empty($code)) {
- $code = 'NULL';
- } else {
- $code = '"'.str_pad($code, 2, '0', STR_PAD_LEFT).'"';
- }
- print 'INSERT INTO `units` SET id='.$unit['id'].', code='.$code.', `name`="'.$unit['Name'].'", `parent_id` = "'.$parent_id.'"'.", created_at=NOW(), updated_at=NOW();\n";
- if (isset($unit['AppointmentsForRender'])) {
- foreach ($unit['AppointmentsForRender'] as $appointment) {
- $personId = createPersonBySubscriber($appointment);
- if (is_null($personId)) {
- continue;
- }
- $appointment['id'] = $appointmentId++;
- if (!isset($appointment['Name'])) {
- continue;
- }
- print 'INSERT INTO `appointments` SET id='.$appointment['id'].', person_id='.$personId.', `unit_id`="'.$unit['id'].'", `name`="'.$appointment['Name'].'", `description`="'.@$appointment['Description'].'", `line`="'.@$appointment['EffectiveExtension'].'", `room`="'.@$appointment['Room']['Name'].'"'.", created_at=NOW(), updated_at=NOW();\n";
- }
- }
- if (isset($unit['Children'])) {
- foreach ($unit['Children'] as $child) {
- processUnit($child['CodeStr'], $unit['id']);
- }
- }
- }
- ?>
|