public function put($id = null) { if (empty($id)) { new Error("Safety Check ID cannot be empty"); } $fields = array(); parse_str(file_get_contents("php://input"), $fields); $result = RequiredFields::getFields(array('completed' => array('required' => true, 'regex' => '/^(0|1)$/')), $fields); $fields = array(); foreach ($result['data'] as $key => $value) { if (!empty($key) && !empty($value)) { $fields[$key] = $value; } } if (0 < count($fields)) { $this->db->prepareUpdate($fields); if ($this->db->update($this->tableName, $id)) { $this->get($id); } else { new Error("Could not update safety check"); } } else { new Error("No values to update"); } }
public function put($customerId = null, $carId = null) { if (empty($carId)) { new Error("Car ID cannot be empty"); } $fields = array(); parse_str(file_get_contents("php://input"), $fields); $result = RequiredFields::getFields(array('owner' => array('regex' => '/^\\d+$/'), 'make' => array('regex' => '/^.{1,100}$/'), 'model' => array('regex' => '/^.{1,100}$/'), 'registration' => array('regex' => '/^[A-Z0-9]{1,6}$/')), $fields); $fields = array(); foreach ($result['data'] as $key => $value) { if (!empty($key) && !empty($value)) { $fields[$key] = $value; } } if (0 < count($fields)) { $this->db->prepareUpdate($fields); if ($this->db->update($this->tableName, $carId)) { $this->get(array_key_exists('owner', $fields) ? $fields['owner'] : $customerId, $carId); } else { new Error("Could not update customer"); } } else { new Error("No values to update"); } }
public function put($id = null) { if (empty($id)) { new Error("Customer ID cannot be empty"); } $fields = array(); parse_str(file_get_contents("php://input"), $fields); $result = RequiredFields::getFields(array('firstname' => array('regex' => '/^.{1,30}$/'), 'lastname' => array('regex' => '/^.{1,30}$/'), 'address' => array('regex' => '/^.{1,100}$/'), 'city' => array('regex' => '/^.{1,50}$/'), 'state' => array('regex' => '/^.{1,20}$/'), 'postcode' => array('regex' => '/^\\d{4}$/')), $fields); $fields = array(); foreach ($result['data'] as $key => $value) { if (!empty($key) && !empty($value)) { $fields[$key] = $value; } } if (0 < count($fields)) { $this->db->prepareUpdate($fields); if ($this->db->update($this->tableName, $id)) { $this->get($id); } else { new Error("Could not update customer"); } } else { new Error("No values to update"); } }
public function put($id = null) { if (empty($id)) { new Error("Item ID cannot be empty"); } $fields = array(); parse_str(file_get_contents("php://input"), $fields); $result = RequiredFields::getFields(array('invoice' => array('regex' => '/^\\d+$/'), 'amount' => array('regex' => '/^([\\d]*\\.[\\d]+|[\\d]+)$/'), 'comment' => array(), 'date' => array('regex' => '/^2\\d{3}\\-[01]\\d\\-[0-3]\\d$/')), $fields); $fields = array(); foreach ($result['data'] as $key => $value) { if (!empty($key) && !empty($value)) { $fields[$key] = $value; } } if (0 < count($fields)) { $this->db->prepareUpdate($fields); if ($this->db->update($this->tableName, $id)) { $this->get($id); } else { new Error("Could not update payment"); } } else { new Error("No values to update"); } }
public function put($id = null) { if (empty($id)) { new Error("Item ID cannot be empty"); } $fields = array(); parse_str(file_get_contents("php://input"), $fields); $result = RequiredFields::getFields(array('description' => array('regex' => '/^.{1,100}$/'), 'defaultCost' => array('regex' => '/^[-+]?([\\d]*\\.[\\d]+|[\\d]+)$/'), 'defaultQuantity' => array('regex' => '/^[-+]?([\\d]*\\.[\\d]+|[\\d]+)$/'), 'comment' => array('regex' => '/^(0|1)$/'), 'active' => array('regex' => '/^(0|1)$/')), $fields); $fields = array(); foreach ($result['data'] as $key => $value) { if (!empty($key) && !empty($value)) { $fields[$key] = $value; } } if (0 < count($fields)) { $this->db->prepareUpdate($fields); if ($this->db->update($this->tableName, $id)) { $this->get($id); } else { new Error("Could not update item"); } } else { new Error("No values to update"); } }
public function post() { $result = RequiredFields::getFields(array('owner' => array('required' => true, 'regex' => '/^\\d+$/'), 'car' => array('required' => true, 'regex' => '/^\\d+$/'), 'odo' => array('required' => true, 'regex' => '/^\\d{1,6}$/'), 'safetyCheck' => array('required' => true, 'regex' => '/^\\d+$/')), $_POST); if ($result['error']) { new Error("Invalid values passed", $result['data']); } else { $this->db->prepareInsert($result['data']); if ($this->db->insert($this->tableName)) { $this->get($this->db->lastId()); } else { new Error("Error inserting service record"); } } }
public function post() { $result = RequiredFields::getFields(array('service' => array('required' => true, 'regex' => '/^\\d+$/'), 'bankDetails' => array('regex' => '/^(0|1)$/')), $_POST); if ($result['error']) { new Error("Invalid values passed", $result['data']); } else { $this->db->prepareInsert($result['data']); if ($this->db->insert($this->tableName)) { $this->get($this->db->lastId()); //new Respond(array('id' => $this->db->lastId())); } else { new Error("Error inserting customer record"); } } }