本文整理汇总了PHP中State::first方法的典型用法代码示例。如果您正苦于以下问题:PHP State::first方法的具体用法?PHP State::first怎么用?PHP State::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State::first方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: packages
public function packages()
{
$view = $this->getActionView();
$states = State::all();
$view->set('states', $states);
$source = RequestMethods::get('source');
$source_state = State::first(array('id = ?' => $source));
$dest = RequestMethods::get('dest');
$dest_state = State::first(array('id = ?' => $dest));
$month = RequestMethods::get('month');
$year = RequestMethods::get('year');
$page = RequestMethods::get('page', 1);
$limit = 9;
if (RequestMethods::get('source')) {
$count = Package::count(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year));
$total_pages = $count / 9 + 1;
for ($i = 1; $i <= $total_pages; $i++) {
$pages[$i] = $i;
}
$packages = Package::all(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year, 'live = ?' => 1), array("*"), null, null, $limit, $page);
$view->set('n', 'http://planyourtours.io/travels/packages?source=' . $source . '&dest=' . $dest . '&type=Group&month=' . $month . '&year=' . $year . '&page=')->set('source', $source_state)->set('dest', $dest_state)->set('month', $month)->set('year', $year);
} else {
$count = Package::count();
$total_pages = $count / 9 + 1;
for ($i = 1; $i <= $total_pages; $i++) {
$pages[$i] = $i;
}
$packages = Package::all(array('live = ?' => 1), array("*"), null, null, $limit, $page);
$view->set('n', 'http://planyourtours.io/travels/packages?&page=');
}
if (!empty($packages)) {
$view->set('packages', $packages)->set('pages', $pages);
}
}
示例2: search
public function search()
{
$view = $this->getActionView();
$states = State::all();
$view->set('states', $states);
$source = RequestMethods::get('source');
$source_state = State::first(array('id = ?' => $source));
$dest = RequestMethods::get('dest');
$dest_state = State::first(array('id = ?' => $dest));
$people = RequestMethods::get('people');
$start = RequestMethods::get('start');
$end = RequestMethods::get('end');
$drivers = CabDriver::all(array('state = ?' => RequestMethods::get('source')));
$startdate = strtotime($start);
$enddate = strtotime($end);
$today = strtotime(date('Y-m-d'));
$i = 0;
foreach ($drivers as $driver) {
$bookings = CabBooking::all(array('driver_id = ?' => $driver->id));
$flag = 0;
foreach ($bookings as $booking) {
$booking_startdate = strtotime($booking->startdate);
$booking_enddate = strtotime($booking->enddate);
if ($startdate < $enddate) {
$flag = 1;
break;
}
if ($startdate < $today) {
$flag = 1;
break;
}
if ($startdate >= $booking_startdate && $enddate <= $booking_enddate || $startdate <= $booking_startdate && $enddate >= $booking_enddate || $startdate <= $booking_startdate && $enddate <= $booking_enddate && $enddate >= $booking_startdate || $startdate >= $booking_startdate && $startdate <= $booking_enddate && $enddate >= $booking_enddate) {
$flag = 1;
break;
}
}
if ($driver->seater < RequestMethods::get('people')) {
$flag = 1;
}
if ($flag == 0) {
$available_drivers[$i] = $driver->id;
$i++;
}
}
$view->set('source', $source_state)->set('dest', $dest_state)->set('start', $start)->set('end', $end)->set('people', $people);
if (!empty($available_drivers)) {
$view->set('drivers', $available_drivers);
foreach ($available_drivers as $driver) {
$type_e = CabDriver::first(array('id = ?' => $driver));
if ($type_e->type == 'economy') {
$view->set('type1', '');
break;
}
}
foreach ($available_drivers as $driver) {
$type_e = CabDriver::first(array('id = ?' => $driver));
if ($type_e->type == 'premium') {
$view->set('type2', '');
break;
}
}
}
if ($this->user) {
if (RequestMethods::post('car')) {
foreach ($available_drivers as $driver) {
$cab = CabDriver::first(array('id = ?' => $driver, 'car_name = ?' => RequestMethods::post('car')));
break;
}
if ($cab) {
$booking = new CabBooking(array('user_id' => $this->user->id, 'driver_id' => $cab->id, 'startdate' => $start, 'enddate' => $end, 'startplace' => $source, 'endplace' => $dest));
if ($booking->validate()) {
$booking->save();
header('/cab/confirmation/' . $booking->id);
}
} else {
echo "<script> alert('Something went wrong') </script>";
}
}
} else {
echo "<script> alert('login first') </script>";
}
}