Exemple #1
0
 public function validate()
 {
     $validation = array();
     //instatiate a new validator
     $validator = new Showcase_Admin_Validator();
     //title validation
     if (empty($this->_article['title'])) {
         $validation['Error'][] = 'Please fill in a title.';
     } else {
         if ($text = $validator->isValidText($this->_article['title'], 150)) {
             if (is_array($text)) {
                 if (isset($text['Error'])) {
                     $validation['Error'][] = $text['Error'];
                 }
             }
         }
     }
     //description validation
     if (empty($this->_article['description'])) {
         $validation['Error'][] = 'Please fill in a description.';
     } else {
         if ($description = $validator->isValidText($this->_article['description'], 1000)) {
             if (is_array($description)) {
                 if (isset($description['Error'])) {
                     $validation['Error'][] = $description['Error'];
                 }
             }
         }
     }
     //image validation
     if (isset($this->_image)) {
         if ($this->_image['error'] != 0 && $this->_image['error'] != 4) {
             $validation['Error'][] = array('Error' => 'Corrupt image. Please upload again.');
         } else {
             if ($this->_image['error'] != 4 && ($imageValidation = $validator->isValidImage($this->_image, '500000', '200', '250', array('image/jpg', 'image/gif')))) {
                 if (isset($imageValidation['Error'])) {
                     $validation['Error'][] = $imageValidation['Error'];
                 }
             }
         }
     }
     //date validation
     if (empty($this->_published)) {
         $validation['Error'][] = 'Please insert a date.';
     } else {
         if ($dateValidation = $validator->isValidDate($this->_published, 'dd/mm/YYYY')) {
             if (is_array($dateValidation)) {
                 if (isset($dateValidation['Error'])) {
                     $validation['Error'][] = $dateValidation['Error'];
                 }
             }
         }
     }
     if (!empty($validation)) {
         return $validation;
     } else {
         return true;
     }
 }
Exemple #2
0
 public function validate($post)
 {
     $validation = array();
     if (empty($post)) {
         $validation['Error'][] = 'No information submitted!';
         return $validation;
     }
     //instatiate a new validator
     $validator = new Showcase_Admin_Validator();
     //job number validation
     if (empty($post['number'])) {
         $validation['Error'][] = 'Please enter a Job Number.';
     } elseif (!is_numeric($post['number'])) {
         $validation['Error'][] = 'Job number is not exclusively numeric';
     }
     //title validation
     if (empty($post['title'])) {
         $validation['Error'][] = 'Please fill in a title.';
     } else {
         if ($titleValidation = $validator->isValidText($post['title'], 150)) {
             if (is_array($titleValidation)) {
                 if (isset($titleValidation['Error'])) {
                     $validation['Error'][] = $titleValidation['Error'];
                 }
             }
         }
     }
     //description validation
     if ($descriptionValidation = $validator->isValidText($post['description'], 1000)) {
         if (is_array($descriptionValidation)) {
             if (isset($descriptionValidation['Error'])) {
                 $validation['Error'][] = $descriptionValidation['Error'];
             }
         }
     }
     //image validation
     if (isset($post['media']['images']) && ($images = $post['media']['images'])) {
         foreach ($images as $image) {
             if ($image['error'] != 0 && $image['error'] != 4) {
                 $validation['Error'][] = 'Corrupt image. Please upload again.';
             } else {
                 if ($image['error'] != 4 && ($imageValidation = $validator->isValidImage($image, '500000', '200', '250', array('image/jpg', 'image/gif')))) {
                     if (isset($imageValidation['Error'])) {
                         $validation['Error'][] = $imageValidation['Error'];
                     }
                 }
             }
         }
     }
     //thumb validation
     if (isset($post['media']['thumbs']) && ($thumbs = $post['media']['thumbs'])) {
         foreach ($thumbs as $thumb) {
             if ($thumb['error'] != 0 && $thumb['error'] != 4) {
                 $validation['Error'][] = 'Corrupt image. Please upload again.';
             } else {
                 if ($thumb['error'] != 4 && ($thumbValidation = $validator->isValidImage($thumb, '500000', '200', '250', array('image/jpg', 'image/gif')))) {
                     if (isset($thumbValidation['Error'])) {
                         $validation['Error'][] = $thumbValidation['Error'];
                     }
                 }
             }
         }
     }
     //document validation
     if (isset($post['media']['documents'])) {
         foreach ($post['media']['documents'] as $document) {
             if ($document['error'] != 0 && $document['error'] != 4) {
                 $validation['Error'][] = 'Corrupt document or empty field. Please upload again.';
             } else {
                 if ($document['error'] != 4 && ($docValidation = $validator->isValidDocument($document, '500000', array('doc', 'pdf')))) {
                     if (isset($docValidation['Error'])) {
                         $validation['Error'][] = $docValidation['Error'];
                     }
                 }
             }
         }
     }
     //date validation
     if ($dateValidation = $validator->isValidDate($this->_post['datePublished'], 'dd/mm/YYYY')) {
         if (is_array($dateValidation)) {
             if (isset($dateValidation['Error'])) {
                 $validation['Error'][] = $dateValidation['Error'];
             }
         }
     }
     //return true or errors
     if (!empty($validation)) {
         return $validation;
     } else {
         return true;
     }
 }