/** * Generate index page - check for a message, get list of active and completed items * display page * @param array $get [description] * @return view */ public function index($get) { $this->pageTitle = 'Home'; $this->page = 'index'; if (isset($get['message'])) { $this->message = Validate::cleanString($get['message']); } $this->activeList = (new ItemList())->getActive(); $this->completedList = (new ItemList())->getCompleted(); $content = $this->createContentArray(); new ViewCtrl($content); }
/** * Check if form key has been set if yes sanitize it * then check if the method for processing this form exits if it does * call it. * * @return process call or error page */ public function processPost() { try { $post = $_POST; if (isset($post['form'])) { $post['form'] = Validate::cleanString($post['form']); if (method_exists(new Process(), $post['form'])) { (new Process())->{$post}['form']($post); } else { throw new \Exception("Oops something went wrong"); } } else { throw new \Exception("Oops something went wrong"); } } catch (Exception $e) { $this->page = 'error'; $this->error = $e; new ViewCtrl($this); } }
/** * 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'); }