public function testSanitizeFiltersData() { //test specifically for date/dateTime conversion from local to db format. $filtersData = array(); $filtersData[0] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/2012'); $filtersData[1] = array('attributeIndexOrDerivedType' => 'dateTime', 'value' => '2/25/2012'); $filtersData[2] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/2012', 'secondValue' => '2/28/2012'); $sanitizedFilterData = DataToReportUtil::sanitizeFiltersData('ReportsTestModule', Report::TYPE_ROWS_AND_COLUMNS, $filtersData); $this->assertEquals('2012-02-24', $sanitizedFilterData[0]['value']); $this->assertEquals('2012-02-25', $sanitizedFilterData[1]['value']); $this->assertEquals('2012-02-24', $sanitizedFilterData[2]['value']); $this->assertEquals('2012-02-28', $sanitizedFilterData[2]['secondValue']); }
/** * Override to handle report filters * @param SavedCalendar | ModelForm $model * @param string $postVariableName * @throws NotSupportedException(); */ protected function attemptToValidateAjaxFromPost($model, $postVariableName) { if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form') { $postData = PostUtil::getData(); $readyToUsePostData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($_POST[$postVariableName]); $sanitizedPostdata = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $readyToUsePostData); $sanitizedOwnerPostData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($sanitizedPostdata, 'owner'); $sanitizedPostDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($sanitizedPostdata, 'owner'); $model->setAttributes($sanitizedPostDataWithoutOwner); if ($model->validate()) { $modelToStringValue = strval($model); if ($sanitizedOwnerPostData != null) { $model->setAttributes($sanitizedOwnerPostData); } if ($model instanceof OwnedSecurableItem) { $model->validate(array('owner')); } } $wizardFormClassName = ReportToWizardFormAdapter::getFormClassNameByType(Report::TYPE_ROWS_AND_COLUMNS); if (!isset($postData[$wizardFormClassName])) { throw new NotSupportedException(); } $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($model); DataToReportUtil::resolveFiltersStructure($postData[$wizardFormClassName], $report); DataToReportUtil::resolveFilters($postData[$wizardFormClassName], $report); //This would do the filter and filter structure validation $reportToWizardFormAdapter = new ReportToWizardFormAdapter($report); $reportForm = $reportToWizardFormAdapter->makeFormByType(); $postData['validationScenario'] = $wizardFormClassName::FILTERS_VALIDATION_SCENARIO; $filtersErrorData = ReportUtil::validateReportWizardForm($postData, $reportForm); $errorData = ZurmoActiveForm::makeErrorsDataAndResolveForOwnedModelAttributes($model); $errorData = array_merge($errorData, $filtersErrorData); echo CJSON::encode($errorData); Yii::app()->end(0, false); } }
protected function resolveSavedReportAndReportByPostData(array $postData, &$savedReport, &$report, $type, $id = null, $isBeingCopied = false) { if ($id == null) { $this->resolveCanCurrentUserAccessReports(); $savedReport = new SavedReport(); $report = new Report(); $report->setType($type); } elseif ($isBeingCopied) { $savedReport = new SavedReport(); $oldReport = SavedReport::getById(intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($oldReport); SavedReportCopyModelUtil::copy($oldReport, $savedReport); $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport); } else { $savedReport = SavedReport::getById(intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($savedReport); $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport); } DataToReportUtil::resolveReportByWizardPostData($report, $postData, ReportToWizardFormAdapter::getFormClassNameByType($type)); }
/** * Populate filters data in model. * * @param SavedCalendar $model * @param array $data */ public static function populateFiltersDataInModel(SavedCalendar $model, $data) { $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($model); DataToReportUtil::resolveFiltersStructure($data, $report); DataToReportUtil::resolveFilters($data, $report); if (count($filtersData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_FILTERS)) > 0) { $sanitizedFiltersData = DataToReportUtil::sanitizeFiltersData($report->getModuleClassName(), $report->getType(), $filtersData); $unserializedData = array(ComponentForReportForm::TYPE_FILTERS => $sanitizedFiltersData, 'filtersStructure' => $report->getFiltersStructure()); $model->serializedData = serialize($unserializedData); } else { $model->serializedData = null; } }