public function applicationsAction()
 {
     $date = new DateTime("now");
     if ($this->request->isPost() and $this->request->isAjax()) {
         $start_from = $this->request->getPost('start_from', 'int');
         $type = $this->request->getPost('type', 'int');
         if ($type == 1) {
             $apps = Application::find(array('conditions' => 'confirmed = 0 and term >= ?1', 'order' => 'term DESC', 'limit' => '5', 'offset' => $start_from, 'bind' => array(1 => $date->format('Y.m.d'))));
         } else {
             if ($type == 2) {
                 $apps = Application::find(array('conditions' => 'confirmed = 1 and term >= ?1', 'order' => 'term DESC', 'limit' => '5', 'offset' => $start_from, 'bind' => array(1 => $date->format('Y.m.d'))));
             } else {
                 if ($type == 3) {
                     $apps = Application::find(array('conditions' => 'confirmed = 1 and term < ?1', 'order' => 'term DESC', 'limit' => '5', 'offset' => $start_from, 'bind' => array(1 => $date->format('Y.m.d'))));
                 } else {
                     $apps = array();
                 }
             }
         }
         $services = array();
         $users = array();
         foreach ($apps as $key => $app) {
             $str = "";
             $a_ss = ApplicationService::find(array('conditions' => 'application_id = ?1', 'bind' => array(1 => $app->id)));
             foreach ($a_ss as $a_s) {
                 $service = Service::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $a_s->service_id)));
                 $str .= $service->name . ', ';
             }
             $services[$key] = substr($str, 0, -2) . '.';
             $car = Car::findFirst(array('conditions' => 'number = ?1', 'bind' => array(1 => $app->car)));
             $users[$key] = User::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $car->owner)));
         }
         if (count($apps) > 0) {
             $view = clone $this->view;
             $view->start();
             $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
             $view->setParamToView('apps', $apps);
             $view->setParamToView('type', $type);
             $view->setParamToView('services', $services);
             $view->setParamToView('users', $users);
             $view->render('admin', 'applications');
             $view->finish();
             $content = $view->getContent();
             $this->view->disable();
             $status = 200;
             $description = 'OK';
             $headers = array();
             $contentType = 'application/json';
             $content = json_encode($content);
             $response = new \Phalcon\Http\Response();
             $response->setStatusCode($status, $description);
             $response->setContentType($contentType, 'UTF-8');
             $response->setContent($content);
             foreach ($headers as $key => $value) {
                 $response->setHeader($key, $value);
             }
             return $response;
         } else {
             return 0;
         }
     }
 }
Example #2
0
 public function applicationsAction()
 {
     //if ($this->request->isPost() and $this->request->isAjax())
     //{
     $start_from = $this->request->getPost('start_from', 'int');
     $user = $this->getAuth();
     $cars = Car::find(array('conditions' => 'owner = ?1', 'bind' => array(1 => $user['user_id'])));
     $cn = array();
     $prices = array();
     foreach ($cars as $car) {
         $cn[] = $car->number;
     }
     $apps = Application::find(array('conditions' => 'car IN ' . "('" . implode("','", $cn) . "')", 'order' => 'term DESC'));
     $services = array();
     foreach ($apps as $key => $app) {
         $str = array();
         $pr = 0;
         $a_ss = ApplicationService::find(array('conditions' => 'application_id = ?1', 'bind' => array(1 => $app->id)));
         foreach ($a_ss as $a_s) {
             $service = Service::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $a_s->service_id)));
             $str[] = $service->name . " - " . $service->price;
             $pr += $service->price;
         }
         $services[$key] = $str;
         $prices[$key] = $pr;
     }
     $date = new DateTime("now");
     $this->view->setParamToView('apps', $apps);
     $this->view->setParamToView('today', $date->format('Y.m.d'));
     $this->view->setParamToView('services', $services);
     $this->view->setParamToView('prices', $prices);
     //}
 }