/**
  * @see sfValidatorBase
  */
 protected function doClean($value)
 {
     $from = $value["from"];
     $to = $value["to"];
     $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
     $datepickerDateFormat = get_datepicker_date_format($inputDatePattern);
     if ($from != $datepickerDateFormat && $to != $datepickerDateFormat) {
         try {
             $value["from"] = parent::doClean($value["from"]);
         } catch (Exception $exc) {
             try {
                 $value["to"] = parent::doClean($value["to"]);
             } catch (Exception $exc) {
                 $this->setMessage('invalid', 'Insert valid "from" and "to" date');
                 $this->setMessage("bad_format", "From date and To date values do not match the date format " . $datepickerDateFormat);
                 throw $exc;
             }
             $this->setMessage('invalid', 'Insert a valid "from" date');
             throw $exc;
         }
         try {
             $value["to"] = parent::doClean($value["to"]);
         } catch (Exception $exc) {
             $this->setMessage('invalid', 'Insert a valid "to" date');
             throw $exc;
         }
     } else {
         if ($from == $datepickerDateFormat && $to != $datepickerDateFormat) {
             if ($to != "") {
                 $value["to"] = parent::doClean($value["to"]);
                 $this->setMessage('invalid', 'Insert a valid "to" date');
                 $this->setMessage("bad_format", "To date value does not match the date format " . $datepickerDateFormat);
             }
         } else {
             if ($from != $datepickerDateFormat && $to == $datepickerDateFormat) {
                 if ($from != "") {
                     $value["from"] = parent::doClean($value["from"]);
                     $this->setMessage('invalid', 'Insert a valid "from" date');
                     $this->setMessage("bad_format", "From date value does not match the date format " . $datepickerDateFormat);
                 }
             } else {
                 if ($from == $datepickerDateFormat && $to == $datepickerDateFormat) {
                     return $value;
                 }
             }
         }
     }
     if ($value["from"] != $datepickerDateFormat && $value["to"] != $datepickerDateFormat && $value["from"] != "" && $value["to"] != "") {
         $this->setMessage('invalid', 'From date should be before to date.');
         $v = new ohrmValidatorSchemaDateRange("project_date_range", sfValidatorSchemaCompare::LESS_THAN_EQUAL, "project_date_range", array('throw_global_error' => true), array('invalid' => $this->getMessage('invalid')));
         $v->clean($value);
     }
     return $value;
 }
Example #2
0
 protected function getReviewSearchClues($request, $suffix = '')
 {
     $clues = array();
     $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat();
     $dateValidator = new ohrmDateValidator(array('date_format' => $inputDatePattern, 'required' => false), array('invalid' => 'Date format should be ' . $inputDatePattern));
     if ($request instanceof sfWebRequest) {
         $clues['from'] = $dateValidator->clean($request->getParameter('txtPeriodFromDate' . $suffix));
         $clues['to'] = $dateValidator->clean($request->getParameter('txtPeriodToDate' . $suffix));
         $clues['due'] = $dateValidator->clean($request->getParameter('txtDueDate' . $suffix));
         $clues['jobCode'] = $request->getParameter('txtJobTitleCode' . $suffix);
         $clues['divisionId'] = $request->getParameter('txtSubDivisionId' . $suffix);
         $clues['empName'] = $request->getParameter('txtEmpName' . $suffix);
         $clues['empId'] = empty($clues['empName']) ? 0 : $request->getParameter('hdnEmpId' . $suffix);
         $clues['reviewerName'] = $request->getParameter('txtReviewerName' . $suffix);
         $clues['reviewerId'] = empty($clues['reviewerName']) ? 0 : $request->getParameter('hdnReviewerId' . $suffix);
         $clues['pageNo'] = $request->getParameter('hdnPageNo' . $suffix);
     } elseif ($request instanceof PerformanceReview) {
         $clues['from'] = $request->getPeriodFrom();
         $clues['to'] = $request->getPeriodTo();
         $clues['due'] = $request->getDueDate();
         $clues['jobCode'] = $request->getJobTitleCode();
         $clues['divisionId'] = $request->getSubDivisionId();
         $clues['empName'] = $request->getEmployee()->getFirstName() . " " . $request->getEmployee()->getLastName();
         $clues['empId'] = $request->getEmployeeId();
         $clues['reviewerName'] = $request->getReviewer()->getFirstName() . " " . $request->getReviewer()->getLastName();
         $clues['reviewerId'] = $request->getReviewerId();
         $clues['id'] = $request->getId();
     }
     return $clues;
 }