Esempio n. 1
0
 /**
  * Validate the given {@link Todo} instance.
  * @param Todo $todo {@link Todo} instance to be validated
  * @return array array of {@link Error} s
  */
 public static function validate(Todo $todo)
 {
     $errors = array();
     if (!$todo->getCreatedOn()) {
         $errors[] = new Error('createdOn', 'Empty or invalid Created On.');
     }
     if (!$todo->getLastModifiedOn()) {
         $errors[] = new Error('lastModifiedOn', 'Empty or invalid Last Modified On.');
     }
     if (!trim($todo->getTitle())) {
         $errors[] = new Error('title', 'Title cannot be empty.');
     }
     if (!$todo->getDueOn()) {
         $errors[] = new Error('dueOn', 'Empty or invalid Due On.');
     }
     if (!trim($todo->getPriority())) {
         $errors[] = new Error('priority', 'Priority cannot be empty.');
     } elseif (!self::isValidPriority($todo->getPriority())) {
         $errors[] = new Error('priority', 'Invalid Priority set.');
     }
     if (!trim($todo->getStatus())) {
         $errors[] = new Error('status', 'Status cannot be empty.');
     } elseif (!self::isValidStatus($todo->getStatus())) {
         $errors[] = new Error('status', 'Invalid Status set.');
     }
     return $errors;
 }
Esempio n. 2
0
 private function getParams(Todo $todo)
 {
     $params = array(':id' => $todo->getId(), ':priority' => $todo->getPriority(), ':created_on' => self::formatDateTime($todo->getCreatedOn()), ':last_modified_on' => self::formatDateTime($todo->getLastModifiedOn()), ':due_on' => self::formatDateTime($todo->getDueOn()), ':title' => $todo->getTitle(), ':description' => $todo->getDescription(), ':comment' => $todo->getComment(), ':status' => $todo->getStatus(), ':deleted' => $todo->getDeleted());
     if ($todo->getId()) {
         // unset created date, this one is never updated
         unset($params[':created_on']);
     }
     return $params;
 }