Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Fcm\Form\Validator;
- use Zend\Form\Form;
- use Zend\Form\Element;
- use Zend\Validator\AbstractValidator;
- class TypeCampaign extends AbstractValidator
- {
- const DEFAULT_MESSAGE = 'msgDraw';
- protected $messageTemplates = array(
- self::DEFAULT_MESSAGE => "'%value%' is required and can't be empty",
- );
- public $currentField;
- public function __construct($currentField = null)
- {
- parent::__construct();
- $this->currentField = $currentField;
- }
- public function isValid($value, $context = null)
- {
- switch ($context['typecampaign']) {
- // No type campaign selected
- case 0:
- if ($context['typecampaign'] == 0 && $this->currentField == 'typecampaign') {
- $this->error(self::DEFAULT_MESSAGE, $context['typecampaign']);
- return false;
- } else {
- return true;
- }
- // Draw
- case 2:
- if ($context['draw'] == " " && $this->currentField == 'draw') {
- $this->error(self::DEFAULT_MESSAGE, 'Draw');
- return false;
- } else {
- return true;
- }
- break;
- // Answer/Question
- case 3:
- if ($context['answerquestion_question'] == " " && $this->currentField == 'answerquestion_question') {
- $this->error(self::DEFAULT_MESSAGE, $value);
- return false;
- } else {
- return true;
- }
- break;
- // Multiple choice
- case 4:
- if ($context['multiplechoice_question'] == null ||
- $context['multiplechoice_correct_answer'] == null ||
- $context['multiplechoice_wrong1'] == null ||
- $context['multiplechoice_wrong2'] == null
- ) {
- $this->error(self::MSG_DRAW, $value);
- return false;
- } else {
- return true;
- }
- break;
- default:
- return true;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement