public function execute($request)
 {
     $reportId = $request->getParameter("reportId");
     $reportGeneratorService = new ReportGeneratorService();
     $runtimeFilterFieldWidgetNamesAndLabelsList = $reportGeneratorService->getRuntimeFilterFieldWidgetNamesAndLabels($reportId);
     $this->reportName = $reportGeneratorService->getReportName($reportId);
     $this->runtimeFilterFieldWidgetNamesAndLabelsList = $runtimeFilterFieldWidgetNamesAndLabelsList;
     $selectedRuntimeFilterFieldList = $reportGeneratorService->getSelectedRuntimeFilterFields($reportId);
     $ohrmFormGenerator = new ohrmFormGenerator();
     $this->reportForm = $ohrmFormGenerator->generateForm($runtimeFilterFieldWidgetNamesAndLabelsList);
     if ($request->isMethod('post')) {
         $this->reportForm->bind($request->getParameter($this->reportForm->getName()));
         if ($this->reportForm->isValid()) {
             $formValues = $this->reportForm->getValues();
             $reportableService = new ReportableService();
             $selectedFilterFieldList = $reportableService->getSelectedFilterFields($reportId, true);
             $runtimeWhereClause = $reportGeneratorService->generateWhereClauseConditionArray($selectedFilterFieldList, $formValues);
             $staticColumns = null;
             if ($this->hasStaticColumns()) {
                 $staticColumns = $this->setStaticColumns($formValues);
             }
             $sql = $reportGeneratorService->generateSql($reportId, $runtimeWhereClause, $staticColumns);
             $this->setReportCriteriaInfoInRequest($formValues);
             $this->getRequest()->setParameter('sql', $sql);
             $this->getRequest()->setParameter('reportId', $reportId);
             $this->setForward();
         }
     }
 }
 public function execute($request)
 {
     $adminMode = $this->getUser()->hasCredential(Auth::ADMIN_ROLE);
     if (!$adminMode) {
         return $this->renderText("You are not allowed to view this page!");
     }
     $this->getReportGroupAndType($request);
     $pageNumber = 1;
     $sortField = 'name';
     $sortOrder = 'ASC';
     $reportableService = new ReportableService();
     $searchString = null;
     $this->searchForm = new ViewPredefinedReportsSearchForm();
     $reportList = $reportableService->getAllPredefinedReports($this->reportType);
     $totalRecords = count($reportList);
     $this->reportJsonList = $this->searchForm->getReportListAsJson($reportList);
     if ($request->isMethod('post')) {
         if ($request->hasParameter("chkSelectRow")) {
             $reportIds = $request->getParameter("chkSelectRow");
             $results = $reportableService->deleteReports($reportIds);
             if ($results > 0) {
                 $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::DELETE_SUCCESS)));
                 $this->redirect('core/viewDefinedPredefinedReports');
                 return;
             }
         } else {
             $this->searchForm->bind($request->getParameter($this->searchForm->getName()));
             if ($this->searchForm->isValid()) {
                 $searchString = $this->searchForm->getValue("search");
             }
         }
     } else {
         // Get saved search params if not a new request.
         if ($request->hasParameter('pageNo') || $request->hasParameter('sortField') || $request->hasParameter('sortOrder')) {
             $this->_getSearchParams($searchString, $pageNumber, $sortField, $sortOrder);
             $pageNumber = $request->getParameter('pageNo', $pageNumber);
             $sortField = $request->getParameter('sortField', $sortField);
             $sortOrder = $request->getParameter('sortOrder', $sortOrder);
             $this->searchForm->setDefault('search', $searchString);
         }
     }
     $noOfRecords = sfConfig::get('app_items_per_page');
     $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $noOfRecords : ($request->getParameter('pageNo', 1) - 1) * $noOfRecords;
     if ($searchString != null) {
         $reports = $reportableService->getPredefinedReportsByPartName($this->reportType, $searchString, $noOfRecords, $offset, $sortField, $sortOrder);
         $totalRecords = $reportableService->getPredefinedReportCountByPartName($this->reportType, $searchString);
     } else {
         $reports = $reportableService->getPredefinedReports($this->reportType, $noOfRecords, $offset, $sortField, $sortOrder);
     }
     $this->_saveSearchParams($searchString, $pageNumber, $sortField, $sortOrder);
     $this->_setListComponent($reports, $noOfRecords, $pageNumber, $totalRecords);
     $this->parmetersForListComponent = array();
     list($this->messageType, $this->message) = $this->getUser()->getFlash('templateMessage');
 }
 public function execute($request)
 {
     $this->setInitialActionDetails($request);
     $reportId = $request->getParameter("reportId");
     $backRequest = $request->getParameter("backRequest");
     $reportableGeneratorService = new ReportGeneratorService();
     $sql = $request->getParameter("sql");
     $reportableService = new ReportableService();
     $this->report = $reportableService->getReport($reportId);
     if (empty($this->report)) {
         return $this->renderText(__('Invalid Report Specified'));
     }
     $useFilterField = $this->report->getUseFilterField();
     if (!$useFilterField) {
         $this->setCriteriaForm();
         if ($request->isMethod('post')) {
             $this->form->bind($request->getParameter($this->form->getName()));
             if ($this->form->isValid()) {
                 $reportGeneratorService = new ReportGeneratorService();
                 $formValues = $this->form->getValues();
                 $this->setReportCriteriaInfoInRequest($formValues);
                 $sql = $reportGeneratorService->generateSqlForNotUseFilterFieldReports($reportId, $formValues);
             }
         }
     } else {
         if ($request->isMethod("get")) {
             $reportGeneratorService = new ReportGeneratorService();
             //                $selectedRuntimeFilterFieldList = $reportGeneratorService->getSelectedRuntimeFilterFields($reportId);
             $selectedFilterFieldList = $reportableService->getSelectedFilterFields($reportId, false);
             $values = $this->setValues();
             //                $linkedFilterFieldIdsAndFormValues = $reportGeneratorService->linkFilterFieldIdsToFormValues($selectedRuntimeFilterFieldList, $values);
             //                $runtimeWhereClauseConditionArray = $reportGeneratorService->generateWhereClauseConditionArray($linkedFilterFieldIdsAndFormValues);
             $runtimeWhereClauseConditionArray = $reportGeneratorService->generateWhereClauseConditionArray($selectedFilterFieldList, $values);
             $sql = $reportGeneratorService->generateSql($reportId, $runtimeWhereClauseConditionArray);
         }
     }
     $paramArray = array();
     if ($reportId == 1) {
         if (!isset($backRequest)) {
             $this->getUser()->setAttribute("reportCriteriaSql", $sql);
             $this->getUser()->setAttribute("parametersForListComponent", $this->setParametersForListComponent());
         }
         if (isset($backRequest) && $this->getUser()->hasAttribute("reportCriteriaSql")) {
             $sql = $this->getUser()->getAttribute("reportCriteriaSql");
             $paramArray = $this->getUser()->getAttribute("parametersForListComponent");
         }
     }
     $params = !empty($paramArray) ? $paramArray : $this->setParametersForListComponent();
     $rawDataSet = $reportableGeneratorService->generateReportDataSet($reportId, $sql);
     $dataSet = self::escapeData($rawDataSet);
     $headerGroups = $reportableGeneratorService->getHeaderGroups($reportId);
     $this->setConfigurationFactory();
     $configurationFactory = $this->getConfFactory();
     $configurationFactory->setHeaderGroups($headerGroups);
     if ($reportId == 3) {
         if (empty($dataSet[0]['employeeName']) && $dataSet[0]['totalduration'] == 0) {
             $dataSet = null;
         }
     }
     ohrmListComponent::setConfigurationFactory($configurationFactory);
     $this->setListHeaderPartial();
     ohrmListComponent::setListData($dataSet);
     $this->parmetersForListComponent = $params;
     $this->initilizeDataRetriever($configurationFactory, $reportableGeneratorService, 'generateReportDataSet', array($reportId, $sql));
 }
 public function execute($request)
 {
     /* For highlighting corresponding menu item 
      * TODO: Currently menu item is hard-coded since this action is only used by PIM Reports
      */
     $request->setParameter('initialActionName', 'viewDefinedPredefinedReports');
     $this->reportPermissions = $this->getDataGroupPermissions('pim_reports');
     $this->getReportGroupAndType($request);
     $reportGeneratorService = new ReportGeneratorService();
     $reportableService = new ReportableService();
     $displayFieldGroups = $reportGeneratorService->getGroupedDisplayFieldsForReportGroup($this->reportGroup);
     $filterWidgets = $reportableService->getFilterFieldsForReportGroup($this->reportGroup);
     $reportId = $request->getParameter('reportId');
     $this->reportId = $reportId;
     if (!empty($reportId)) {
         $report = $reportableService->getReport($reportId);
         if (empty($report)) {
             $this->getUser()->setFlash('templateMessage', array('warning', __('Invalid Report Specified')));
             $this->redirect('core/viewDefinedPredefinedReports');
         }
         $reportName = $reportGeneratorService->getReportName($reportId);
     }
     if ($this->reportPermissions->canRead()) {
         $ohrmFormGenerator = new ohrmFormGenerator();
         $this->form = $ohrmFormGenerator->generatePredefinedForm($filterWidgets, $displayFieldGroups, $reportId, $reportName);
         $this->form->requiredFilterWidgets = $reportableService->getRequiredFilterFieldsForReportGroup($this->reportGroup);
     }
     if ($request->isMethod('post')) {
         if ($this->reportPermissions->canCreate() || $this->reportPermissions->canUpdate()) {
             $this->form->bind($request->getParameter($this->form->getName()));
             $selectedDisplayFieldGroups = $request->getParameter('display_groups');
             $selectedDisplayFields = $request->getParameter('display_fields');
             $this->form->selectedDisplayFieldGroups = $selectedDisplayFieldGroups;
             $this->form->selectedDisplayFields = $selectedDisplayFields;
             if ($this->form->isValid()) {
                 $reportId = $this->form->getValue('report_id');
                 $reportName = $this->form->getValue('report_name');
                 $selectedFilterValues = $this->form->getSelectedFilterValues();
                 if (empty($reportId) && !$this->reportPermissions->canCreate() || !empty($reportId) && !$this->reportPermissions->canUpdate()) {
                     $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
                 }
                 // If report_id not available, create report
                 if (empty($reportId)) {
                     $report = $reportableService->saveReport($reportName, $this->reportGroup, true, $this->reportType);
                     $reportId = $report->getReportId();
                 } else {
                     $report = $reportableService->getReport($reportId);
                     // update report name if required
                     if ($reportName != $report->getName()) {
                         $reportableService->updateReportName($reportId, $reportName);
                     }
                 }
                 // save selected values.
                 $reportGeneratorService->saveSelectedDisplayFieldGroups($selectedDisplayFieldGroups, $reportId);
                 $reportGeneratorService->saveSelectedDisplayFields($selectedDisplayFields, $reportId);
                 $reportGeneratorService->saveSelectedFilterFields($selectedFilterValues, $reportId, 'Predefined');
                 $this->getUser()->setFlash('success', __(TopLevelMessages::SAVE_SUCCESS));
                 $this->redirect('core/viewDefinedPredefinedReports');
                 return;
             }
         }
     } else {
         if (empty($this->reportId) && !$this->reportPermissions->canCreate() || !empty($this->reportId) && !$this->reportPermissions->canUpdate()) {
             $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
         }
         // Get filters, display field groups and display fields for report
         if (!empty($reportId)) {
             $selectedDisplayFieldGroups = $reportableService->getSelectedDisplayFieldGroups($reportId);
             $selectedDisplayFields = $reportableService->getSelectedDisplayFields($reportId);
             $selectedFilterFields = $reportableService->getSelectedFilterFieldNames($reportId, "Predefined");
             $this->form->updateSelectedDisplayFieldGroups($selectedDisplayFieldGroups);
             $this->form->updateSelectedDisplayFields($selectedDisplayFields);
             $this->form->updateSelectedFilterFields($selectedFilterFields);
         }
     }
 }
 public function execute($request)
 {
     $adminMode = $this->getUser()->hasCredential(Auth::ADMIN_ROLE);
     if (!$adminMode) {
         return $this->renderText("You are not allowed to view this page!");
     }
     $this->getReportGroupAndType($request);
     $reportGeneratorService = new ReportGeneratorService();
     $reportableService = new ReportableService();
     $displayFieldGroups = $reportGeneratorService->getGroupedDisplayFieldsForReportGroup($this->reportGroup);
     $filterWidgets = $reportableService->getFilterFieldsForReportGroup($this->reportGroup);
     $reportId = $request->getParameter('reportId');
     $reportName;
     if (!empty($reportId)) {
         $report = $reportableService->getReport($reportId);
         if (empty($report)) {
             $this->getUser()->setFlash('templateMessage', array('warning', __('Invalid Report Specified')));
             $this->redirect('core/viewDefinedPredefinedReports');
         }
         $reportName = $reportGeneratorService->getReportName($reportId);
     }
     $ohrmFormGenerator = new ohrmFormGenerator();
     $this->form = $ohrmFormGenerator->generatePredefinedForm($filterWidgets, $displayFieldGroups, $reportId, $reportName);
     $this->form->requiredFilterWidgets = $reportableService->getRequiredFilterFieldsForReportGroup($this->reportGroup);
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()));
         $selectedDisplayFieldGroups = $request->getParameter('display_groups');
         $selectedDisplayFields = $request->getParameter('display_fields');
         $this->form->selectedDisplayFieldGroups = $selectedDisplayFieldGroups;
         $this->form->selectedDisplayFields = $selectedDisplayFields;
         if ($this->form->isValid()) {
             $reportId = $this->form->getValue('report_id');
             $reportName = $this->form->getValue('report_name');
             $selectedFilterValues = $this->form->getSelectedFilterValues();
             // If report_id not available, create report
             if (empty($reportId)) {
                 $report = $reportableService->saveReport($reportName, $this->reportGroup, true, $this->reportType);
                 $reportId = $report->getReportId();
             } else {
                 $report = $reportableService->getReport($reportId);
                 // update report name if required
                 if ($reportName != $report->getName()) {
                     $reportableService->updateReportName($reportId, $reportName);
                 }
             }
             // save selected values.
             $reportGeneratorService->saveSelectedDisplayFieldGroups($selectedDisplayFieldGroups, $reportId);
             $reportGeneratorService->saveSelectedDisplayFields($selectedDisplayFields, $reportId);
             $reportGeneratorService->saveSelectedFilterFields($selectedFilterValues, $reportId, 'Predefined');
             $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::SAVE_SUCCESS)));
             $this->redirect('core/viewDefinedPredefinedReports');
             return;
         }
     } else {
         // Get filters, display field groups and display fields for report
         if (!empty($reportId)) {
             $selectedDisplayFieldGroups = $reportableService->getSelectedDisplayFieldGroups($reportId);
             $selectedDisplayFields = $reportableService->getSelectedDisplayFields($reportId);
             $selectedFilterFields = $reportableService->getSelectedFilterFieldNames($reportId, "Predefined");
             $this->form->updateSelectedDisplayFieldGroups($selectedDisplayFieldGroups);
             $this->form->updateSelectedDisplayFields($selectedDisplayFields);
             $this->form->updateSelectedFilterFields($selectedFilterFields);
         }
     }
 }