/** * Sanitize value according to parameter used * @param string $formFieldValue value of the formField * @param string $formFieldName name of the form field * @param string $parameter array containg rules * @return set or add to property values */ public function sanitize($formFieldValue, $formFieldName, $parameter) { try { switch ($parameter) { case 'string': $this->formFieldValues[$formFieldName] = Validate::cleanString($formFieldValue); break; case 'dateTime': if (Validate::isDateTime($formFieldValue)) { $this->formFieldValues[$formFieldName] = $formFieldValue; } else { $this->formFieldErrors[$formFieldName][] = ' Invalid Date '; $this->formFieldValues[$formFieldName] = $formFieldValue; } break; case 'bool': $formFieldValue = Validate::isNumber($formFieldValue); if ($formFieldValue > 1 || $formFieldValue < 0 || $formFieldValue == false) { throw new \Exception('That was unexpected!! or was it....'); } else { $this->formFieldValues[$formFieldName] = $formFieldValue; } break; case 'integer': $formFieldValue = Validate::isNumber($formFieldValue); if (!$formFieldValue) { throw new \Exception('That was unexpected!! or was it....'); } else { $this->formFieldValues[$formFieldName] = $formFieldValue; } break; } } catch (\Exception $e) { $this->page = 'error'; $this->error = $e; new ViewCtrl($this); } }
/** * Restore a task that has been marked as completed * - Validate data * - set query statement * - excute and redirect * @param array $post $_POST data * @return none */ public function restore($post) { $this->itemId = Validate::isNumber($post['itemId']); $query = "UPDATE todo SET completed = 0 , active = 1, date_updated = NOW() WHERE list_item_id = {$this->itemId}"; Connect::executeQuery($query); RouteCtrl::routeTo('/main/Task%20Restored'); }