Beispiel #1
0
 /**
  * Set a device disabled
  * @param $result
  * @return mixed
  */
 public function setDeviceDisabled($result)
 {
     // validate input
     if (!is_numeric($this->data->id)) {
         $result['error'] = "A valid id must be supplied";
         return $result;
     }
     // get location id
     $devMdl = new DevicesModel();
     if ($this->data->disable == false) {
         // we don't want to enable a device with a disabled location
         $dev = $devMdl->get($this->data->id)[0];
         if (!$this->doesLocationExist($dev['locationid'])) {
             $result['error'] = "The devices location is disabled, pick a new location or enable it.";
             return $result;
         }
     }
     if ($devMdl->setDisabled($this->data->id, boolval($this->data->disable)) === false) {
         $result['error'] = "Could not enable/disable the device";
     }
     // log data
     Logger::write("Device " . ($this->data->disable == true ? "disabled" : "enabled") . " with id:" . $this->data->id, "CONFIG");
     return $result;
 }