Inheritance: implements IReportDefinition
Esempio n. 1
0
 /**
  * Merge results of multiple subreports. Set of sub reports result is given.
  * When merging this method uses join conditions defined in report definition, 
  * @param string[][] $resultsSetArray
  * @param ReportDefinition $reportDefinitionObject
  * @return string[]
  * @throws ReportException
  */
 private function mergeWithMultipleJoins($resultsSetArray, $reportDefinitionObject)
 {
     $result = array();
     $reportDefinitionObject->resetJoin();
     $join = $reportDefinitionObject->getCurrentJoin();
     if (is_null($join) || empty($join)) {
         throw new ReportException("Invalid XML Definition!!! \n                    ( The report should contain at least one join element, \n                    if there are more than one sub reports defined )");
     }
     $foundAJoinWithoutAsAttribute = false;
     $numOfJoins = $reportDefinitionObject->getJoinCount();
     for ($i = 0; $i < $numOfJoins; $i++) {
         $joinAs = $reportDefinitionObject->getJoinAs($join);
         if ($foundAJoinWithoutAsAttribute) {
             throw new ReportException("Invalid 'join' definition! refer to ReadMe file..");
         }
         if ($joinAs == "") {
             $foundAJoinWithoutAsAttribute = true;
         }
         $result = $this->mergeResultsUsingJoinBy($resultsSetArray, $reportDefinitionObject, $join);
         $resultsSetArray[$joinAs] = $result;
         $join = $reportDefinitionObject->getNextJoin();
     }
     $reportDefinitionObject->resetJoin();
     return $result;
 }
 public function testGetsRowDataForResourcTypeCustomAttributes()
 {
     $rows = array(array(ColumnNames::ACCESSORY_NAME => 'an', ColumnNames::ACCESSORY_ID => 1, ColumnNames::RESOURCE_TYPE_ATTRIBUTE_LIST => '1=1!sep!2=!sep!3=3'));
     $report = new CustomReport($rows, $this->attributeRepository);
     $definition = new ReportDefinition($report, null);
     /** @var $row ReportCell[] */
     $row = $definition->GetRow($rows[0]);
     $this->assertEquals(3, count($row));
     $this->assertEquals('an', $row[0]->Value());
     $this->assertEquals('1', $row[1]->Value());
     $this->assertEquals(null, $row[2]->Value(), 'there is no 3rd attribute in the fake');
 }
Esempio n. 3
0
 public function view()
 {
     if (!$this->loadData()) {
         $this->dataError();
         sendBack();
     }
     $display_fields = array();
     $measure_fields = array();
     $aggregate_fields = array();
     $search_fields = array();
     $filter_fields = array();
     // get report model
     $report = $this->_uses[$this->modeltype];
     // unserialise the options from the db
     $options = unserialize($report->options);
     // overlay the defaults so we've got a full set of options
     $options = $this->expand_options($options, $report->tablename);
     // sort options by position
     $options = $this->sort_options($options);
     foreach ($options as $field => $field_options) {
         // ignore the filter field... it really isn't a field
         if (in_array($field, array('filter', 'search'))) {
             continue;
         }
         $position = $field_options['position'];
         // ignore fields that aren't meant to be displayed
         if ($field_options['normal_display_field'] !== 'false') {
             // we're always dealing with normal fields now
             $display_fields[$position] = $field;
             if ($field_options['normal_break_on'] == "true") {
                 $measure_fields[$position] = $field;
             }
             if (!empty($field_options['normal_method']) && $field_options['normal_method'] != 'dont_total') {
                 $aggregate_fields[$position] = $field_options['normal_method'] . '(' . $field . ') as ' . $field;
                 // if we're setting an aggregate field... this must not be a display field
                 unset($display_fields[$position]);
             }
         }
         // if the field is also a search field, add it to the search array
         if ($field_options['normal_enable_search'] === 'true') {
             $search_fields[$field] = $field;
         }
     }
     if (!empty($options['filter'])) {
         // loop through filter lines
         foreach (range(1, 3) as $number) {
             // filter line 1 will never have an operator
             if ($number == 1) {
                 $operator = '';
             } else {
                 $operator = $options['filter']['filter_' . $number . '_operator'] . ' ';
             }
             $field = $options['filter']['filter_' . $number . '_field'];
             $condition = $options['filter']['filter_' . $number . '_condition'];
             $value = $options['filter']['filter_' . $number . '_value'];
             // if we're dealing with a valid filter line...
             if (($number == 1 or !empty($operator)) and !empty($field) and !empty($value)) {
                 $filter_fields[$number] = $operator . $field . ' ' . $condition . ' ' . $value;
             }
         }
     }
     // output to smarty
     $this->view->set('display_fields', implode(',', $display_fields));
     $this->view->set('break_on_fields', implode(',', $measure_fields));
     $this->view->set('aggregate_fields', implode('<br />', $aggregate_fields));
     $this->view->set('search_fields', implode(',', $search_fields));
     $this->view->set('filter_fields', implode('<br />', $filter_fields));
     $rd = ReportDefinition::getDefinitionByid($report->report_definition);
     $report_definition_name = $rd->_data['name'];
     $this->view->set('report_definition', $report_definition_name);
     $hasreport = new HasReport();
     $report_list = $hasreport->getAssignedRoles($report->id);
     $this->view->set('roles', $report_list);
     // create sidebar
     $this->view->set('report', $report);
     $sidebar = new SidebarController($this->view);
     $sidebarlist = array();
     $sidebarlist['all'] = array('tag' => 'All Reports', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'));
     $sidebarlist['edit'] = array('tag' => 'Edit Report', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'edit', $report->idField => $report->{$report->idField}));
     if ($report->owner == EGS_USERNAME) {
         $sidebarlist['delete'] = array('tag' => 'Delete Report', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'delete', $report->idField => $report->{$report->idField}));
     }
     $sidebarlist['copy'] = array('tag' => 'Copy Report', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'copy', $report->idField => $report->{$report->idField}));
     $sidebarlist['run'] = array('tag' => 'Run Report', 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'run', $report->idField => $report->{$report->idField}));
     if ($report->owner == EGS_USERNAME) {
         if (empty($report_list)) {
             $tag = 'Publish Report';
         } else {
             $tag = 'Amend Report Roles';
         }
         $sidebarlist['publish'] = array('tag' => $tag, 'link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'publish_report', $report->idField => $report->{$report->idField}));
     }
     $sidebar->addList('Actions', $sidebarlist);
     $this->view->register('sidebar', $sidebar);
     $this->view->set('sidebar', $sidebar);
 }
Esempio n. 4
0
 public function build_custom_xsl($collection, $definition_name, $title, $col_headers, $col_widths, $options = array())
 {
     // $collection is not used: why do we need it?
     // get the XSL
     $xsl = ReportDefinition::getDefinition($definition_name)->definition;
     if (!empty($xsl)) {
         // define / generate the various xsl vars that are to be replaced
         $xslVars['REPORT_TITLE'] = $title;
         $column_definitions = '<fo:table-column column-width="proportional-column-width(%s)"/>';
         $column_headings = '<fo:table-cell padding="1mm" border-width="1pt" border-style="solid" text-align="%s" >' . "\r\n";
         $column_headings .= '    <fo:block >%s</fo:block>' . "\r\n";
         $column_headings .= '</fo:table-cell>';
         $row_cells = '<fo:table-cell padding="1mm" border-style="solid" border-width="1pt" >' . "\r\n";
         $row_cells .= '    <!-- check if we\'re dealing with a total row -->' . "\r\n";
         $row_cells .= '    <xsl:if test="%s/@negative_number=\'true\'">' . "\r\n";
         $row_cells .= '        <xsl:attribute name="color">red</xsl:attribute>' . "\r\n";
         $row_cells .= '    </xsl:if>' . "\r\n";
         $row_cells .= '    <xsl:if test="%s/@text-align=\'right\'">' . "\r\n";
         $row_cells .= '        <xsl:attribute name="text-align">right</xsl:attribute>' . "\r\n";
         $row_cells .= '    </xsl:if>' . "\r\n";
         $row_cells .= '    <fo:block>' . "\r\n";
         $row_cells .= '        <xsl:value-of select="%s"/>' . "\r\n";
         $row_cells .= '    </fo:block>' . "\r\n";
         $row_cells .= '</fo:table-cell>';
         $column_widths = array();
         // echo 'getMinColWidths '.microtime(TRUE).'<pre>'.print_r($collection->getMinColWidths($col_headers), true).'</pre>'.microtime(TRUE).'<br>';
         if (isset($this->_data['col_widths']) && !empty($this->_data['col_widths'])) {
             // parse the column widths into an array
             $column_widths = $this->parse_column_widths($this->_data['col_widths']);
             // echo 'parse_column_widths<pre>'.print_r($column_widths, true).'</pre><br>';
             // calculate an average width, just in case a column width isn't specified
             // an average of the specified ones should be fine
             $total_widths = 0;
             $average_width = 50;
             // failsafe
             foreach ($column_widths as $width) {
                 $total_widths += $width;
             }
             $failsafe_width = $total_widths / count($column_widths);
         } else {
             $failsafe_width = 50;
         }
         foreach ($col_headers as $key => $value) {
             if (isset($column_widths[$key])) {
                 $column_width = $column_widths[$key];
             } else {
                 $column_width = $failsafe_width;
             }
             $text_align = "left";
             if ($options[$key]['normal_enable_formatting'] == 'true' && isset($options[$key]['normal_justify'])) {
                 $text_align = $options[$key]['normal_justify'];
             }
             $xslVars['REPORT_COLUMN_DEFINITIONS'] .= sprintf($column_definitions, $column_width) . "\r\n";
             $xslVars['REPORT_COLUMN_HEADINGS'] .= sprintf($column_headings, $text_align, $value) . "\r\n";
             $xslVars['REPORT_ROW_CELLS'] .= sprintf($row_cells, $key, $key, $key) . "\r\n";
         }
         $xslVars['COLLECTION_NAME'] = $collection->getModelName();
         // process xsl
         $xsl = $this->process_xsl($xsl, $xslVars);
     } else {
         $xsl = FALSE;
     }
     return $xsl;
 }