示例#1
0
 public function run()
 {
     $res = $this->response;
     $id = $this->req('id');
     $offer = \Car\Offer::find($id);
     if ($offer) {
         $status = 400;
         $message = 'fill-all-fields';
         $data = null;
         $f = $res->form(array('use_comm' => true));
         $f->input(array('type' => 'text', 'name' => 'name', 'required' => true));
         $f->input(array('type' => 'text', 'name' => 'phone', 'required' => true));
         $f->input(array('type' => 'email', 'name' => 'email', 'required' => true));
         $f->input(array('type' => 'textarea', 'name' => 'desc', 'required' => false));
         if ($f->submited()) {
             if ($f->passed()) {
                 $attrs = $f->get_data();
                 $attrs['car'] = $id;
                 $status = 200;
                 $message = 'saved';
                 $item = new \Car\Request($attrs);
                 $item->save();
                 $item->send_notif($res);
                 $data = $item->get_data();
             } else {
                 $data = $f->get_errors();
             }
         }
         $res->mime = 'text/html';
         $this->json_response($status, $message, $data);
     } else {
         throw new \System\Error\NotFound();
     }
 }
示例#2
0
 public function run()
 {
     $res = $this->response;
     $status = 400;
     $message = 'fill-all-fields';
     $data = null;
     $icons = \Car\Offer::get_attr_options('icon');
     $opts = array();
     foreach ($icons as $icon) {
         $opts[] = array('value' => $icon, 'name' => $icon);
     }
     $ident = $this->ident;
     def($ident, null);
     $f = $res->form(array('use_comm' => true));
     $f->input(array('type' => 'text', 'name' => 'driver', 'required' => true));
     $f->input(array('type' => 'text', 'name' => 'from', 'required' => true));
     $f->input(array('type' => 'number', 'name' => 'seats', 'min' => 1, 'required' => true));
     $f->input(array('type' => 'datetime', 'name' => 'departure', 'required' => true));
     $f->input(array('type' => 'select', 'name' => 'icon', 'required' => true, 'options' => $opts));
     $f->input(array('name' => 'phone', 'type' => 'phone', 'required' => true));
     $f->input(array('type' => 'email', 'name' => 'email', 'required' => true));
     $f->input(array('type' => 'textarea', 'name' => 'desc', 'required' => false));
     if ($f->submited()) {
         if ($f->passed()) {
             $attrs = $f->get_data();
             $status = 200;
             $message = 'saved';
             if ($ident) {
                 $item = \Car\Offer::get_first()->where(array('ident' => $ident))->fetch();
                 if (!$item) {
                     throw new \System\Error\NotFound();
                 }
             } else {
                 $item = new \Car\Offer();
             }
             $item->update_attrs($attrs);
             $item->visible = true;
             $item->save();
             if (!$item->sent_notif) {
                 $item->send_notif($res);
             }
             $data = $item->get_data();
         } else {
             $data = $f->get_errors();
         }
         $res->mime = 'text/html';
         if (!isset($ident) || $f->submited()) {
             $this->json_response($status, $message, $data);
         }
     }
 }
示例#3
0
 public function run()
 {
     $this->req('ident');
     $offer = \Car\Offer::get_first()->where(array('ident' => $this->ident, 'visible' => true))->fetch();
     if ($offer) {
         $cfg = $this->request->fconfig;
         $cfg['ui']['data'] = array(array('model' => 'Car.Offer', 'items' => array($offer->to_object_with_perms($this->request->user))));
         $this->request->fconfig = $cfg;
         $this->response->subtitle = 'úpravy nabídky na sdílení auta';
         $this->partial('car/admin/form', array("item" => $offer, "requests" => $offer->requests->fetch()));
     } else {
         throw new \System\Error\NotFound();
     }
 }
示例#4
0
 public function run()
 {
     $data = $this->dbus->get_data('admin');
     $offer = null;
     if (isset($data['offer'])) {
         $offer = $data['offer'];
     }
     if (!$offer) {
         $id = $this->req('id');
         $offer = \Car\Offer::get_first()->where(array('id_car_offer' => $id, 'visible' => true))->fetch();
     }
     if ($offer) {
         $this->response->subtitle = $offer->driver . ' vás zve na cestu na Improtřesk 2016';
         $this->partial('car/offer-detail', array("item" => $offer, "free" => $offer->seats - $offer->requests->where(array('status' => 2))->count(), "show_form" => !!$this->show_form, "show_rq" => true, "requests" => $offer->requests->where(array('status' => array(1, 2)))->fetch()));
     } else {
         throw new \System\Error\NotFound();
     }
 }
示例#5
0
 public function run()
 {
     $rq = $this->request;
     $res = $this->response;
     $ident = $this->req('ident');
     $offer = \Car\Offer::get_first()->where(array('ident' => $ident, 'visible' => true))->fetch();
     if ($offer) {
         $cfg = $rq->fconfig;
         $cfg['ui']['data'] = array(array('model' => 'Car.Offer', 'items' => array($offer->to_object_with_perms($rq->user))));
         $rq->fconfig = $cfg;
         $res->subtitle = 'úpravy nabídky na sdílení auta';
         $this->propagate('offer', $offer);
         $this->propagate('id', $offer->id);
         $this->partial('car/admin/links', array("ident" => $ident, "slot" => 'detail'));
     } else {
         throw new \System\Error\NotFound();
     }
 }
示例#6
0
 public function run()
 {
     $all = \Car\Offer::get_all()->add_filter(array('attr' => 'seats', 'type' => 'gt', 'gt' => 'used', 'self' => true))->add_filter(array('attr' => 'seats', 'type' => 'gt', 'gt' => 0))->sort_by('departure')->fetch();
     $this->partial('car/offer-list', array('list' => $all));
 }