示例#1
0
 public function action_getByService()
 {
     $id_service = $this->request->post('id');
     $limit = $this->request->post('limit');
     $offset = $this->request->post('offset');
     if (Request::current()->is_ajax() && $id_service) {
         $criteria = new \DBCriteria();
         $parent = \Model\Services::model()->findByPk($id_service);
         $childs = [$id_service];
         // Child Services
         if ($parent->parent_id == 0) {
             $child_serv = \Model\Services::model()->getListArray($id_service);
             if ($child_serv) {
                 $childs = array_keys($child_serv);
             }
         }
         $childs_sql = "(" . implode(",", $childs) . ")";
         // Find Places
         $criteria = new \DBCriteria();
         if ($limit) {
             $criteria->limit = $limit;
         } else {
             $criteria->limit = 2000;
         }
         if ($offset) {
             $criteria->offset = $offset;
         }
         $data = \Model\Places::model()->with(array('placeService' => array('select' => false, 'joinType' => 'INNER JOIN', 'condition' => ' placeService.idservice_type IN ' . $childs_sql)))->findAll($criteria);
         $result = [];
         $exclude = [];
         foreach ($this->exclude as $key => $value) {
             $exclude = array_merge($exclude, $value);
         }
         foreach ($data as $key => $value) {
             if (!in_array($value->idplaces, $exclude)) {
                 $service_type = $value->placeService->idservice_type;
                 $push = ['item_id' => $value->idplaces, 'center_lat' => $value->lat, 'center_lng' => $value->lng, 'service_type' => $service_type];
                 $result[] = $push;
             }
         }
         $this->response->body(json_encode(['data' => $result]));
     }
 }
示例#2
0
 public function getServices()
 {
     $data = \Model\Services::model()->with(['serviceChilds'])->findAllByAttributes(['parent_id' => 0]);
     return $data;
 }