Exemplo n.º 1
0
 public static function addNewModel($brandID = null, $modelName = null)
 {
     try {
         if (is_null($modelName)) {
             throw new ArgumentNullException('model_name');
         } else {
             $modelName = htmlspecialchars($modelName);
         }
         if (is_null($brandID)) {
             throw new ArgumentNullException('brandID');
         }
         $arInsert[0] = array('BRANDS_ID' => $brandID, 'NAME' => $modelName);
         $query = new Query('insert');
         $query->setInsertParams($arInsert, CarModelTable::getTableName(), CarModelTable::getMapArray());
         $res = $query->exec();
         if ($res->getResult()) {
             return $res->getInsertId();
         }
     } catch (ArgumentNullException $e) {
         $e->showException();
     }
 }
Exemplo n.º 2
0
 /**
  * Получает развернутые данные об автомобиле из других таблиц
  *
  * @param $arResult
  *
  * @return mixed
  */
 protected static function fetchCarData($arResult)
 {
     $myCarMap = MyCarTable::getMapArray();
     $carBodyMap = CarBodyTable::getMapArray();
     $carBrandMap = CarBrandTable::getMapArray();
     $carGearboxMap = CarGearboxTable::getMapArray();
     $carModelMap = CarModelTable::getMapArray();
     foreach ($arResult as $key => &$arCar) {
         foreach ($arCar as $field => &$value) {
             if (isset($myCarMap[$field])) {
                 $value = $myCarMap[$field]->fetchDataModification($value);
             } elseif (strstr($field, 'BRAND_')) {
                 switch ($field) {
                     case 'BRAND_ID':
                         $value = $carBrandMap['ID']->fetchDataModification($value);
                         $arCar['BRAND']['ID'] = $value;
                         break;
                     case 'BRAND_NAME':
                         $value = $carBrandMap['NAME']->fetchDataModification($value);
                         $arCar['BRAND']['NAME'] = $value;
                         break;
                     case 'BRAND_CODE':
                         $value = $carBrandMap['CODE']->fetchDataModification($value);
                         $arCar['BRAND']['CODE'] = $value;
                         break;
                 }
             } elseif (strstr($field, 'MODEL_')) {
                 switch ($field) {
                     case 'MODEL_ID':
                         $value = $carModelMap['ID']->fetchDataModification($value);
                         $arCar['MODEL']['ID'] = $value;
                         break;
                     case 'MODEL_NAME':
                         $value = $carModelMap['NAME']->fetchDataModification($value);
                         $arCar['MODEL']['NAME'] = $value;
                         break;
                     case 'MODEL_BRANDS_ID':
                         $value = $carModelMap['BRANDS_ID']->fetchDataModification($value);
                         $arCar['MODEL']['BRAND_ID'] = $value;
                         break;
                     case 'MODEL_CODE':
                         $value = $carModelMap['CODE']->fetchDataModification($value);
                         $arCar['MODEL']['CODE'] = $value;
                         break;
                 }
             } elseif (strstr($field, 'GEARBOX_')) {
                 switch ($field) {
                     case 'GEARBOX_ID':
                         $value = $carGearboxMap['ID']->fetchDataModification($value);
                         $arCar['GEARBOX']['ID'] = $value;
                         break;
                     case 'GEARBOX_NAME':
                         $value = $carGearboxMap['NAME']->fetchDataModification($value);
                         $arCar['GEARBOX']['NAME'] = $value;
                         break;
                     case 'GEARBOX_CODE':
                         $value = $carGearboxMap['CODE']->fetchDataModification($value);
                         $arCar['GEARBOX']['CODE'] = $value;
                         break;
                 }
             } elseif (strstr($field, 'BODY_')) {
                 switch ($field) {
                     case 'BODY_ID':
                         $value = $carBodyMap['ID']->fetchDataModification($value);
                         $arCar['BODY']['ID'] = $value;
                         break;
                     case 'BODY_NAME':
                         $value = $carBodyMap['NAME']->fetchDataModification($value);
                         $arCar['BODY']['NAME'] = $value;
                         break;
                     case 'BODY_CODE':
                         $value = $carBodyMap['CODE']->fetchDataModification($value);
                         $arCar['BODY']['CODE'] = $value;
                         break;
                 }
             }
         }
         unset($value);
     }
     unset($arCar);
     return $arResult;
 }