Пример #1
0
 /**
  * Update a device name and location
  * @param $result
  * @return mixed
  */
 public function updateDevice($result)
 {
     // validate input
     $jsonval = new JsonValidate($this->data, '{"devid":1, "devname":"", "locid":1}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     if (!$this->doesLocationExist($this->locationId)) {
         $result['error'] = "The location id specified does not exist";
         return $result;
     }
     $devMdl = new DevicesModel();
     if ($devMdl->edit($this->deviceId, $this->deviceName, $this->locationId) !== false) {
         $result['data'] = true;
         // log data
         Logger::write("Device updated", "CONFIG", json_encode($this->data));
     } else {
         $result['error'] = "Could not update the device";
     }
     return $result;
 }
Пример #2
0
 /**
  * Update a device name and location
  * @param $result
  * @return mixed
  */
 public function updateDevice($result)
 {
     // validate input
     $jsonval = new JsonValidate($this->data, '{"id":1, "name":"", "locationid":1, "type":"", "ordertype":"", "orderdisplay":""}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     if (!$this->doesLocationExist($this->data->locationid)) {
         $result['error'] = "The location id specified does not exist";
         return $result;
     }
     $devMdl = new DevicesModel();
     if ($devMdl->edit($this->data->id, $this->data) !== false) {
         $result['data'] = $this->data;
         $socketIO = new WposSocketIO();
         $socketIO->sendDeviceConfigUpdate($this->data->id, $this->data);
         // log data
         Logger::write("Device updated", "CONFIG", json_encode($this->data));
     } else {
         $result['error'] = "Could not update the device";
     }
     return $result;
 }