示例#1
0
 public static function createNewPoint($arPoint = array())
 {
     if (!isset($arPoint['NAME'])) {
         $arPoint['NAME'] = 'ПТ';
         $arPoint['AUTO'] = true;
     } else {
         $arPoint['AUTO'] = false;
     }
     if (!isset($arPoint['TYPE'])) {
         $arPoint['TYPE'] = static::getDefaultPointTypeID();
     }
     if (!isset($arPoint['LON']) || strlen($arPoint['LON']) < 2 || (!isset($arPoint['LAT']) || strlen($arPoint['LAT']) < 2)) {
         if (isset($arPoint['ADDRESS']) && strlen($arPoint['ADDRESS']) > 3) {
             if ($arCoords = static::getCoordsByAddressYandex($arPoint['ADDRESS'])) {
                 $arPoint['LON'] = $arCoords['lon'];
                 $arPoint['LAT'] = $arCoords['lat'];
             } else {
                 //TODO:Вывод ошибки о том, что данные не добавлены, так как нет ответа яндекс
                 return false;
             }
         }
     }
     if ($arPoint['AUTO']) {
         $arPoint['NAME'] .= ' (' . $arPoint['LON'] . ', ' . $arPoint['LAT'] . ')';
     }
     $arAdd[] = array('NAME' => $arPoint['NAME'], 'POINT_TYPES_ID' => $arPoint['TYPE'], 'ADDRESS' => $arPoint['ADDRESS'], 'LATITUDE' => $arPoint['LAT'], 'LONGITUDE' => $arPoint['LON']);
     $query = new Query('insert');
     $query->setInsertParams($arAdd, Tables\PointsTable::getTableName(), Tables\PointsTable::getMapArray());
     $res = $query->exec();
     if ($res->getResult()) {
         return $res->getInsertId();
     } else {
         return false;
     }
 }