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
 /**
  * Show the form for creating a new resource.
  * GET /api/create
  *
  * @return Response
  */
 public function css($id)
 {
     $css = "";
     foreach (Application::find($id)->versions()->get() as $version) {
         $css = $css . $version->css;
     }
     return Response::make($css, '200')->header('Content-Type', 'text/css');
 }
 public function deleteScore()
 {
     $application_id = Input::get('application_id');
     $application = Application::find($application_id);
     if (!$application->delete()) {
         return Response::json(array('errCode' => 1, 'message' => '删除失败!'));
     }
     return Response::json(array('errCode' => 0, 'message' => '删除成功!'));
 }
 public function postStore()
 {
     $input = \Input::all();
     if ($input['parent_id']) {
         $parentApplication = \Application::find($input['parent_id']);
     } else {
         $parentApplication = $this->application;
     }
     $validation = \Validator::make($input, \Application::$rules);
     // dd($input);
     if ($validation->passes()) {
         $newApp = new \Application();
         $newApp->name = $input['name'];
         $newApp->user_id = \Auth::user()->id;
         //$newApp->parent_id = $parentApplication->id;
         $newApp->cms_package = $parentApplication->cms_package;
         $parentApplication->children()->save($newApp);
         //TODO: Fix baum here - not saving correctly
         \Application::rebuild();
         //we need to do the urls..
         $domains = explode(',', $input['domain']);
         $appUrls = [];
         foreach ($domains as $domain) {
             $appUrl = new \ApplicationUrl();
             $appUrl->domain = $domain;
             $appUrl->folder = '/';
             //TODO: folders - is this ever going to work?
             $appUrls[] = $appUrl;
         }
         $newApp->url()->saveMany($appUrls);
         //and the plugins
         $parentPlugins = $parentApplication->plugins()->get();
         foreach ($parentPlugins as $parentPlugin) {
             $newApp->plugins()->attach($parentPlugin->id);
             //associate($parentPlugin)
         }
         return redirect()->action('\\Bootleg\\Cms\\ApplicationController@anyIndex')->with(['success' => 'Application Succesfully Created']);
     }
     \Request::flash();
     return redirect()->back()->withErrors($validation->errors());
 }
Example #5
0
 public function applyAction()
 {
     if ($this->request->isPost()) {
         $user = $this->getAuth();
         $new_car = $this->request->getPost('new_car');
         if ($new_car == 0) {
             $car = Car::findFirst(array('conditions' => 'number = ?1', 'bind' => array(1 => $this->request->getPost('choose-car'))));
         } else {
             $car = new Car();
             $car->number = $this->request->getPost('number');
             $car->brand = $this->request->getPost('brand');
             $car->model = $this->request->getPost('model');
             $car->owner = $user['user_id'];
             if (!$car->save()) {
                 message($this, "d", "Данные об автомобиле указаны неверно");
                 return $this->response->redirect("applyForService");
             }
         }
         if ($car) {
             $date = $this->request->getPost('date');
             $time = $this->request->getPost('time');
             $apps = Application::find(array('conditions' => 'term = ?1', 'bind' => array(1 => $date)));
             if ($date) {
                 if ($time) {
                     if (count($apps) < 4 * 20) {
                         $services = $this->request->getPost('services');
                         if (count($services) > 0) {
                             $app = new Application();
                             $app->car = $car->number;
                             $app->term = $date . ' ' . $time;
                             $app->confirmed = 0;
                             $app->manager = NULL;
                             if ($app->save()) {
                                 foreach ($services as $service) {
                                     $as = new ApplicationService();
                                     $as->application_id = $app->id;
                                     $as->service_id = $service;
                                     if (!$as->save()) {
                                         message($this, "d", "Ошибка при сохранении выбранной услуги");
                                         return $this->response->redirect("applyForService");
                                     }
                                 }
                                 //todo! Обработка поля с доп. информацией
                                 message($this, "s", "Заявка отправлена. В ближайшее время наш менеджер свяжется с Вами для ее подтверждения");
                                 return $this->response->redirect("cabinet");
                             } else {
                                 message($this, "d", "Ошибка при сохранении заявки");
                                 foreach ($app->getMessages() as $message) {
                                     message($this, "d", "Ошибка: " . $message->getMessage() . " в поле " . $message->getField() . ". Тип: " . $message->getType());
                                 }
                                 return $this->response->redirect("applyForService");
                             }
                         } else {
                             message($this, "d", "Минимум одна услуга должна быть выбрана");
                             return $this->response->redirect("applyForService");
                         }
                     } else {
                         message($this, "d", "Выбранная дата занята. Пожалуйста, выберите другой день");
                         return $this->response->redirect("applyForService");
                     }
                 } else {
                     message($this, "d", "Время не выбрано!");
                     return $this->response->redirect("applyForService");
                 }
             } else {
                 message($this, "d", "Дата не выбрана!");
                 return $this->response->redirect("applyForService");
             }
         } else {
             message($this, "d", "Автомобиль не найден");
             return $this->response->redirect("applyForService");
         }
     }
 }
 public function getSwitch($id)
 {
     $application = \Application::find($id);
     if ($application) {
         \Session::put('cms_app', $id);
         return redirect()->back()->with('message', 'Application switched');
     } else {
         return redirect()->back()->with('message', 'An error occured when switching app');
     }
 }
 /**
  * Remove the specified resource from storage.
  * DELETE /application/{appid}/{versionid}
  *
  * @param  int  $appid
  * @param  int  $versionid
  * @return Response
  */
 public function deleteLink($appid, $versionid)
 {
     Application::find($appid)->versions()->detach($versionid);
     return Redirect::action('ApplicationController@show', [$appid])->withSuccess('Plugin removed.');
 }