Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • ReportAdmin
  • SS_Report
  • SS_ReportWrapper
  1 <?php
  2 /**
  3  * Reports section of the CMS.
  4  * 
  5  * All reports that should show in the ReportAdmin section
  6  * of the CMS need to subclass {@link SS_Report}, and implement
  7  * the appropriate methods and variables that are required.
  8  * 
  9  * @see SS_Report
 10  * 
 11  * @package cms
 12  * @subpackage reports
 13  */
 14 class ReportAdmin extends LeftAndMain {
 15     
 16     static $url_segment = 'reports';
 17     
 18     static $url_rule = '/$Action/$ID';
 19     
 20     static $menu_title = 'Reports'; 
 21     
 22     static $template_path = null; // defaults to (project)/templates/email
 23     
 24     public function init() {
 25         parent::init();
 26         
 27         Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_left.js');
 28         Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_right.js');
 29 
 30         Requirements::css(CMS_DIR . '/css/ReportAdmin.css');        
 31         
 32         // Set custom options for TinyMCE specific to ReportAdmin
 33         HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
 34         HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
 35         
 36         // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
 37         Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
 38     }
 39     
 40     /**
 41      * Does the parent permission checks, but also
 42      * makes sure that instantiatable subclasses of
 43      * {@link Report} exist. By default, the CMS doesn't
 44      * include any Reports, so there's no point in showing
 45      * 
 46      * @param Member $member
 47      * @return boolean
 48      */
 49     function canView($member = null) {
 50         if(!$member && $member !== FALSE) $member = Member::currentUser();
 51         
 52         if(!parent::canView($member)) return false;
 53         
 54         $hasViewableSubclasses = false;
 55         foreach($this->Reports() as $report) {
 56             if($report->canView($member)) return true;
 57         }
 58         
 59         return false;
 60     }
 61     
 62     /**
 63      * Return a DataObjectSet of SS_Report subclasses
 64      * that are available for use.
 65      *
 66      * @return DataObjectSet
 67      */
 68     public function Reports() {
 69         $output = new DataObjectSet();
 70         foreach(SS_Report::get_reports('ReportAdmin') as $report) {
 71             if($report->canView()) $output->push($report);
 72         }
 73         return $output;
 74     }
 75     
 76     /**
 77      * Show a report based on the URL query string.
 78      *
 79      * @param SS_HTTPRequest $request The HTTP request object
 80      */
 81     public function show($request) {
 82         $params = $request->allParams();
 83         
 84         return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));   
 85     }
 86 
 87     /**
 88      * @TODO What does this do?
 89      *
 90      * @param unknown_type $params
 91      * @param unknown_type $editForm
 92      * @return unknown
 93      */
 94     protected function showWithEditForm($params, $editForm) {
 95         if(isset($params['ID'])) Session::set('currentReport', $params['ID']);
 96         if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']);
 97         
 98         if(Director::is_ajax()) {
 99             SSViewer::setOption('rewriteHashlinks', false);
100             
101             $result = $this->customise(array(
102                 'EditForm' => $editForm
103             ))->renderWith($this->getTemplatesWithSuffix('_right'));
104                         
105             return $this->getLastFormIn($result);
106         }
107         
108         return array();
109     }
110     
111     /**
112      * For the current report that the user is viewing,
113      * return a Form instance with the fields for that
114      * report.
115      *
116      * @return Form
117      */
118     public function EditForm() {
119         // Return the report if the ID is sent by request, or we're specifically asking for the edit form
120         $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
121         
122         if($id) {
123             foreach($this->Reports() as $report) {
124                 if($id == $report->ID()) return $this->reportEditFormFor($id);
125             }
126         }
127         return false;
128     }
129     
130     /**
131      * Get the current report
132      *
133      * @return SS_Report
134      */
135     public function CurrentReport() {
136         $id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
137         
138         if($id) {
139             foreach($this->Reports() as $report) {
140                 if($id == $report->ID()) return $report;
141             }
142         }
143         return false;
144     }
145     
146     /**
147      * Return a Form instance with fields for the
148      * particular report currently viewed.
149      * 
150      * @TODO Dealing with multiple data types for the
151      * $id parameter is confusing. Ideally, it should
152      * deal with only one.
153      *
154      * @param id|string $id The ID of the report, or class name
155      * @return Form
156      */
157     public function reportEditFormFor($id) {
158         $page = false;
159         $fields = new FieldSet();
160         $actions = new FieldSet();
161         
162         $reports = SS_Report::get_reports('ReportAdmin');
163         $obj = $reports[$id];
164 
165         if($obj) $fields = $obj->getCMSFields();
166         if($obj) $actions = $obj->getCMSActions();
167         
168         $idField = new HiddenField('ID');
169         $idField->setValue($id);
170         $fields->push($idField);
171         
172         $form = new Form($this, 'EditForm', $fields, $actions);
173 
174         $form->loadDataFrom($_REQUEST);
175 
176         // Include search criteria in the form action so that pagination works
177         $filteredCriteria = array_merge($_GET, $_POST);
178         foreach(array('ID','url','ajax','ctf','update','action_updatereport','SecurityID') as $notAParam) {
179             unset($filteredCriteria[$notAParam]);
180         }
181 
182         $formLink = $this->Link() . '/EditForm';
183         if($filteredCriteria) $formLink .= '?' . http_build_query($filteredCriteria);
184         $form->setFormAction($formLink);
185         $form->setTemplate('ReportAdminForm');
186         
187         return $form;
188     }
189     
190     /**
191      * Determine if we have reports and need
192      * to display the "Reports" main menu item
193      * in the CMS.
194      * 
195      * The test for an existance of a report
196      * is done by checking for a subclass of
197      * "SS_Report" that exists.
198      *
199      * @return boolean
200      */
201     public static function has_reports() {
202         return sizeof(SS_Report::get_reports('ReportAdmin')) > 0;
203     }
204     
205     public function updatereport() {
206         FormResponse::load_form($this->EditForm()->forTemplate());
207         return FormResponse::respond();
208     }
209 }
210 
211 
212 
213 
214 
215 ?>
216 
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0