Example #1
0
 /**
  * 添加线路
  */
 public function ActionAddTrip()
 {
     $trip_model = new Trip();
     if (isset($_POST['Trip'])) {
         // 填充模型
         $trip_model->attributes = $_POST['Trip'];
         // 拼接有效期时间 [起始时间/结束时间]
         $trip_model['TripDate'] = $_POST['Trip']['StartTime'] . '/' . $_POST['Trip']['EndTime'];
         // 拼接有效期时间 [起始时间/结束时间]
         // 执行添加
         if ($trip_model->save()) {
             // 添加操作日志 [S]
             $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' 添加了一个名为 【' . $_POST['Trip']['TripName'] . '】 的线路';
             OperationLogManage::AddOperationLog($log);
             // 添加日志
             // 添加操作日志 [E]
             Yii::app()->user->setFlash('save_sign', '添加成功');
             Yii::app()->user->setFlash('trip_id', $trip_model->attributes['Id']);
             $this->redirect(Yii::app()->createUrl('Trip/AddTrip'));
         } else {
             Yii::app()->user->setFlash('save_sign', '添加失败');
             $this->renderPartial('add_Trip', array('trip_model' => $trip_model));
         }
     } else {
         // 获取供应商列表
         $supplier = array(1 => '供应商 - A', 2 => '供应商 - B', 3 => '供应商 - C', 4 => '供应商 - D', 5 => '供应商 - E');
         // 跳转至添加页
         $this->render('add_trip', array('trip_model' => $trip_model, 'supplier' => $supplier));
     }
 }
Example #2
0
 public function save()
 {
     if ($this->_isNew) {
         $model = new Trip();
         $model->setAttributes($this->getAttributes());
         $model->save();
     } else {
         $this->_initial->setAttributes($this->getAttributes());
         $this->_initial->save();
     }
 }
 public static function setUpBeforeClass()
 {
     global $testTripId1, $testTripId2;
     $testTripId1 = '-test-trip-1';
     $testTripId2 = '-test-trip-2';
     $query = "DELETE FROM blogTrip " . "WHERE tripId='{$testTripId1}'" . "OR tripId='{$testTripId2}'";
     mysql_query($query);
     $trip = new Trip($testTripId1);
     $trip->save();
     $trip = new Trip($testTripId2);
     $trip->save();
 }
Example #4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Trip();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Trip'])) {
         $model->attributes = $_POST['Trip'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #5
0
 /**
  * Extra text. Make sure the get operation works with a "latest"
  * value.
  */
 function testGetLatest()
 {
     global $testTripId1, $testTripId2;
     // use the timezone where we do our testing :-)
     date_default_timezone_set("America/New_York");
     $now = time();
     $today = date('Y-m-d', $now);
     $yesterday = date('Y-m-d', $now - 24 * 60 * 60);
     $tomorrow = date('Y-m-d', $now + 24 * 60 * 60);
     $past = date('Y-m-d', $now - 5 * (24 * 60 * 60));
     $future = date('Y-m-d', $now + 5 * (24 * 60 * 60));
     $farPast = date('Y-m-d', $now - 10 * (24 * 60 * 60));
     $farFuture = date('Y-m-d', $now + 10 * (24 * 60 * 60));
     $testTrip1 = new Trip($testTripId1);
     $testTrip2 = new Trip($testTripId2);
     $data = array('current' => '');
     // one past and one future trip
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($yesterday);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($tomorrow);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $result = getApi('getTrip.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertEquals($testTripId1, $result['tripId']);
     // one past and one current trip
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($yesterday);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($yesterday);
     $testTrip2->setEndDate($tomorrow);
     $this->assertTrue($testTrip2->save());
     $result = getApi('getTrip.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertEquals($testTripId2, $result['tripId']);
     // two past trips
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($yesterday);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($farPast);
     $testTrip2->setEndDate($past);
     $this->assertTrue($testTrip2->save());
     $result = getApi('getTrip.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertEquals($testTripId1, $result['tripId']);
     // one current and one future trip
     $testTrip1->setStartDate($yesterday);
     $testTrip1->setEndDate($tomorrow);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($tomorrow);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $result = getApi('getTrip.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertEquals($testTripId1, $result['tripId']);
     // two current trips, nested
     $testTrip1->setStartDate($yesterday);
     $testTrip1->setEndDate($tomorrow);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($past);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $result = getApi('getTrip.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertEquals($testTripId1, $result['tripId']);
     // two current trips, staggered
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($tomorrow);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($yesterday);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $result = getApi('getTrip.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertTrue(isset($result['tripId']));
     $this->assertEquals($testTripId2, $result['tripId']);
 }
Example #6
0
                $object->setName($data['name']);
            }
            if (isset($data['description'])) {
                $object->setDescription($data['description']);
            }
            if (isset($data['bannerImg'])) {
                $object->setBannerImg($data['bannerImg']);
            }
            if (isset($data['startDate'])) {
                $object->setStartDate($data['startDate']);
            }
            if (isset($data['endDate'])) {
                $object->setEndDate($data['endDate']);
            }
            if (isset($data['active'])) {
                $object->setActive($data['active']);
            }
            if (isset($data['deleted'])) {
                $object->setDeleted($data['deleted']);
            }
            if ($object->save()) {
                $response = successResponse();
            } else {
                $response = errorResponse(RESPONSE_INTERNAL_ERROR);
            }
        }
    } else {
        $response = errorResponse(RESPONSE_BAD_REQUEST);
    }
}
echo json_encode($response);
Example #7
0
                    $trip->setBannerImg($data['bannerImg']);
                }
                if (isset($data['startDate'])) {
                    $trip->setStartDate($data['startDate']);
                }
                if (isset($data['endDate'])) {
                    $trip->setEndDate($data['endDate']);
                }
                if (isset($data['active'])) {
                    $trip->setActive($data['active']);
                }
                if (isset($data['deleted'])) {
                    $trip->setDeleted($data['deleted']);
                }
                if (isset($data['hash'])) {
                    $trip->setHash($data['hash']);
                }
                if ($trip->save()) {
                    $response = successResponse();
                } else {
                    $response = errorResponse(RESPONSE_INTERNAL_ERROR);
                }
            } else {
                $response = errorResponse(RESPONSE_BAD_REQUEST, 'Missing tripId');
            }
        } else {
            $response = errorResponse(RESPONSE_BAD_REQUEST, 'Not GET or PUT');
        }
    }
}
echo json_encode($response);
Example #8
0
 /**
  * Метод создания пользователя, путешествия, покупки
  * возвращает массив JSON с ошибками
  */
 public function actionaddPurchase()
 {
     if (empty(Yii::app()->request->csrfToken)) {
         throw new CHttpException('403', 'Ошибочный запрос, отказано в доступе.');
     }
     $params = CJSON::decode(file_get_contents('php://input'), true);
     $errors = array();
     $user = new Users();
     $user->username = $params['data']['userfullname'];
     $user->password = $params['data']['password'];
     $user->email = $params['data']['email'];
     $user->first_name = strpos($params['data']['userfullname'], ' ') === false ? $params['data']['userfullname'] : substr($params['data']['userfullname'], 0, strpos($params['data']['userfullname'], ' '));
     $user->last_name = strpos($params['data']['userfullname'], ' ') === false ? $params['data']['userfullname'] : substr($params['data']['userfullname'], strpos($params['data']['userfullname'], ' '));
     if ($user->validate()) {
         if (!$user->save()) {
             throw new CHttpException('403', 'Ошибочный запрос, не удалось обновить user');
         }
     } else {
         throw new CHttpException('403', 'Ошибочный запрос, не удалось обновить user');
     }
     $trip = new Trip();
     $trip->users__id = $user->id;
     $trip->departure = $params['data']['departure'];
     $trip->destination = $params['data']['destination'];
     $trip->date_start = date("Y-m-d", strtotime($params['data']['date_start']));
     $trip->date_end = date("Y-m-d", strtotime($params['data']['date_end']));
     if ($trip->validate()) {
         if (!$trip->save()) {
             throw new CHttpException('403', 'Ошибочный запрос, не удалось обновить trip');
         }
     } else {
         throw new CHttpException('403', 'Ошибочный запрос, не удалось обновить trip');
     }
     $purchase = new Purchases();
     $purchase->users__id = $user->id;
     $purchase->trip__id = $trip->id;
     $purchase->name = $params['data']['name'];
     $purchase->price = $params['data']['price'];
     if ($purchase->validate()) {
         if (!$purchase->save()) {
             throw new CHttpException('403', 'Ошибочный запрос, не удалось обновить purchase');
         }
     } else {
         throw new CHttpException('403', 'Ошибочный запрос, не удалось обновить purchase validate');
     }
     $errors['customer'] = array_merge($user->getErrors(), $trip->getErrors());
     echo CJSON::encode($errors);
 }
Example #9
0
 /**
  * Extra test. Make sure the get operation works with a "latest"
  * value.
  */
 function testGetLatest()
 {
     global $testTripId1, $testTripId2;
     // use the timezone where we do our testing :-)
     date_default_timezone_set("America/New_York");
     $now = time();
     $today = date('Y-m-d', $now);
     $yesterday = date('Y-m-d', $now - 24 * 60 * 60);
     $tomorrow = date('Y-m-d', $now + 24 * 60 * 60);
     $past = date('Y-m-d', $now - 5 * (24 * 60 * 60));
     $future = date('Y-m-d', $now + 5 * (24 * 60 * 60));
     $farPast = date('Y-m-d', $now - 10 * (24 * 60 * 60));
     $farFuture = date('Y-m-d', $now + 10 * (24 * 60 * 60));
     $testTrip1 = new Trip($testTripId1);
     $testTrip2 = new Trip($testTripId2);
     // one past and one future trip
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($yesterday);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($tomorrow);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $tripId = Trip::findCurrentTrip();
     $this->assertEquals($testTripId1, $tripId);
     // one past and one current trip
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($yesterday);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($yesterday);
     $testTrip2->setEndDate($tomorrow);
     $this->assertTrue($testTrip2->save());
     $tripId = Trip::findCurrentTrip();
     $this->assertEquals($testTripId2, $tripId);
     // two past trips
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($yesterday);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($farPast);
     $testTrip2->setEndDate($past);
     $this->assertTrue($testTrip2->save());
     $tripId = Trip::findCurrentTrip();
     $this->assertEquals($testTripId1, $tripId);
     // one current and one future trip
     $testTrip1->setStartDate($yesterday);
     $testTrip1->setEndDate($tomorrow);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($tomorrow);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $tripId = Trip::findCurrentTrip();
     $this->assertEquals($testTripId1, $tripId);
     // two current trips, nested
     $testTrip1->setStartDate($yesterday);
     $testTrip1->setEndDate($tomorrow);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($past);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $tripId = Trip::findCurrentTrip();
     $this->assertEquals($testTripId1, $tripId);
     // two current trips, staggered
     $testTrip1->setStartDate($past);
     $testTrip1->setEndDate($tomorrow);
     $this->assertTrue($testTrip1->save());
     $testTrip2->setStartDate($yesterday);
     $testTrip2->setEndDate($future);
     $this->assertTrue($testTrip2->save());
     $tripId = Trip::findCurrentTrip();
     $this->assertEquals($testTripId2, $tripId);
 }
Example #10
0
<?php

extract($_POST);
$tripArray = array('origin' => $origin, 'destination' => $destination, 'travelers' => $travelers, 'hours_per_day' => $hoursPerDay, 'efficiency' => $vehicleEfficiency, 'use_toll_roads' => $useTollRoads, 'meal_grade' => $mealGrade, 'hotel_grade' => $hotelGrade, 'created_by' => 1, 'created' => mktime());
$trip = new Trip($tripArray);
$trip->save();
$costPerMeal = $mealGrade * BASE_MEAL * $travelers;
$mealCostPerDay = $costPerMeal * 3;
$numRooms = $travelers / 4 < 1 ? 1 : ceil($travelers / 4);
$costPerRoom = $hotelGrade * BASE_HOTEL;
$roomCostPerDay = $numRooms * $costPerRoom;
switch ($mealGrade) {
    case 1:
        $mealGradeText = 'Roach Coach';
        break;
    case 2:
        $mealGradeText = 'Budget';
        break;
    case 3:
        $mealGradeText = 'Upscale';
        break;
    default:
        $mealGradeText = 'Not Selected';
        break;
}
switch ($hotelGrade) {
    case 1:
        $hotelGradeText = 'Sleep in Shifts';
        break;
    case 2:
        $hotelGradeText = 'Budget';
Example #11
0
File: Trip.php Project: YSeanKo/MCS
 public function claim()
 {
     if ($this->validate()) {
         $form = new Trip();
         $form->departDate = $this->departDate;
         $form->arrivalDate = $this->arrivalDate;
         $form->departTime = $this->departTime;
         $form->arrivalTime = $this->arrivalTime;
         $form->departLocation = $this->departLocation;
         $form->departCity = $this->departCity;
         $form->departCityLat = $this->departCityLat;
         $form->departCityLng = $this->departCityLng;
         $form->arrivalLocation = $this->arrivalLocation;
         $form->destinationCity = $this->destinationCity;
         $form->destinationCityLat = $this->destinationCityLat;
         $form->destinationCityLng = $this->destinationCityLng;
         $form->dutyType = $this->dutyType;
         $form->vehicle = $this->vehicle;
         $form->distance = $this->distance;
         $form->save();
         return true;
     } else {
         return false;
     }
 }