Exemplo n.º 1
0
 public function actionClaim()
 {
     $this->layout = 'claim';
     $model = new Trip();
     //        $this->render('claim', array('model' => $model));
     //
     //        if ($model->load(Yii::$app->request->post()) && $model->claim(Yii::$app->params['adminEmail']))
     //        {
     //            Yii::$app->session->setFlash('contactFormSubmitted');
     //
     //            return $this->refresh();
     //        }
     //        else
     //        {
     //            return $this->render('claim', array('model' => $model));
     //        }
     if (isset($_POST['Trip'])) {
         $model->attributes = $_POST['Trip'];
         $model->claim();
         Yii::app()->user->setFlash('claim', 'Thank you for contacting us. We will respond to you as soon as possible.');
         $this->refresh();
     }
     $dataProvider = new CActiveDataProvider('Trip');
     $this->render('claim', array('model' => $model, 'dataProvider' => $dataProvider));
 }
Exemplo n.º 2
0
 public function actionTrip($id)
 {
     /** @var $trip Trip */
     $trip = Trip::model()->findByPk($id);
     /** @var $user User */
     $user = User::model()->findByPk($trip->owner_id);
     $this->breadcrumbs = array(_('Користувачі') => $this->createUrl('users'), $user->getFirstName() . ' - подорожі' => $this->createUrl('trips', array('userId' => $user->id)), 'Перегляд подорожі');
     $this->render('trip', array('trip' => $trip, 'user' => $user));
 }
Exemplo n.º 3
0
 public function load($id)
 {
     $trip = Trip::model()->findByPk($id);
     if ($trip) {
         $this->_isNew = FALSE;
         $this->_initial = $trip;
         $this->setAttributes($trip->getAttributes());
     } else {
         throw new CHttpException('404');
     }
 }
Exemplo n.º 4
0
 public function testSteps()
 {
     $a = new Trip('Praha', 'Brno');
     $a->addStep(new Step(5, 2, 'turn right'));
     $this->assertEquals(1, count($a->steps));
     $this->assertEquals(5, $a->distance);
     $this->assertEquals(2, $a->duration);
     $a->addStep(new Step(60, 75, 'turn left'));
     $this->assertEquals(2, count($a->steps));
     $this->assertEquals(65, $a->distance);
     $this->assertEquals(77, $a->duration);
     // sequence orders
     $this->assertEquals(1, $a->steps[0]->sequenceOrder);
     $this->assertEquals(2, $a->steps[1]->sequenceOrder);
     // removing first step
     $a->removeStep($a->steps[0]);
     // distance and duration of the second step
     $this->assertEquals(1, count($a->steps));
     $this->assertEquals(60, $a->distance);
     $this->assertEquals(75, $a->duration);
 }
Exemplo n.º 5
0
 public static function setUpBeforeClass()
 {
     global $testTripId1, $testTripId2;
     global $testUserId1, $testUserId2;
     $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();
     $testUserId1 = "-test-user-1";
     $testUserId2 = "-test-user-2";
     $query = "DELETE FROM blogUser " . "WHERE userId='{$testUserId1}'" . "OR userId='{$testUserId2}'";
     mysql_query($query);
     $user = new User($testUserId1);
     $user->save();
     $user = new User($testUserId2);
     $user->save();
 }
Exemplo n.º 6
0
function updateTables($version)
{
    Auth::updateTables($version);
    Comment::updateTables($version);
    Feedback::updateTables($version);
    Journal::updateTables($version);
    Media::updateTables($version);
    Setting::updateTables($version);
    Trip::updateTables($version);
    TripAttribute::updateTables($version);
    TripUser::updateTables($version);
    User::updateTables($version);
    print "Tables have been updated. ";
}
Exemplo n.º 7
0
 public function testUpdateDatabase()
 {
     $version = Setting::getDataVersion();
     $this->assertTrue(Auth::updateTables($version, ''));
     $this->assertTrue(Comment::updateTables($version, ''));
     $this->assertTrue(Feedback::updateTables($version, ''));
     $this->assertTrue(Journal::updateTables($version, ''));
     $this->assertTrue(Media::updateTables($version, ''));
     $this->assertTrue(Trip::updateTables($version, ''));
     $this->assertTrue(TripAttribute::updateTables($version, ''));
     $this->assertTrue(TripUser::updateTables($version, ''));
     $this->assertTrue(User::updateTables($version, ''));
     // Note: make sure the Settings::updateTables is last: when any of the
     // above fail, the data version in the database should NOT be updated!
     $this->assertTrue(Setting::updateTables($version, ''));
 }
Exemplo n.º 8
0
    $address = $result->address_components[0]->long_name . " " . $result->address_components[1]->long_name . ", " . $result->address_components[2]->long_name . ", " . $result->address_components[3]->short_name . " " . $result->address_components[5]->short_name;
    $rating = $result->rating;
    if (!$rating) {
        $rating = 2.5;
    }
    $coordinate = ["latitude" => $result->geometry->location->lat, "longitude" => $result->geometry->location->lng];
    $coordinates[$i] = $coordinate;
    $daily_hours = [];
    for ($j = 0; $j < 7; $j++) {
        $daily_hours[$j] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    }
    $hours_results = $result->opening_hours;
    foreach ($hours_results->periods as $period) {
        $open = (int) round($period->open->time / 100);
        $close = (int) round($period->close->time / 100);
        $difference = abs($close - $open);
        for ($k = $period->close->day; $k < $period->close->day + $difference; $k++) {
            $daily_hours[$period->close->day][$k] = 1;
        }
    }
    foreach ($daily_hours as $one_daily_hour_key => $one_daily_hour_value) {
        $temp_daily_hour = $daily_hours[$one_daily_hour_key];
        $daily_hours[$one_daily_hour_key] = new DailyHours($one_daily_hour_value);
    }
    $place = new Place($name, $daily_hours, [new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 37, 24, 3, 28, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 28, 35, 42, 56, 78, 76, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 81, 83, 74, 63, 42, 28, 14, 17, 21, 31, 12, 15, 19, 23, 20, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 37, 24, 3, 28, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 28, 35, 42, 56, 78, 76, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 81, 83, 74, 63, 42, 28, 14, 17, 21, 31, 12, 15, 19, 23, 20, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 81, 83, 74, 63, 42, 28, 14, 17, 21, 31, 12, 15, 19, 23, 20, 0, 0, 0])], $rating);
    $places[$i] = $place;
}
$trip = new Trip(5, 9);
echo json_encode($trip->order($places, $coordinates));
// echo json_encode($places);
// echo json_encode($coordinates);
Exemplo n.º 9
0
 /**
  * Test #15.
  * The findByHash function returns null for an non-existing hash.
  * @depends testSetAttributes
  */
 public function getHashGetNull()
 {
     global $testTripId1, $testMediaId1;
     // create a random object and save it
     $object = new Media($testTripId1, $testMediaId1);
     $object->setType('photo');
     $object->setCaption('Caption 1');
     $object->setTimestamp('2015-09-30 12:03:45');
     $object->setLocation('location');
     $object->setWidth('900');
     $object->setHeight('600');
     $object->setDeleted('N');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $object = Trip::findByHash('non-existent hash');
     $this->assertNull($object);
     $this->assertEquals(1, $this->countTestRows());
 }
Exemplo n.º 10
0
 /**
  * Test #15.
  * The findByHash function returns null for an non-existing hash.
  * @depends testSetAttributes
  */
 public function getHashGetNull()
 {
     global $testTripId1, $testUserId1, $testUserId1;
     // create a random object and save it
     $object = new TripUser($testTripId1, $testUserId1);
     $object->setRole('role-1');
     $object->setMessage('message');
     $object->setDeleted('N');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $object = Trip::findByHash('non-existent hash');
     $this->assertNull($object);
     $this->assertEquals(1, $this->countTestRows());
 }
Exemplo n.º 11
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($trip)
 {
     $flights = Trip::find($trip->id)->flights()->get();
     $array = array("trip" => $trip, "associated flights" => array("content" => $flights));
     return $array;
 }
Exemplo n.º 12
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']);
 }
Exemplo n.º 13
0
    public $data;
    function __construct()
    {
        parent::__construct();
    }
    public function get_trip()
    {
        //$get_data = $_POST;
        $post_data = file_get_contents("php://input");
        $get_data = json_decode($post_data, true);
        $sql = "SELECT * FROM ft_trip WHERE spotview_id = :spotview_id AND type = :type";
        $stmt = $this->db->prepare($sql);
        $stmt->execute(array(':spotview_id' => $get_data['spotview_id'], ':type' => $get_data['type']));
        $stmt->setFetchMode(PDO::FETCH_ASSOC);
        $res = $stmt->fetchAll();
        if ($res) {
            $this->res['code'] = 0;
            $this->res['message'] = 'success';
            $this->res['trip'] = $res;
        } else {
            $this->res['code'] = 1;
            $this->res['message'] = 'fail! No trip';
        }
    }
    function __destruct()
    {
        $this->die_json($this->res);
    }
}
$trip = new Trip();
$trip->get_trip();
Exemplo n.º 14
0
 /**
  * return an array of trip entities that the member created
  *
  * @access public
  * @return array
  */
 public function getTripsArray()
 {
     if (!$this->_has_loaded) {
         return false;
     }
     $tripmodel = new Trip();
     $usertrips = $tripmodel->getTrips($this->Username);
     $trip_data = $tripmodel->getTripData();
     return array($usertrips, $trip_data);
 }
Exemplo n.º 15
0
<?php

session_start();
$user = new User();
$participant = new User();
if ($user->selectByEmail(Database::sessionDecrypt($_SESSION['user'])) && $participant->selectByEmail($_POST['participant'])) {
    $trip = new Trip();
    if ($trip->selectById($_POST['tripId'])) {
        if ($trip->removeParticipant($participant->getUserId())) {
            echo ReturnCode::$success;
        } else {
            echo ReturnCode::$error;
        }
    } else {
        echo ReturnCode::$tripNotFound;
    }
} else {
    echo ReturnCode::$userNotFound;
}
Exemplo n.º 16
0
} else {
    $tripId = '';
    if (isset($_GET['current'])) {
        $tripId = Trip::findCurrentTrip();
        if (!$tripId) {
            $tripId = '';
        }
    } else {
        if (isset($_GET['tripId'])) {
            $tripId = $_GET['tripId'];
        }
    }
    if ($tripId === '') {
        $response = errorResponse(RESPONSE_BAD_REQUEST);
    } else {
        $object = new Trip($tripId);
        if ($object->getCreated() === null) {
            $response = errorResponse(RESPONSE_NOT_FOUND);
        } else {
            $response = successResponse();
            $response['tripId'] = $object->getTripId();
            $response['created'] = $object->getCreated();
            $response['updated'] = $object->getUpdated();
            $response['name'] = $object->getName();
            $response['description'] = $object->getDescription();
            $response['bannerImg'] = $object->getBannerImg();
            $response['startDate'] = $object->getStartDate();
            $response['endDate'] = $object->getEndDate();
            $response['active'] = $object->getActive();
            $response['deleted'] = $object->getDeleted();
            // Do NOT return the hash field on the GET service.
Exemplo n.º 17
0
    foreach ($hours_results->periods as $period) {
        $open = (int) round($period->open->time / 100);
        $close = (int) round($period->close->time / 100);
        $difference = abs($close - $open);
        for ($k = $period->close->day; $k < $period->close->day + $difference; $k++) {
            $daily_hours[$period->close->day][$k] = 1;
        }
    }
    foreach ($daily_hours as $one_daily_hour_key => $one_daily_hour_value) {
        $temp_daily_hour = $daily_hours[$one_daily_hour_key];
        $daily_hours[$one_daily_hour_key] = new DailyHours($one_daily_hour_value);
    }
    $place = new Place($name, $daily_hours, [new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 37, 24, 3, 28, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 28, 35, 42, 56, 78, 76, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 81, 83, 74, 63, 42, 28, 14, 17, 21, 31, 12, 15, 19, 23, 20, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 37, 24, 3, 28, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 0, 0, 28, 35, 42, 56, 78, 76, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 81, 83, 74, 63, 42, 28, 14, 17, 21, 31, 12, 15, 19, 23, 20, 0, 0, 0]), new DailyHours([0, 0, 0, 0, 0, 0, 81, 83, 74, 63, 42, 28, 14, 17, 21, 31, 12, 15, 19, 23, 20, 0, 0, 0])], $rating);
    $places[$i] = $place;
}
$trip = new Trip(5, 9);
$final_scores = $trip->order($places, $coordinates);
//	echo json_encode($final_scores);
$google_maps = "https://www.google.com/maps/dir/39.9009656,-75.171894";
foreach ($coordinates as $coordinate) {
    $google_maps .= "/{$coordinate['latitude']},{$coordinate['longitude']}";
}
// uber
$uber = 0;
// Get cURL resource
$ch = curl_init();
// Set url
curl_setopt($ch, CURLOPT_URL, 'https://api.uber.com/v1/estimates/time?start_latitude=39.905&start_longitude=-75.172');
// Set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
// Set options
Exemplo n.º 18
0
$outbound_stops = Stop::CreateStopsFromList($outbound_stop_ids);
$routes = array(new Route(12), new Route(29));
$inbound_trips = Trip::GetTrips($routes, $inbound_stops, '0', $limit, $time);
$inbound_times = Trip::GetStopTimesForTrips($inbound_trips, $inbound_stops);
uasort($inbound_times, 'TripTimeComparer');
// TODO: when we are displaying a day's last trip + some morning trips, we want to treat the 24:48:00 differently than we
// treat a day's list with the last trip wrapping over. Currently the last trip(s) are sorting to the end, which is highly
// undesired. We do however need the sort for merging the two routes' schedules during weekdays.
// Some thoughts: 1) other than the route merge, sorting seems to be handled by the database. This may however be implicit
// by trip_id, which is not the safest. See if we can sort in SQL. (Still a problem since evening+morning come from two separate
// SQL queries, but we can just sort inside GetTrips in that case.) 2) if not, incorporate some sort of day/timestamp identity
// to each stoptime returned. This is somewhat absurd, as we'd probably need full timestamp to avoid problems wrapping
// over ends of service periods, months, years, etc.
// Currently leaving unsolved -- ~qviri, 2009.02.22
$outbound_trips = Trip::GetTrips($routes, $outbound_stops, '1', $limit, $time);
$outbound_times = Trip::GetStopTimesForTrips($outbound_trips, $outbound_stops);
uasort($outbound_times, 'TripTimeComparer');
$schedule = Page::GetRequestedServicePeriod($time);
echo '<p style="margin-bottom: -1.5em;">viewing ';
if (Page::IsShowingFullSchedule() === false) {
    echo $schedule->name . ' schedule upcoming trips';
    echo ' &#183; view full schedule: ';
    // TODO: there is a GetAllServicePeriods() but it also includes 'All week' and foreach leaves dangling commas... meh
    echo ' <a href="?serviceperiod=2">weekday</a>, ';
    echo ' <a href="?serviceperiod=3">Saturday</a>, ';
    echo ' <a href="?serviceperiod=4">Sunday</a>';
} else {
    echo 'full ' . $schedule->name . ' schedule';
    echo ' &#183; <a href="/keats/">view upcoming trips</a>';
}
echo '</p>' . "\n\n";
Exemplo n.º 19
0
<?php

require_once "lib/Trip.class.php";
require_once "lib/vcomp.datetime.class.php";
$trip_date = new VCOMP_DateTime("trip_date");
$newTrip = new Trip();
$newTrip->setTripDate($trip_date->getTimestamp());
$newTrip->setDuration($_POST["hours"] * 3600 + $_POST["minutes"] * 60 + $_POST["seconds"]);
$newTrip->setDistance($_POST["distance"]);
$newTrip->setAvgSpeed($_POST["avg_speed"]);
$newTrip->setMaxSpeed($_POST["max_speed"]);
$newTrip->setOdometer($_POST["odometer"]);
$newTrip->setCalories($_POST["calories"]);
Exemplo n.º 20
0
 /**
  * Processing edit of a blog.
  *
  * This is a POST callback function.
  *
  * Sets following errors in POST vars:
  * title        - invalid(empty) title.
  * startdate    - wrongly formatted start date.
  * enddate      - wrongly formatted end date.
  * duration     - empty enddate and invalid duration.
  * category     - category is not belonging to user.
  * trip         - trip is not belonging to user.
  * upderror     - error performing db update.
  * tagerror     - error while updating tags.
  */
 public function editProcess($args, $action, $mem_redirect, $mem_resend)
 {
     if (!($member = $this->_model->getLoggedInMember())) {
         return false;
     }
     $userId = $member->id;
     $vars = $args->post;
     if (!isset($vars['id']) || !$this->_model->isUserPost($userId, $vars['id'])) {
         return false;
     }
     if (isset($vars['txt'])) {
         $vars['txt'] = $this->_cleanupText($vars['txt']);
     }
     if (!$this->_validateVars($vars)) {
         return false;
     }
     $post = $this->_model->getPost($vars['id']);
     if (!$post) {
         return false;
     }
     $flags = $post->flags;
     // cannot write sticky blogs currently
     $flags = $flags & ~(int) Blog::FLAG_STICKY;
     if (!isset($vars['vis'])) {
         $vars['vis'] = 'pri';
     }
     switch ($vars['vis']) {
         case 'pub':
             $flags = $flags & ~(int) Blog::FLAG_VIEW_PROTECTED & ~(int) Blog::FLAG_VIEW_PRIVATE;
             break;
         case 'prt':
             $flags = $flags & ~(int) Blog::FLAG_VIEW_PRIVATE | (int) Blog::FLAG_VIEW_PROTECTED;
             break;
         default:
             $flags = $flags & ~(int) Blog::FLAG_VIEW_PROTECTED | (int) Blog::FLAG_VIEW_PRIVATE;
             break;
     }
     $tripId = isset($vars['tr']) && strcmp($vars['tr'], '') != 0 ? (int) $vars['tr'] : false;
     $this->_model->updatePost($post->blog_id, $flags, $tripId);
     // 'Touch' the corresponding trip!
     if ($tripId) {
         $TripModel = new Trip();
         $TripModel->touchTrip($tripId);
     }
     /*// to sql datetime format.
       if ((isset($vars['sty']) && (int)$vars['sty'] != 0) || (isset($vars['stm']) && (int)$vars['stm'] != 0) || (isset($vars['std']) && (int)$vars['std'] != 0)) {
           $start = mktime(0, 0, 0, (int)$vars['stm'], (int)$vars['std'], (int)$vars['sty']);
           $start = date('YmdHis', $start);
       } else {
           $start = false;
       } */
     // to sql datetime format.
     if (isset($vars['date']) && (strlen($vars['date']) <= 10 && strlen($vars['date']) > 8)) {
         list($day, $month, $year) = preg_split('/[\\/.-]/', $vars['date']);
         if (substr($month, 0, 1) == '0') {
             $month = substr($month, 1, 2);
         }
         if (substr($day, 0, 1) == '0') {
             $day = substr($day, 1, 2);
         }
         $start = mktime(0, 0, 0, (int) $month, (int) $day, (int) $year);
         $start = date('YmdHis', $start);
     } else {
         $start = false;
     }
     // Check if the location already exists in our DB and add it if necessary
     if ($vars['geonameid'] && $vars['latitude'] && $vars['longitude'] && $vars['geonamename'] && $vars['geonamecountrycode'] && $vars['admincode']) {
         $geoname_ok = $this->_model->checkGeonamesCache($vars['geonameid']);
     } else {
         $geoname_ok = false;
     }
     $geonameId = $geoname_ok ? $vars['geonameid'] : false;
     $this->_model->updatePostData($post->blog_id, $vars['t'], $vars['txt'], $start, $geonameId);
     if (!$this->_model->updateTags($post->blog_id, explode(',', $vars['tags']))) {
         $vars['errors'] = array('tagerror');
         return false;
     }
     $this->_model->updateBlogToCategory($post->blog_id, $vars['cat']);
     PPostHandler::clearVars();
     return 'blog/edit/' . $post->blog_id . '/finish';
 }
Exemplo n.º 21
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Trip::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 22
0
                 $response['startDate'] = $trip->getStartDate();
                 $response['endDate'] = $trip->getEndDate();
                 $response['active'] = $trip->getActive();
                 $response['deleted'] = $trip->getDeleted();
                 $response['hash'] = $trip->getHash();
             }
         }
     } else {
         $response = errorResponse(RESPONSE_BAD_REQUEST, 'Missing hash');
     }
 } else {
     if (isPutMethod()) {
         $data = getPostData();
         if (isset($data['tripId']) && $data['tripId'] !== '') {
             $tripId = $data['tripId'];
             $trip = new Trip($tripId);
             if (isset($data['created'])) {
                 $trip->setCreated($data['created']);
             }
             if (isset($data['updated'])) {
                 $trip->setUpdated($data['updated']);
             }
             if (isset($data['name'])) {
                 $trip->setName($data['name']);
             }
             if (isset($data['description'])) {
                 $trip->setDescription($data['description']);
             }
             if (isset($data['bannerImg'])) {
                 $trip->setBannerImg($data['bannerImg']);
             }
Exemplo n.º 23
0
 /**
  * 切换日游媒体状态
  * @return bool
  */
 public function ActionAjaxChangeTripMediaValid()
 {
     $trip_id = $_POST['trip_media_id'];
     // 获取要修改的日游媒体ID
     $valid = $_POST['valid'];
     // 获取该日游媒体当前的状态 [0:禁用 / 1:启用]
     $valid = $valid == 0 ? 1 : 0;
     $trip_media_model = TripMedia::model();
     $trip_media_info = $trip_media_model->findByPk($trip_id);
     // 查询更改的日游媒体信息
     // 执行更新
     if ($trip_media_info->updateByPk($trip_id, array('Valid' => $valid)) > 0) {
         // 获取所有日游
         $trip = IconvEncode::ObjArrChangeArray(Trip::model()->findAll(), 'TripName');
         // 添加操作日志 [S]
         $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' ' . ($valid == 0 ? '禁用了' : '启用了') . ' 【' . $trip[$trip_media_info['TripId']] . '】 的媒体文件';
         OperationLogManage::AddOperationLog($log);
         // 添加日志
         // 添加操作日志 [E]
         echo true;
     } else {
         echo false;
     }
 }
                         }
                         $all_trips_of_sid = Trip::getTripsBySid($dir, $sid, $date1, $date2);
                         if ($all_trips_of_sid == null) {
                             //trip from/to station with id 'sid' not found
                             header("HTTP/1.1 404 Not Found");
                             print "Trip data for station " . $sid . " from date: " . $date1 . " to date :" . $date2 . " are null";
                             exit;
                         }
                         header("Content-type: application/json");
                         print json_encode($all_trips_of_sid);
                         exit;
                     } else {
                         //url:	~/trip/date1/date2
                         $date1 = $path_components[2];
                         $date2 = $path_components[3];
                         $all_trips_within_range = Trip::getTripsByDateRange($date1, $date2);
                         if ($all_trips_within_range == null) {
                             // trip from date 1 to date 2 not found
                             header("HTTP/1.1 404 Not Found");
                             print "Trip data from date: " . $date1 . " to date :" . $date2 . " are null.";
                             exit;
                         }
                         header("Content-type: application/json");
                         print json_encode($all_trips_within_range);
                         exit;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 25
0
 /**
  * Test #15.
  * The findByHash function returns null for an non-existing hash.
  * @depends testSetAttributes
  */
 public function getHashGetNull()
 {
     global $testUserId1;
     // create a random object and save it
     $object = new User($testUserId1);
     $object->setName('Test User');
     $object->setExternalType('externaltype');
     $object->setExternalId('externalid');
     $object->setAccess('access');
     $object->setEmail('*****@*****.**');
     $object->setNotification('Y');
     $object->setTempCode('tempcode');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $object = Trip::findByHash('non-existent hash');
     $this->assertNull($object);
     $this->assertEquals(1, $this->countTestRows());
 }
Exemplo n.º 26
0
 /**
  * 切换线路状态
  * @return bool
  */
 public function ActionAjaxChangeTripValid()
 {
     $id = $_POST['id'];
     // 获取要修改的线路ID
     $valid = $_POST['valid'];
     // 获取该线路当前的状态 [0:禁用 / 1:启用]
     $valid = $valid == 0 ? 1 : 0;
     $trip_model = Trip::model();
     $trip_info = $trip_model->findByPk($id);
     // 查询更改的线路信息
     // 执行更新
     if ($trip_info->updateByPk($id, array('Valid' => $valid)) > 0) {
         // 添加操作日志 [S]
         $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' ' . ($valid == 0 ? '禁用了' : '启用了') . ' 【' . $trip_info['TripName'] . '】 线路';
         OperationLogManage::AddOperationLog($log);
         // 添加日志
         // 添加操作日志 [E]
         echo true;
     } else {
         echo false;
     }
 }
Exemplo n.º 27
0
 /**
  * @param Trip|NULl
  * @return Step Fluent interface	 
  */
 public function setTrip(Trip $trip = NULL)
 {
     if ($this->trip != NULL) {
         $this->trip->removeStep($this);
     }
     if ($trip != NULL) {
         $trip->addStep($this);
     }
     $this->trip = $trip;
     return $this;
     // fluent interface
 }
Exemplo n.º 28
0
 /**
  * Create an instance by the hash value. This function is in support
  * of the synchronization functionality. It takes a hash value and
  * it will return an instance of the object for that hash value
  * if the hash exists. If the hash does not exist, null will be
  * returned, indicating that the object should be created using the
  * normal constructor.
  */
 public static function findByHash($hash = '')
 {
     if (!isset($hash) || $hash === '') {
         return null;
     }
     $hashValue = db_sql_encode($hash);
     $query = "SELECT * FROM blogTrip " . "WHERE hash={$hashValue} " . "ORDER BY updated DESC " . "LIMIT 1";
     $result = mysql_query($query);
     if (!$result) {
         // Error executing the query
         print $query . "<br/>";
         print " --> error: " . mysql_error() . "<br/>\n";
         return null;
     }
     if (mysql_num_rows($result) <= 0) {
         // Object does not exist
         return null;
     }
     // Create an instance with a special ID '-' to bypass the
     // checks on empty ID. The ID value will be overwritten by the
     // value coming back from the database anyway.
     $object = new Trip('-');
     if ($object->loadFromResult($result)) {
         return $object;
     }
     return null;
 }
Exemplo n.º 29
0
 protected function _updateRelatedModels()
 {
     if ($this->_initialAttributes['first_name'] != $this->first_name) {
         Trip::model()->updateAll(array('owner_name' => $this->first_name), 'owner_id = :userId', array(':userId' => $this->id));
     }
     if ($this->_initialAttributes['birthday'] != $this->birthday) {
         Trip::model()->updateAll(array('owner_age' => $this->getAge()), 'owner_id = :userId', array(':userId' => $this->id));
     }
 }
Exemplo n.º 30
0
include_once dirname(__FILE__) . '/../business/AuthB.php';
include_once dirname(__FILE__) . '/../database/Trip.php';
$auth = new AuthB();
if (!$auth->canPutTrip()) {
    $response = errorResponse(RESPONSE_UNAUTHORIZED);
} else {
    if (isPutMethod()) {
        $data = getPostData();
        $tripId = '';
        if (isset($data['tripId'])) {
            $tripId = $data['tripId'];
        }
        if ($tripId === '') {
            $response = errorResponse(RESPONSE_BAD_REQUEST);
        } else {
            $object = new Trip($tripId);
            if (isset($data['name'])) {
                $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']);
            }