public static function setOption($optionName, $optionValue) { $optionName = strtoupper($optionName); if (!isset(static::$arOptions[$optionName])) { $arInsert = array('NAME' => $optionName, 'VALUE' => $optionValue); $result = Tables\OptionsTable::getList(array("filter" => array("NAME" => $optionName))); if ($result) { $query = new Query('update'); $query->setUpdateParams($arInsert, $result[0]['ID'], Tables\OptionsTable::getTableName(), Tables\OptionsTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { static::$arOptions[$optionName] = $optionValue; return true; } else { return false; } } else { $query = new Query('insert'); $query->setInsertParams($arInsert, Tables\OptionsTable::getTableName(), Tables\OptionsTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { static::$arOptions[$optionName] = $optionValue; return true; } else { return false; } } } else { return true; } }
/** * Обновляет данне по автомобилю * * @param array $arData * * @throw Exception\ArgumentNullException * Exception\ArgumentOutOfRangeException * @return \MSergeev\Core\Lib\DBResult */ public static function editCar($arData = array()) { try { if (empty($arData)) { throw new Exception\ArgumentNullException('arData'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } $arMap = MyCarTable::getMapArray(); $arUpdate = array(); foreach ($arData as $field => $value) { try { if (isset($arMap[$field])) { $arUpdate[$field] = $arData[$field]; } else { throw new Exception\ArgumentOutOfRangeException("arData[" . $field . "]"); } } catch (Exception\ArgumentOutOfRangeException $e) { $e->showException(); } } if (isset($arUpdate['DEFAULT']) && $arUpdate['DEFAULT']) { $res = static::uncheckDefaultAllCars(); } $query = new Query('update'); $query->setUpdateParams($arUpdate, null, MyCarTable::getTableName(), MyCarTable::getMapArray()); if (isset($arUpdate['ID']) && intval($arUpdate['ID']) > 0) { $query->setUpdateParams(null, intval($arUpdate['ID'])); } $res = $query->exec(); return $res; }
public static function addValueByTariffID($tariffID, $value, $arDateTime = null) { if (is_null($arDateTime)) { $day = intval(date('d')); $month = intval(date('m')); $year = intval(date('Y')); $hour = date('G'); } else { if (isset($arDateTime['DATE'])) { list($day, $month, $year) = explode('.', $arDateTime['DATE']); } else { if (isset($arDateTime['DAY'])) { $day = intval($arDateTime['DAY']); } else { $day = intval(date('d')); } if (isset($arDateTime['MONTH'])) { $month = intval($arDateTime['MONTH']); } else { $month = intval(date('m')); } if (isset($arDateTime['YEAR'])) { $year = intval($arDateTime['YEAR']); } else { $year = intval(date('Y')); } } if (isset($arDateTime['HOUR'])) { $hour = intval($arDateTime['HOUR']); } else { $hour = intval(date('G')); } } $valuesHourlyTableName = ValuesHourlyTable::getTableName(); //Получаем предыдущее показание счетчика по данному тарифу, сложив все показания за часы $sumValue = self::getCurrentValuesByTariffID($tariffID); //Получаем текущую тарифную ставку $nowRate = Rates::getLastRate($tariffID); //Получаем расход за час $newValue = $value - $sumValue - $nowRate['TARIFF_ID_START_VALUE']; if ($newValue < 0) { $newValue = 0; } //Добавляем часовые значения $arInsert = array('TARIFF_ID' => $tariffID, 'HOUR' => $hour, 'DAY' => $day, 'MONTH' => $month, 'YEAR' => $year, 'VALUE' => $newValue, 'COST' => $newValue * $nowRate['VALUE']); //Проверяем, есть ли данные значения в базе $arRes = ValuesHourlyTable::getList(array('select' => array('ID'), 'filter' => array('TARIFF_ID' => $arInsert['TARIFF_ID'], 'HOUR' => $arInsert['HOUR'], 'DAY' => $arInsert['DAY'], 'MONTH' => $arInsert['MONTH'], 'YEAR' => $arInsert['YEAR']))); if ($arRes) { //Update $query = new Query('update'); $query->setUpdateParams($arInsert, $arRes[0]['ID'], $valuesHourlyTableName, ValuesHourlyTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { return $res->getAffectedRows(); } else { return false; } } else { //Insert $query = new Query('insert'); $query->setInsertParams($arInsert, $valuesHourlyTableName, ValuesHourlyTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { return $res->getInsertId(); } else { return false; } } }
protected static function parseSunRiseSet($city, $arWeather) { $dateHelper = new DateHelper(); list($sunRiseDate, $sunRiseTime) = explode('T', $arWeather['sun']['@attributes']['rise']); $sunRiseDate = $dateHelper->convertDateFromDB($sunRiseDate); $sunRiseTime = explode(':', $sunRiseTime); $sunRiseTime[0] += $city['UTC_HOUR']; if ($sunRiseTime[0] > 23) { $sunRiseTime[0] -= 24; $sunRiseDate = $dateHelper->strToTime($sunRiseDate); } list($sunSetDate, $sunSetTime) = explode('T', $arWeather['sun']['@attributes']['set']); $sunSetDate = $dateHelper->convertDateFromDB($sunSetDate); $sunSetTime = explode(':', $sunSetTime); $sunSetTime[0] += $city['UTC_HOUR']; if ($sunSetTime[0] > 23) { $sunSetTime[0] -= 24; $sunSetDate = $dateHelper->strToTime($sunSetDate); } $sunRiseMin = $sunRiseTime[0] * 60 + $sunRiseTime[1]; $sunSetMin = $sunSetTime[0] * 60 + $sunSetTime[1]; if ($sunSetMin >= $sunRiseMin) { $sunDayMin = $sunSetMin - $sunRiseMin; } else { $sunDayMin = $sunSetMin + 24 * 60 - $sunRiseMin; } $sunDayHour = floor($sunDayMin / 60); $sunDayMin -= $sunDayHour * 60; $arSunRise = SunTable::getList(array('filter' => array('CITY_ID' => $city['ID'], 'DATE' => $sunRiseDate))); $arInsertUpdate = array('CITY_ID' => $city['ID'], 'DATE' => $sunRiseDate, 'SUNRISE' => $sunRiseTime[0] . ':' . $sunRiseTime[1] . ':' . $sunRiseTime[2], 'SUNSET' => $sunSetTime[0] . ':' . $sunSetTime[1] . ':' . $sunSetTime[2], 'DAYTIME' => $sunDayHour . ':' . $sunDayMin . ':00'); if ($arSunRise) { //Update $query = new Query('update'); $query->setUpdateParams($arInsertUpdate, $arSunRise[0]['ID'], SunTable::getTableName(), SunTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { return $res->getInsertId(); } else { return false; } } else { //Insert $query = new Query('insert'); $query->setInsertParams($arInsertUpdate, SunTable::getTableName(), SunTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { return $res->getAffectedRows(); } else { return false; } } }
public static function activateSection($sectionID) { $className = static::getClassName(); $tableName = static::getTableName(); $arUpdate = array('ACTIVE' => true); $query = new Query('update'); $query->setUpdateParams($arUpdate, $sectionID, $tableName, $className::getMapArray()); $res = $query->exec(); return $res; }
/** * Функция высчитывает данные о пройденном расстоянии от выбранной даты или за все время * * @param int $carID * @param string $date */ protected static function updateDayOdometer($carID = null, $date = null) { $dateHelper = new DateHelper(); $arResult = array(); if (is_null($carID)) { $carID = MyCar::getDefaultCarID(); } if (is_null($date)) { //TODO: Проверить работу кода $arRes = Tables\RoutsTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '>ODO' => 0), 'order' => array('DATE' => 'ASC', 'ID' => 'ASC'))); $arResult['BUY_ODO'] = MyCar::getBuyCarOdo($carID); $arResult['MAX_DATE_ODO'] = array(); $bFirst = true; foreach ($arRes as $ar_res) { if ($bFirst) { $bFirst = false; $arResult['FIRST_DAY'] = $ar_res['DATE']; } $arResult['ROUTS'][$ar_res['ID']]['DATE'] = $ar_res['DATE']; $arResult['ROUTS'][$ar_res['ID']]['ODO'] = $ar_res['ODO']; if (!isset($arResult['MAX_DATE_ODO'][$ar_res['DATE']]) || $ar_res['ODO'] > $arResult['MAX_DATE_ODO'][$ar_res['DATE']]) { $arResult['MAX_DATE_ODO'][$ar_res['DATE']] = $ar_res['ODO']; } } $arResult['LAST_DAY'] = date('d.m.Y'); $lastOdo = $arResult['BUY_ODO']; $arResult['DAY_ODO'] = array(); foreach ($arResult['MAX_DATE_ODO'] as $day => $odo) { $arResult['DAY_ODO'][$day] = round($odo - $lastOdo, 1); $lastOdo = $odo; } $arResult['ODO_ALL_DAYS'] = array(); $now_day = $arResult['FIRST_DAY']; while ($now_day !== $arResult['LAST_DAY']) { if (isset($arResult['DAY_ODO'][$now_day])) { $arResult['ODO_ALL_DAYS'][$now_day] = $arResult['DAY_ODO'][$now_day]; } else { $arResult['ODO_ALL_DAYS'][$now_day] = 0; } $now_day = $dateHelper->strToTime($now_day, '+1 day', 'site'); } } else { $arResult['FIRST_DAY'] = $date; $arResult['LAST_DAY'] = date('d.m.Y'); $arResult['BUY_ODO'] = MyCar::getBuyCarOdo($carID); //TODO: Проверить работу кода $arRes = Tables\RoutsTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '>=DATE' => $date, '>ODO' => 0), 'order' => array('DATE' => 'ASC', 'ID' => 'ASC'))); $arResult['MAX_DATE_ODO'] = array(); foreach ($arRes as $ar_res) { $arResult['ROUTS'][$ar_res['ID']]['DATE'] = $ar_res['DATE']; $arResult['ROUTS'][$ar_res['ID']]['ODO'] = $ar_res['ODO']; if (!isset($arResult['MAX_DATE_ODO'][$ar_res['DATE']]) || $ar_res['ODO'] > $arResult['MAX_DATE_ODO'][$ar_res['DATE']]) { $arResult['MAX_DATE_ODO'][$ar_res['DATE']] = $ar_res['ODO']; } } //TODO: Проверить работу кода $arRes2 = Tables\RoutsTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '<DATE' => $date, '>ODO' => 0), 'order' => array('DATE' => 'DESC', 'ID' => 'DESC'))); if ($arRes2) { $lastOdo = $arRes2[0]['ODO']; $arResult['LAST_RES'] = $arRes2[0]; } else { $lastOdo = $arResult['BUY_ODO']; } $arResult['LAST_ODO'] = $lastOdo; $arResult['DAY_ODO'] = array(); foreach ($arResult['MAX_DATE_ODO'] as $day => $odo) { $arResult['DAY_ODO'][$day] = round($odo - $lastOdo, 1); $lastOdo = $odo; } $arResult['ODO_ALL_DAYS'] = array(); $now_day = $arResult['FIRST_DAY']; while ($now_day !== $arResult['LAST_DAY']) { if (isset($arResult['DAY_ODO'][$now_day])) { $arResult['ODO_ALL_DAYS'][$now_day] = $arResult['DAY_ODO'][$now_day]; } else { $arResult['ODO_ALL_DAYS'][$now_day] = 0; } $now_day = $dateHelper->strToTime($now_day, '+1 day', 'site'); } } //TODO: Проверить работу кода $arRes2 = Tables\OdoTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '>=DATE' => $arResult['FIRST_DAY']), 'order' => array('DATE' => 'ASC'))); $arResult['ODO_TABLE'] = array(); foreach ($arRes2 as $ar_res) { $arResult['ODO_TABLE'][$ar_res['DATE']] = array('ID' => $ar_res['ID'], 'ODO' => $ar_res['ODO']); } $arResult['UPDATED'] = $arResult['INSERTED'] = array(); foreach ($arResult['ODO_ALL_DAYS'] as $day => $odo) { if (isset($arResult['ODO_TABLE'][$day])) { if ($odo != $arResult['ODO_TABLE'][$day]['ODO']) { $query = new Query('update'); $query->setUpdateParams(array('ODO' => $odo), $arResult['ODO_TABLE'][$day]['ID'], Tables\OdoTable::getTableName(), Tables\OdoTable::getMapArray()); $res = $query->exec(); $arResult['UPDATED'][$day] = $res->getResult(); } } else { $query = new Query('insert'); $arInsert[0] = array('MY_CAR_ID' => $carID, 'DATE' => $day, 'ODO' => $odo); $query->setInsertParams($arInsert, Tables\OdoTable::getTableName(), Tables\OdoTable::getMapArray()); $res = $query->exec(); $arResult['INSERTED'][$day] = $res->getInsertId(); } } }
protected static function updateTs($tsID = null, $arUpdate = null) { try { if (is_null($tsID)) { throw new Exception\ArgumentNullException('tsID'); } if (is_null($arUpdate)) { throw new Exception\ArgumentNullException('arUpdate'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } $arCompare = Tables\TsTable::getList(array('filter' => array('ID' => $tsID))); $arCompare = $arCompare[0]; $date = new Date($arCompare['DATE'], 'db'); $arCompare['DATE'] = $date->getDate("d.m.Y"); foreach ($arUpdate as $key => $update) { if ($arCompare[$key] == $arUpdate[$key]) { unset($arUpdate[$key]); } } if (empty($arUpdate)) { return true; } else { $query = new Query('update'); $query->setUpdateParams($arUpdate, intval($tsID), Tables\TsTable::getTableName(), Tables\TsTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { return true; } else { return false; } } }
/** * Обновляет значение расхода для указанной записи * * @param int $primary * @param array $arUpdate * * @return bool */ protected static function updateExpence($primary = null, $arUpdate = null) { try { if (is_null($primary)) { throw new Exception\ArgumentNullException('primary'); } if (is_null($arUpdate)) { throw new Exception\ArgumentNullException('arUpdate'); } elseif (!is_array($arUpdate)) { throw new Exception\ArgumentTypeException('arUpdate', 'array'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } catch (Exception\ArgumentTypeException $e2) { $e2->showException(); return false; } $query = new Query('update'); $query->setUpdateParams($arUpdate, $primary, Tables\FuelTable::getTableName(), Tables\FuelTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { return true; } else { return false; } }