. */ namespace SP\Forms; use SP\Core\Acl\ActionsInterface; use SP\Core\Exceptions\ValidationException; use SP\Core\Messages\NoticeMessage; use SP\DataModel\NoticeData; use SP\Http\Request; /** * Class NoticeForm * * @package SP\Forms */ class NoticeForm extends FormBase implements FormInterface { /** * @var NoticeData */ protected $noticeData; /** * Validar el formulario * * @param $action * @return bool * @throws \SP\Core\Exceptions\ValidationException */ public function validate($action) { switch ($action) { case ActionsInterface::NOTICE_USER_CREATE: case ActionsInterface::NOTICE_USER_EDIT: $this->analyzeRequestData(); $this->checkCommon(); break; } return true; } /** * Analizar los datos de la petición HTTP * * @return void */ protected function analyzeRequestData() { $Description = new NoticeMessage(); $Description->addDescription(Request::analyze('notice_description')); $this->noticeData = new NoticeData(); $this->noticeData->setNoticeId($this->itemId); $this->noticeData->setNoticeType(Request::analyze('notice_type')); $this->noticeData->setNoticeComponent(Request::analyze('notice_component')); $this->noticeData->setNoticeDescription($Description); $this->noticeData->setNoticeUserId(Request::analyze('notice_user', 0)); if ($this->noticeData->getNoticeUserId() === 0) { $this->noticeData->setNoticeOnlyAdmin(Request::analyze('notice_onlyadmin', 0, false, 1)); $this->noticeData->setNoticeSticky(Request::analyze('notice_sticky', 0, false, 1)); } } /** * @throws ValidationException */ private function checkCommon() { if (!$this->noticeData->getNoticeComponent()) { throw new ValidationException(__u('Es necesario un componente')); } if (!$this->noticeData->getNoticeType()) { throw new ValidationException(__u('Es necesario un tipo')); } if (!$this->noticeData->getNoticeDescription()) { throw new ValidationException(__u('Es necesaria una descripción')); } if (!$this->noticeData->getNoticeUserId() && !$this->noticeData->isNoticeOnlyAdmin() && !$this->noticeData->isNoticeSticky()) { throw new ValidationException(__u('Es necesario un destinatario')); } } /** * @return NoticeData */ public function getItemData() { return $this->noticeData; } }