Advertisement
Eddz

Untitled

Sep 6th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Fcm\Form\Validator;
  4.  
  5. use Zend\Form\Form;
  6. use Zend\Form\Element;
  7. use Zend\Validator\AbstractValidator;
  8.  
  9. class TypeCampaign extends AbstractValidator
  10. {
  11.  
  12.     const DEFAULT_MESSAGE = 'msgDraw';
  13.  
  14.     protected $messageTemplates = array(
  15.         self::DEFAULT_MESSAGE => "'%value%' is required and can't be empty",
  16.     );
  17.     public $currentField;
  18.  
  19.     public function __construct($currentField = null)
  20.     {
  21.         parent::__construct();
  22.         $this->currentField = $currentField;
  23.     }
  24.  
  25.     public function isValid($value, $context = null)
  26.     {
  27.         switch ($context['typecampaign']) {
  28.             // No type campaign selected
  29.             case 0:
  30.                 if ($context['typecampaign'] == 0 && $this->currentField == 'typecampaign') {
  31.                     $this->error(self::DEFAULT_MESSAGE, $context['typecampaign']);
  32.                     return false;
  33.                 } else {
  34.                     return true;
  35.                 }
  36.             // Draw
  37.             case 2:
  38.                 if ($context['draw'] == " " && $this->currentField == 'draw') {
  39.                     $this->error(self::DEFAULT_MESSAGE, 'Draw');
  40.                     return false;
  41.                 } else {
  42.                     return true;
  43.                 }
  44.                 break;
  45.             // Answer/Question
  46.             case 3:
  47.                 if ($context['answerquestion_question'] == " " && $this->currentField == 'answerquestion_question') {
  48.                     $this->error(self::DEFAULT_MESSAGE, $value);
  49.                     return false;
  50.                 } else {
  51.                     return true;
  52.                 }
  53.                 break;
  54.             // Multiple choice
  55.             case 4:
  56.                 if ($context['multiplechoice_question'] == null ||
  57.                         $context['multiplechoice_correct_answer'] == null ||
  58.                         $context['multiplechoice_wrong1'] == null ||
  59.                         $context['multiplechoice_wrong2'] == null
  60.                 ) {
  61.                     $this->error(self::MSG_DRAW, $value);
  62.                     return false;
  63.                 } else {
  64.                     return true;
  65.                 }
  66.                 break;
  67.  
  68.             default:
  69.                 return true;
  70.                 break;
  71.         }
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement