/** * Return a {@link ComplexTableField} that shows * all Order instances that are current. * * "Current" means all Orders that don't have a * Status property of "Complete" or "Cancelled". * * @return ComplexTableField */ function getReportField() { // Get the fields used for the table columns $fields = Order::$table_overview_fields; // Add some fields specific to this report $fields['Invoice'] = ''; $fields['Print'] = ''; $table = new TableListField('Orders', 'Order', $fields); // Customise the SQL query for Order, because we don't want it querying // all the fields. Invoice and Printed are dummy fields that just have some // text in them, which would be automatically queried if we didn't specify // a custom query. $query = singleton('Order')->buildSQL("\"Order\".\"Status\" NOT IN ('Complete', 'Cancelled')", '"Order"."Created" DESC'); $query->groupby[] = '"Order"."Created"'; $table->setCustomQuery($query); // Set the links to the Invoice and Print fields allowing a user to view // another template for viewing an Order instance $table->setFieldFormatting(array('Invoice' => '<a href=\\"OrderReport_Popup/invoice/$ID\\">Invoice</a>', 'Print' => '<a target=\\"_blank\\" href=\\"OrderReport_Popup/index/$ID?print=1\\">Print</a>')); $table->setFieldCasting(array('Created' => 'Date', 'Total' => 'Currency->Nice')); $table->setPermissions(array('edit', 'show', 'export', 'delete')); return $table; }
/** * Return a field, such as a {@link ComplexTableField} that is * used to show and manipulate data relating to this report. * * Generally, you should override {@link columns()} and {@link records()} to make your report, * but if they aren't sufficiently flexible, then you can override this method. * * @return FormField subclass */ function getReportField() { $columnTitles = array(); $fieldFormatting = array(); $csvFieldFormatting = array(); $fieldCasting = array(); // Parse the column information foreach($this->columns() as $source => $info) { if(is_string($info)) $info = array('title' => $info); if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting']; if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting']; if(isset($info['casting'])) $fieldCasting[$source] = $info['casting']; $columnTitles[$source] = isset($info['title']) ? $info['title'] : $source; } // To do: implement pagination $query = $this->sourceQuery($_REQUEST); $tlf = new TableListField('ReportContent', $this->dataClass(), $columnTitles); $tlf->setCustomQuery($query); $tlf->setShowPagination(true); $tlf->setPageSize(50); $tlf->setPermissions(array('export', 'print')); // Hack to figure out if we are printing if (isset($_REQUEST['url']) && array_pop(explode('/', $_REQUEST['url'])) == 'printall') { $tlf->setTemplate('SSReportTableField'); } if($fieldFormatting) $tlf->setFieldFormatting($fieldFormatting); if($csvFieldFormatting) $tlf->setCSVFieldFormatting($csvFieldFormatting); if($fieldCasting) $tlf->setFieldCasting($fieldCasting); return $tlf; }
function getReferrerTableListField() { $tf = new TableListField( 'Referrers', 'Referrer', array( 'URL' => 'URL', 'IsExternal' => 'External?', 'ReferrerCount' => 'Count' ) ); $tf->setShowPagination(true); $tf->setFieldFormatting(array( 'URL' => '<a href=\"$URL\">$URL</a>' )); $tf->setFieldCasting(array( 'IsExternal' => 'Boolean->Nice' )); $tf->setPermissions(array( 'show','export' )); $query = $this->getComponentsQuery( 'Referrers', null, // filter 'ReferrerCount DESC' // sort ); $query->groupby('`Referrer`.`URL`'); $query->select[] = 'COUNT(*) AS ReferrerCount'; $tf->setCustomQuery($query); return $tf; }