public function editAction($dealerId = NULL)
 {
     $this->view->setVar("title", "Редагування дилера");
     $user = $this->session->get("user");
     $methodistBrands = \BrandsMethodists::find("user_id=" . $user->id)->toArray();
     $methodistActivities = \ActivitiesMethodists::find("user_id=" . $user->id)->toArray();
     $dealer = $dealerId ? \Dealers::findFirst($dealerId) : new \Dealers();
     if ($dealerId and !$dealer->id) {
         // не найден такой диллер
         $this->view->pick("dealer/not-found");
         return;
     }
     $city = $dealer->City;
     $this->view->regionId = $city ? $city->Region->id : NULL;
     $dealerBrands = $dealer->id ? $dealer->DealersBrands->toArray() : array();
     $dealerActivities = $dealer->id ? \DealersActivities::find("dealer_id=" . $dealer->id)->toArray() : array();
     $this->view->dealers = \Dealers::find(array('order' => 'title'));
     $this->view->regions = \Region::find();
     $this->view->regionFirst = $this->view->regions[0];
     $this->view->cities = \City::find();
     $this->view->staffListGroup = \StafflistGroup::find();
     $this->view->brands = BrandsService::getForChosenEntity(\Brands::find()->toArray(), $methodistBrands, $dealerBrands);
     $this->view->activities = ActivitiesService::getForChosenEntity(\Activities::find()->toArray(), $methodistActivities, $dealerActivities);
     $this->view->dealerStatuses = \DealerStatuses::find();
     $controllers = \Users::query()->rightJoin("UserGroups")->where("UserGroups.group_id = 3")->execute();
     $this->view->controllers = $controllers;
     $this->view->dealerControllers = $dealer->DealersControllers;
     $this->view->dealer = $dealer;
     $this->view->saved = $this->request->get("saved");
 }
 public function getimageAction()
 {
     $this->_helper->layout->disableLayout();
     $id = (int) $this->_request->getParam('id', 0);
     $brandTable = new Brands();
     $brand = $brandTable->find($id)->current();
     //Zend_Debug::dump($photo);
     header("Content-type:{$brand->logo_type}");
     $this->view->image = base64_decode($brand->logo);
 }
Exemple #3
0
 public function updatebrands($id)
 {
     $rules = array('brand_name' => 'sometimes|required|min:2|max:30', 'description' => 'sometimes|required|min:2|max:30', 'brand_image' => 'sometimes|required|min:2|max:30', 'brand_logo' => 'sometimes|required|min:2|max:30');
     $messages = array('brand_name.required' => 'Brand Name is required.', 'description.required' => 'Description is required.', 'brand_image.required' => 'Brand Image is required.', 'brand_logo.required' => 'Brand Logo is required.');
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return $this->response(array('statusCode' => 400, 'statusDescription' => 'Bad Request', 'errors' => $validator->messages()->toJson()));
     } else {
         $brand_name = Input::get('brand_name');
         $description = Input::get('description');
         $brand_image = Input::get('brand_image');
         $brand_logo = Input::get('brand_logo');
         Brands::find($id)->update(array('brand_name' => $brand_name, 'description' => $description, 'brand_image' => $brand_image, 'brand_logo' => $brand_logo));
         return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success', 'message' => "Brand Update Successfully"));
     }
 }
 /**
  * Возвращает список брендов для пересохранения (дилера, курса, и тд.)
  * @param $brandsMethodist - все доступные бренды методиста
  * @param $entityBrands - бренды сущности
  * @param array $formBrands - бренды из формы
  * @return array
  */
 public static function getCalculationResult($brandsMethodist, $entityBrands, array $formBrands)
 {
     $brandsAll = \Brands::find();
     $data = array();
     foreach ($brandsAll as $brand) {
         $issetInMethodist = EntityService::inEntityRecursive($brandsMethodist, $brand->id, "brand_id");
         $issetInEntity = EntityService::inEntityRecursive($entityBrands, $brand->id, "brand_id");
         // если бренд отсутствует у методиста и присудствует у entity
         if (!$issetInMethodist and $issetInEntity) {
             $data[] = $brand;
         }
     }
     if ($formBrands === array()) {
         return $data;
     }
     $brandsByForm = \Brands::find("id IN (" . implode(",", $formBrands) . ")");
     foreach ($brandsByForm as $brandByForm) {
         $data[] = $brandByForm;
     }
     return $data;
 }
 public function editAction($id = NULL)
 {
     $this->view->title = "Редагувати студента";
     $this->view->nothing = true;
     $this->view->ind_code = $this->request->get("ind_code");
     if (!is_null($this->view->ind_code) && $this->checkINN($this->view->ind_code) || !is_null($id)) {
         $this->view->nothing = false;
         $this->view->student = is_null($id) ? \Students::findFirst("ind_code = " . $this->view->ind_code) : \Students::findFirst($id);
         $this->view->user = $this->session->get("user");
         $methodistBrands = \BrandsMethodists::find("user_id=" . $this->view->user->id)->toArray();
         $methodistActivities = \ActivitiesMethodists::find("user_id=" . $this->view->user->id)->toArray();
         if ($this->view->student != NULL) {
             $this->view->ind_code = $this->view->student->ind_code;
             $this->view->user = \Users::findFirst($this->view->student->user_id);
             $studentBrands = BrandsService::getStudentBrands($this->view->student);
             $studentActivities = ActivitiesService::getStudentActivities($this->view->student);
             $studentPostsJSON = array();
             if ($this->view->student->StudentsPosts != NULL) {
                 foreach ($this->view->student->StudentsPosts as $sp) {
                     //{"dealer":"1","post":"2","brands":["2", "5"],"activities":["1"],"rate":"1.0","appoint_date":"2015-04-01"}
                     $studentPostsJSON[$sp->id] = array();
                     $studentPostsJSON[$sp->id]["dealer"] = $sp->dealer;
                     $studentPostsJSON[$sp->id]["post"] = $sp->post;
                     $array = array();
                     foreach ($sp->StudentsPostsBrands as $spb) {
                         $array[] = $spb->Brands->id;
                     }
                     $studentPostsJSON[$sp->id]["brands"] = $array;
                     $array = array();
                     foreach ($sp->StudentsPostsActivities as $spa) {
                         $array[] = $spa->Activities->id;
                     }
                     $studentPostsJSON[$sp->id]["activities"] = $array;
                     $studentPostsJSON[$sp->id]["rate"] = $sp->rate;
                     $studentPostsJSON[$sp->id]["appoint_date"] = $sp->appoint_date;
                 }
             }
             //$this->view->student->StudentsEducation;
         } else {
             $this->view->student = new \Students();
             $this->view->user = new \Users();
             $studentPostsJSON = array();
             $studentBrands = array();
             $studentActivities = array();
         }
         $this->view->brands = BrandsService::getForChosenEntity(\Brands::find()->toArray(), $methodistBrands, $studentBrands);
         $this->view->activities = ActivitiesService::getForChosenEntity(\Activities::find()->toArray(), $methodistActivities, $studentActivities);
         $this->view->allEducations = \Educations::find("parent_id is NULL");
         $this->view->allDealers = \Dealers::find();
         $this->view->studentPostsJSON = $studentPostsJSON;
     }
 }