/**
  * @return string
  */
 protected function renderFiltersContent($form)
 {
     assert('$form instanceof ZurmoActiveForm');
     $content = null;
     $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($this->model);
     $adapter = new ReportToWizardFormAdapter($report);
     $reportWizardForm = $adapter->makeRowsAndColumnsWizardForm();
     $filtersForReportWizardViewClassName = static::getFiltersForReportWizardViewClassName();
     $filtersForReportWizardView = new $filtersForReportWizardViewClassName($reportWizardForm, $form, false);
     $content .= $filtersForReportWizardView->render();
     $this->registerFiltersScripts();
     $this->registerModuleClassNameChangeScript();
     $this->registerFiltersCss();
     return $content;
 }
 /**
  * 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);
     }
 }
 /**
  * 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;
     }
 }
 /**
  * Makes report by saved calendar.
  * @param SavedCalendar $savedCalendar
  * @return Report
  */
 protected function makeReportBySavedCalendar(SavedCalendar $savedCalendar)
 {
     $moduleClassName = $savedCalendar->moduleClassName;
     $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($savedCalendar);
     $existingFilters = $report->getFilters();
     $existingFiltersCount = count($existingFilters);
     $newFiltersToAdd = array();
     $newStructureToAdd = null;
     $this->processFiltersAndStructureForMeetingsThatStartAndEndAfterRange($newFiltersToAdd, $newStructureToAdd, $existingFiltersCount, $savedCalendar, $report);
     $this->processFiltersAndStructureForMeetingsThatStartBeforeRange($newFiltersToAdd, $newStructureToAdd, $existingFiltersCount, $savedCalendar, $report);
     $this->processFiltersAndStructureForMeetingsThatEndAfterRange($newFiltersToAdd, $newStructureToAdd, $existingFiltersCount, $savedCalendar, $report);
     foreach ($newFiltersToAdd as $filter) {
         $report->addFilter($filter);
     }
     if ($report->getFiltersStructure() != null) {
         $report->setFiltersStructure($report->getFiltersStructure() . " AND ({$newStructureToAdd})");
     } else {
         $report->setFiltersStructure($newStructureToAdd);
     }
     $displayAttribute = new DisplayAttributeForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'id';
     $report->addDisplayAttribute($displayAttribute);
     return $report;
 }
 /**
  * @covers SavedCalendarToReportAdapter::makeReportBySavedCalendar
  */
 public function testMakeReportBySavedCalendar()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $savedCalendars = SavedCalendar::getAll();
     $savedCalendar = $savedCalendars[0];
     $savedCalendar->serializedData = 'a:2:{s:7:"Filters";a:1:{i:0;a:5:{s:17:"structurePosition";s:1:"1";s:27:"attributeIndexOrDerivedType";s:15:"createdDateTime";s:9:"valueType";s:5:"After";s:5:"value";s:10:"2014-01-18";s:18:"availableAtRunTime";s:1:"0";}}s:16:"filtersStructure";s:1:"1";}';
     $report = SavedCalendarToReportAdapter::makeReportBySavedCalendar($savedCalendars[0]);
     $this->assertEquals($report->getDescription(), $savedCalendars[0]->description);
     $this->assertEquals($report->getName(), $savedCalendars[0]->name);
     $this->assertEquals($report->getModuleClassName(), $savedCalendars[0]->moduleClassName);
     $this->assertEquals($report->getOwner(), $savedCalendars[0]->owner);
     $this->assertEquals($report->getType(), Report::TYPE_ROWS_AND_COLUMNS);
     $this->assertEquals($report->getFiltersStructure(), "1");
 }