Exemplo n.º 1
0
 public function __construct($params = null)
 {
     parent::__construct($params);
     //URL parameter specifies the report instance
     $this->report_shortname = $this->required_param('report');
     //convert shortname to report instance
     $this->report_instance = php_report::get_default_instance($this->report_shortname);
 }
Exemplo n.º 2
0
/**
 * Runs and exports, through email, the report instance specified by the
 * provided report schedule
 *
 * @param   stdClass  $report_schedule  The PHP report schedule containing the information
 *                                      about the specific report to be exported
 *
 * @return  boolean                     true on success, otherwise false
 */
function php_report_schedule_export_instance($report_schedule, $now = 0) {
    global $CFG, $USER;

    if ($now == 0) {
        $now = time();
    }

    $data = unserialize($report_schedule->config);

    // Create report to be emailed to recipient
    $shortname = $report_schedule->report;
    $format = $data['format'];
    // Initialize a temp path name
    $tmppath = '/temp';
    // Create a unique temporary filename to use for this schedule
    $filename = tempnam($CFG->dataroot.$tmppath, 'php_report_');

    $parameterdata = $data['parameters'];

    // Generate the report file
    $result = php_report::export_default_instance($shortname, $format, $filename, $parameterdata, $report_schedule->userid, php_report::EXECUTION_MODE_SCHEDULED);

    if (!$result) {
        //handle failure case
        unlink($filename);
        return false;
    }

    // Attach filename to an email - so get recipient...
    $recipients_array = explode(',',$data['recipients']);
    $from = get_string('noreplyname');
    $subject = get_string('email_subject','local_elisreports').$data['label'];
    $messagetext = html_to_text($data['message']);
    $messagehtml = $data['message'];
    $start = strlen($CFG->dataroot);
    $attachment = substr($filename,$start);
    $attachname = $report_schedule->report.$now.'.'.$data['format'];

    // $user->id & all other fields now required by Moodle 2.6+ email_to_user() API which also calls fullname($user)
    $user = new stdClass;
    $allfields = get_all_user_name_fields();
    foreach ($allfields as $field) {
        $user->$field = null;
    }
    $user->id = $USER->id; // let's just use this user as default (TBD)
    $user->mailformat = 1;

    // Attach the file to the recipients
    foreach ($recipients_array as $recipient) {
        $user->email = trim($recipient);
        email_to_user($user, $from, $subject, $messagetext, $messagehtml, $attachment, $attachname);
    }

    // Remove the file that was created for this report
    unlink($filename);

    return true;
}
 /**
  * This is where an icon report's data should be calculated and set in $this->data
  *
  * $this->data should contain an array for each icon, containing the display name,
  * the numerical value, and the path to the icon file
  */
 function calculate_data()
 {
     $this->data = $this->get_default_data();
     // Get extra icons... send list of filters but don't include exceptions - as we do need the filter list here
     $exceptions = $this->get_filter_exceptions();
     $rest_of_filters = array();
     foreach ($this->filter->_fields as $key => $value) {
         if (!in_array($key, $exceptions)) {
             $rest_of_filters[] = $key;
         }
     }
     // Pass the rest_of_filters array, but then also let the method know this is a special config filter
     $extra_icons = $this->filter->get_sql_filter('', $rest_of_filters, $this->allow_interactive_filters(), $this->allow_configured_filters(), '', true);
     foreach ($this->data as $key => $value) {
         //If key is in choices array and not in extra_icons
         if (array_key_exists($key, $this->checkboxes_filter->options['choices']) && !strpos($extra_icons, $key)) {
             // then we need to remove it from $this->data in fact...
             unset($this->data[$key]);
             continue;
         }
         //first step - try getting the item value directly
         $data_item = $this->get_data_item($key);
         if ($data_item !== FALSE) {
             $this->data[$key]->value = $data_item;
         } else {
             //backup plan - use SQL query to get the item value
             $use_filters = true;
             $sql = $this->get_data_item_sql($key, $use_filters);
             if ($sql !== FALSE) {
                 //parse SQL for a WHERE clause
                 $has_where_clause = php_report::sql_has_where_clause($sql);
                 $conditional_symbol = 'WHERE';
                 if ($has_where_clause) {
                     $conditional_symbol = 'AND';
                 }
                 // apply filters if applicable
                 if (!empty($this->filter) && !empty($use_filters)) {
                     // Include filter_exceptions here so that our config type filter is not included in the filters added to the final sql
                     $sql_filter = $this->filter->get_sql_filter('', $this->get_filter_exceptions($key), $this->allow_interactive_filters(), $this->allow_configured_filters());
                     if (!empty($sql_filter)) {
                         $sql .= " {$conditional_symbol} ({$sql_filter})";
                     }
                 }
                 //obtain field value
                 if ($field_data = get_field_sql($sql)) {
                     $this->data[$key]->value = $field_data;
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
/**
 * Runs and exports, through email, the report instance specified by the
 * provided report schedule
 *
 * @param   stdClass  $report_schedule  The PHP report schedule containing the information
 *                                      about the specific report to be exported
 *
 * @return  boolean                     true on success, otherwise false
 */
function php_report_schedule_export_instance($report_schedule, $now = 0)
{
    global $CFG;
    if ($now == 0) {
        $now = gmmktime();
        // time();
    }
    $data = unserialize($report_schedule->config);
    // Create report to be emailed to recipient
    $shortname = $report_schedule->report;
    $format = $data['format'];
    // Initialize a temp path name
    $tmppath = '/temp';
    // Create a unique temporary filename to use for this schedule
    $filename = tempnam($CFG->dataroot . $tmppath, 'php_report_');
    $parameterdata = $data['parameters'];
    // Generate the report file
    $result = php_report::export_default_instance($shortname, $format, $filename, $parameterdata, $report_schedule->userid, php_report::EXECUTION_MODE_SCHEDULED);
    if (!$result) {
        //handle failure case
        unlink($filename);
        return false;
    }
    // Attach filename to an email - so get recipient...
    $recipients_array = explode(',', $data['recipients']);
    $from = get_string('noreplyname');
    $subject = get_string('email_subject', 'block_php_report') . $data['label'];
    $messagetext = html_to_text($data['message']);
    $messagehtml = $data['message'];
    $start = strlen($CFG->dataroot);
    $attachment = substr($filename, $start);
    $attachname = $report_schedule->report . $now . '.' . $data['format'];
    // Attach the file to the recipients
    foreach ($recipients_array as $recipient) {
        $user = new stdClass();
        $user->email = $recipient;
        $user->mailformat = 1;
        email_to_user($user, $from, $subject, $messagetext, $messagehtml, $attachment, $attachname);
    }
    // Remove the file that was created for this report
    unlink($filename);
    return true;
}
Exemplo n.º 5
0
 /**
  * Constructor
  * @param  string   $name      the name of the filter instance
  * @param  string   $label     the label of the filter instance
  * @param  boolean  $advanced  advanced form element flag
  * @param  string   $field     user table filed name
  * @param  array    $options   select options
  */
 public function __construct($uniqueid, $alias, $name, $label, $advanced, $field, $options = array())
 {
     parent::generalized_filter_type($uniqueid, $alias, $name, $label, $advanced, !empty($options['help']) ? $options['help'] : array('simpleselect', $label, 'filters'));
     $this->_field = $field;
     if (!isset($options['report'])) {
         print_error('autocomplete_noreport', 'local_eliscore');
     }
     $this->_parent_report = $options['report'];
     $this->parent_report_instance = php_report::get_default_instance($options['report']);
     if (isset($options['ui']) && in_array($options['ui'], array('inline', 'popup'), true)) {
         $this->_ui = $options['ui'];
     }
     if (!empty($options['restriction_sql']) && is_string($options['restriction_sql'])) {
         $this->_restriction_sql = $options['restriction_sql'];
     }
     if (!empty($options['popup_title'])) {
         $this->_popup_title = $options['popup_title'];
     }
     if (isset($options['label_template'])) {
         $this->_label_template = $options['label_template'];
     } else {
         $this->_label_template = !empty($this->_fields[0]) ? $this->_fields[0] : '';
     }
     if (isset($options['selection_enabled']) && is_bool($options['selection_enabled'])) {
         $this->_selection_enabled = $options['selection_enabled'];
     }
     if (!empty($options['defaults']['id'])) {
         $this->_default_id = $options['defaults']['id'];
     }
     if (!empty($options['defaults']['label'])) {
         $this->_default_label = $options['defaults']['label'];
     }
     if (!empty($options['required'])) {
         $this->_required = $options['required'];
     }
     $this->_useid = $field == 'id';
     $this->load_options($options);
 }
Exemplo n.º 6
0
 /**
  * Takes a record and transform it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The current report record
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The reformatted record
  */
 function transform_record($record, $export_format)
 {
     if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
         $record->lastname = php_report::fullname($record);
         //unset($record->firstname);
     }
     return $record;
 }
Exemplo n.º 7
0
 function definition()
 {
     require_js_files();
     $mform =& $this->_form;
     $page = $this->_customdata;
     $workflow = $page->workflow;
     $mform->addElement('hidden', '_wfid', $workflow->id);
     $mform->setType('_wfid', PARAM_INT);
     $mform->addElement('hidden', '_step', scheduling_workflow::STEP_FORMAT);
     $mform->setType('_step', PARAM_TEXT);
     $mform->addElement('hidden', 'action', 'save');
     $mform->setType('action', PARAM_TEXT);
     $mform->addElement('html', '<h2>' . htmlspecialchars(get_string('format_description', 'local_elisreports')) . '</h2>');
     $radioarray = array();
     //obtain the actual report instance so we can check its export formats
     $data = unserialize($workflow->data);
     $report_shortname = $data['report'];
     $report_instance = php_report::get_default_instance($report_shortname, NULL, php_report::EXECUTION_MODE_SCHEDULED);
     //global list of all available export formats
     $allowable_export_formats = php_report::get_allowable_export_formats();
     //export formats supported by the report we are scheduling
     $export_formats = $report_instance->get_export_formats();
     //add an export option for each applicable format
     if ($report_instance->can_view_report()) {
         foreach ($allowable_export_formats as $allowable_export_format) {
             if (in_array($allowable_export_format, $export_formats)) {
                 $radioarray[] = $mform->createElement('radio', 'format', '', get_string($allowable_export_format, 'local_elisreports'), $allowable_export_format);
             }
         }
     }
     $mform->addGroup($radioarray, 'format', get_string('format'), '', false);
     $mform->addRule('format', get_string('required_field', 'local_elisreports', get_string('format')), 'required', null, 'client');
     $mform->setDefault('format', 'csv');
     workflowpage::add_navigation_buttons($mform, scheduling_workflow::STEP_PARAMETERS);
 }
Exemplo n.º 8
0
/**
 * Specifies the tree entries used to represent links to PHP reports
 *
 * @return  menuitem array  List of menu items to add (including report categories
 *                          but excluding the top-level report entry)
 */
function block_elisadmin_get_report_tree_items()
{
    global $CFG, $DB;
    // If the reports block is not installed, no entries will be displayed.
    if (file_exists($CFG->dirroot . '/local/elisreports/version.php') !== true) {
        return array();
    }
    //get the category-level links
    $items = block_elisadmin_get_report_category_items();
    //path to library file for scheduling classes
    $schedulelib_path = $CFG->dirroot . '/local/elisreports/lib/schedulelib.php';
    //check to make sure the required functionality is there
    //todo: remove this check when it's safe to do so
    if (file_exists($schedulelib_path)) {
        //reporting base class
        require_once $schedulelib_path;
        //schedule report entry
        //make sure we are using a "clean" page to check global permissions
        $test_permissions_page = new scheduling_page(array());
        //make sure we can access the report listing
        if ($test_permissions_page->can_do('list')) {
            //create a direct url to the list page
            $schedule_reports_page = new menuitempage('url_page', 'lib/menuitem.class.php', $CFG->wwwroot . '/local/elisreports/schedule.php?action=list');
            //convert to a menu item
            $css_class = block_elisadmin_get_item_css_class('schedulereports');
            $schedule_reports_item = new menuitem('schedule_reports', $schedule_reports_page, 'rept', get_string('schedule_reports', 'local_elisreports'), $css_class, '', FALSE, 'rept');
            //merge in with the current result
            $items = array_merge(array($schedule_reports_item), $items);
        }
    }
    //for storing the items bucketed by category
    $buckets = array();
    //look for all report instances
    if (file_exists($CFG->dirroot . '/local/elisreports/instances') && ($handle = opendir($CFG->dirroot . '/local/elisreports/instances'))) {
        while (FALSE !== ($report_shortname = readdir($handle))) {
            //grab a test instance of the report in question
            $default_instance = php_report::get_default_instance($report_shortname);
            //make sure the report shortname is valid
            if ($default_instance !== FALSE) {
                //make sure the current user can access this report
                if ($default_instance->is_available() && $default_instance->can_view_report()) {
                    //user-friendly report name
                    $displayname = $default_instance->get_display_name();
                    //add the item to the necessary bucket
                    $item_category = $default_instance->get_category();
                    if (!isset($buckets[$item_category])) {
                        $buckets[$item_category] = array();
                    }
                    //obtain the page specific to this report
                    $report_page_classpath = $CFG->dirroot . '/local/elisreports/lib/reportpage.class.php';
                    $report_page_params = array('report' => $report_shortname);
                    $page = new generic_menuitempage('report_page', $report_page_classpath, $report_page_params);
                    //retrieve the actual menuitem
                    $page_css_class = block_elisadmin_get_item_css_class('reportinstance');
                    $category_path = 'rept/' . $item_category;
                    $buckets[$item_category][$displayname] = new menuitem($report_shortname, $page, $item_category, $displayname, $page_css_class, '', FALSE, $category_path);
                }
            }
        }
    }
    //retrieve the items representing the reports themselves from the bucketed listings
    $report_instance_items = block_elisadmin_get_report_bucket_items($buckets);
    //merge the flat listings of category items and report instance items
    $items = array_merge($items, $report_instance_items);
    //return the flat listing
    return $items;
}
 /**
  * Takes a record and transforms it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The current report record
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The reformatted record
  */
 function transform_record($record, $export_format)
 {
     if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
         $user = new stdClass();
         $user->firstname = $record->firstname;
         $user->lastname = $record->r_student;
         $record->r_student = php_report::fullname($user);
     }
     if (empty($record->r_elements)) {
         $record->r_elements = '0';
         $record->r_percent = '0';
     } else {
         //$percentage = round($record->r_complete / $record->r_elements * 10000) / 100;
         $percentage = round($record->r_percent / $record->r_elements * 10000) / 100;
         $percentage = $percentage > 100 ? 100 : $percentage;
         $record->r_percent = $percentage;
     }
     if ($export_format != php_report::$EXPORT_FORMAT_CSV) {
         $record->r_percent .= get_string('percent_symbol', $this->lang_file);
     }
     if (empty($record->r_graded)) {
         $record->r_graded = '0';
     }
     if (empty($record->r_total_elements)) {
         $record->r_total_elements = '0';
     }
     $secs_in_hour = 3600;
     if (!empty($record->r_timespent)) {
         if ($record->r_timespent > 0 && $record->r_timespent < $secs_in_hour) {
             $timespent = 1;
             $record->r_timespent = $export_format == php_report::$EXPORT_FORMAT_HTML ? '&lt;1' : '1';
         } else {
             $timespent = floor($record->r_timespent / $secs_in_hour);
             $record->r_timespent = $timespent;
         }
     } else {
         $timespent = 0;
         $record->r_timespent = "0";
     }
     if ($export_format != php_report::$EXPORT_FORMAT_CSV) {
         $record->r_timespent .= ' ' . get_string($timespent == 1 ? 'hour' : 'hours', $this->lang_file);
     }
     // ELIS-4916: now using ELIS grade!
     if (!empty($record->elisgrade)) {
         $record->r_total_grade = pm_display_grade($record->elisgrade);
         if (is_numeric($record->r_total_grade) && $export_format != php_report::$EXPORT_FORMAT_CSV) {
             $record->r_total_grade .= get_string('percent_symbol', $this->lang_file);
         }
     } else {
         $record->r_total_grade = get_string('na', $this->lang_file);
     }
     $record->r_status = $record->r_status == 1 ? get_string('complete', $this->lang_file) : get_string('incomplete', $this->lang_file);
     $record->curriculum_name = $record->curriculum_name == '' ? get_string('na', $this->lang_file) : $record->curriculum_name;
     return $record;
 }
 /**
  * Transforms a heading element displayed above the columns into a listing of such heading elements
  *
  * @param   string array           $grouping_current  Mapping of field names to current values in the grouping
  * @param   table_report_grouping  $grouping          Object containing all info about the current level of grouping
  *                                                    being handled
  * @param   stdClass               $datum             The most recent record encountered
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  string array                              Set of text entries to display
  */
 function transform_grouping_header_label($grouping_current, $grouping, $datum, $export_format)
 {
     if ($grouping->id == 'studentname') {
         $user = new stdClass();
         $user->firstname = $datum->firstname;
         $user->lastname = $datum->lastname;
         $fullname = php_report::fullname($user);
         $result = array($this->add_grouping_header($grouping->label, $fullname, $export_format));
     } else {
         $result = array($this->add_grouping_header($grouping->label, $grouping_current[$grouping->field], $export_format));
     }
     return $result;
 }
Exemplo n.º 11
0
 /**
  * Mainline for showing all jobs currently set up for an existing
  * report
  *
  * @uses $CFG
  * @uses $USER
  * @uses $OUTPUT
  * @uses $PAGE
  */
 function display_listinstancejobs()
 {
     global $CFG, $USER, $OUTPUT, $PAGE;
     //report specified by URL
     $report = $this->required_param('report', PARAM_ALPHAEXT);
     //get the necessary data
     $recordset = local_elisreports_get_report_jobs_recordset($report);
     //set up a job if none exist and a special parameter
     //is passed in to signal this functinality
     $createifnone = optional_param('createifnone', 0, PARAM_INT);
     if ($createifnone) {
         if (!$recordset or !$recordset->valid()) {
             //set up a job for this report
             $this->display_default();
             return;
         }
     }
     if ($recordset = local_elisreports_get_report_jobs_recordset($report) and $recordset->valid()) {
         //we actually have scheduled instances for this report
         //display appropriate headers
         $this->render_listinstancejobs_header(true, NULL, php_report::EXECUTION_MODE_SCHEDULED);
         //set up our form
         echo '<form action="' . $this->url . '" method="post">';
         //used by the "select all" functionality to identify a defining div
         echo '<div id="list_display">';
         echo '<input type="hidden" id="report" name="report" value="' . $report . '"/>';
         //table setup
         $table = new html_table();
         //headers, with a "select all" checkbox in the first column
         $PAGE->requires->js('/local/elisreports/js/lib.js');
         //checkbox for selecting all
         $checkbox_label = get_string('listinstancejobs_header_select', 'local_elisreports');
         $checkbox_attributes = array('onclick' => 'select_all()');
         $checkbox = html_writer::checkbox('selectall', '', false, $checkbox_label, $checkbox_attributes);
         $table->head = array($checkbox, get_string('listinstancejobs_header_label', 'local_elisreports'), get_string('listinstancejobs_header_owner', 'local_elisreports'), get_string('listinstancejobs_header_lastrun', 'local_elisreports'), get_string('listinstancejobs_header_nextrun', 'local_elisreports'), get_string('listinstancejobs_header_lastmodified', 'local_elisreports'));
         //left align all columns
         $table->align = array();
         foreach ($table->head as $column_header) {
             $table->align[] = 'left';
         }
         $table->data = array();
         //run through available schedules
         foreach ($recordset as $record) {
             $config_data = unserialize($record->config);
             $tz = $config_data['timezone'];
             //echo "action_listinstancejobs():: {$config_data['label']}: nextruntime = {$record->nextruntime}<br/>";
             //convert the last run time to the appropraite format
             if ($record->lastruntime == 0) {
                 //special case: never run before
                 $lastruntime = get_string('no_last_runtime', 'local_elisreports');
             } else {
                 $lastruntime = userdate($record->lastruntime, '', $tz) . ' (' . usertimezone($tz) . ')';
                 debug_error_log("/local/elisreports/lib/schedulelib.php::action_listinstancejobs(); {$config_data['label']}: record->lastruntime = {$record->lastruntime}, tz = {$tz}");
             }
             // convert 'will run next at' time to appropriate format
             $jobenddate = $config_data['schedule']['enddate'];
             debug_error_log("/local/elisreports/lib/schedulelib.php::action_listinstancejobs(); {$config_data['label']}: nextruntime = {$record->nextruntime}, jobenddate = {$jobenddate}");
             if (!empty($record->nextruntime) && (empty($jobenddate) || $record->nextruntime < $jobenddate + DAYSECS)) {
                 $nextruntime = userdate($record->nextruntime, '', $tz) . ' (' . usertimezone($tz) . ')';
             } else {
                 $nextruntime = get_string('job_completed', 'local_elisreports');
             }
             $checkbox = '<input type="checkbox" name="schedule_' . $record->scheduleid . '">';
             //link for editing this particular schedule instance
             $edit_schedule_params = array('id' => $record->scheduleid, 'action' => 'default');
             $edit_schedule_page = $this->get_new_page($edit_schedule_params);
             $edit_schedule_link = '<a href="' . $edit_schedule_page->url . '">' . $config_data['label'] . '</a>';
             //data row
             $table->data[] = array($checkbox, $edit_schedule_link, php_report::fullname($record), $lastruntime, $nextruntime, userdate($config_data['timemodified']));
         }
         echo html_writer::table($table);
         echo $OUTPUT->spacer();
         //display the dropdown and button in an enabled state
         $this->render_listinstancejobs_actions_dropdown(true);
         echo '</div>';
         echo '</form>';
     } else {
         //display header info
         $this->render_listinstancejobs_header(false, NULL, php_report::EXECUTION_MODE_SCHEDULED);
         //display the dropdown and button in a disabled state
         $this->render_listinstancejobs_actions_dropdown(false);
         echo $OUTPUT->spacer();
     }
     //general footer
     $this->render_listinstancejobs_footer();
 }
Exemplo n.º 12
0
    /**
     * This is where an icon report's data should be calculated and set in $this->data
     *
     * $this->data should contain an array for each icon, containing the display name,
     * the numerical value, and the path to the icon file
     */
    function calculate_data() {
        global $DB;

        $this->data = $this->get_default_data();

        foreach ($this->data as $key => $value) {

            //first step - try getting the item value directly
            $data_item = $this->get_data_item($key);

            if ($data_item !== FALSE) {
                $this->data[$key]->value = $data_item;
            } else {
                //backup plan - use SQL query to get the item value

                $use_filters = true;
                list($sql, $params) = $this->get_data_item_sql($key, $use_filters);

                if ($sql !== FALSE) {
                    //parse SQL for a WHERE clause

                    $has_where_clause = php_report::sql_has_where_clause($sql);

                    $conditional_symbol = 'WHERE';

                    if($has_where_clause) {
                        $conditional_symbol = 'AND';
                    }

                    //apply filters if applicable
                    if(!empty($this->filter) && !empty($use_filters)) {
                        list($additional_sql, $additional_params) = $this->filter->get_sql_filter('', $this->get_filter_exceptions($key), $this->allow_interactive_filters(), $this->allow_configured_filters());
                        if(!empty($additional_sql)) {
                            $sql .= " {$conditional_symbol} ({$additional_sql})";
                            $params = array_merge($params, $additional_params);
                        }
                    }

                    //obtain field value
                    if ($field_data = $DB->get_field_sql($sql, $params)) {
                        $this->data[$key]->value = $field_data;
                    }
                }
            }
        }


    }
 /**
  * Takes a record and transoforms it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The current report record
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The reformatted record
  */
 function transform_record($record, $export_format)
 {
     if ($record->completestatus == STUSTATUS_PASSED) {
         $record->completestatus = get_string('status_complete', 'rlreport_course_completion_gas_gauge');
     } else {
         $record->completestatus = get_string('status_incomplete', 'rlreport_course_completion_gas_gauge');
     }
     if ($export_format == php_report::$EXPORT_FORMAT_HTML) {
         //convert user name to their full name and link to the CM user page for that user
         $userpage = new userpage(array('id' => $record->cmuserid, 'action' => 'view'));
         $record->firstname = '<span class="external_report_link"><a href="' . $userpage->url . '" target="_blank">' . php_report::fullname($record) . '</a></span>';
     } else {
         if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
             $record->firstname = php_report::fullname($record);
         }
     }
     //calculate the percentage of completion elements satisfied
     if ($record->numcompletionelements == 0) {
         $record->percentcomplete = get_string('na', 'rlreport_course_completion_gas_gauge');
     } else {
         $record->percentcomplete = $record->numcompleted / $record->numcompletionelements * 100;
         $record->percentcomplete = number_format($record->percentcomplete, 1);
     }
     //display logic for the count of completion elements
     //$record->numcompleted = $record->numcompleted . ' / ' . $record->numcompletionelements;
     $record->numcompleted = get_string('completed_tally', 'rlreport_course_completion_gas_gauge', $record);
     //format the Moodle gradebook course score
     // ELIS-4916(ELIS-4439): now using ELIS grade!
     //if ($record->score === NULL || empty($record->grademax)) {
     if (!empty($record->elisgrade)) {
         $record->score = pm_display_grade($record->elisgrade);
         if (is_numeric($record->score) && $export_format != php_report::$EXPORT_FORMAT_CSV) {
             $record->score .= get_string('percent_symbol', 'rlreport_course_completion_gas_gauge');
         }
     } else {
         $record->score = get_string('na', 'rlreport_course_completion_gas_gauge');
     }
     return $record;
 }
Exemplo n.º 14
0
    /**
     * Print the paging headers for the table.
     *
     * @param   int|string  $id  Id of php report element, if applicable
     * @uses    $CFG
     * @uses    $OUTPUT
     * @return  string           HTML output for display.
     */
    function print_header($id = 0) {
        global $CFG, $OUTPUT;

        $output = '';
        $args = '';

        $export_formats = $this->get_export_formats();
        $allowable_export_formats = php_report::get_allowable_export_formats();

        if ($id !== 0) {
            $effective_url = $CFG->wwwroot . '/local/elisreports/dynamicreport.php?id=' . $id;
        } else {
            $effective_url = $this->baseurl;
        }

        //similar to parent class, but maintains gas gauge page
        $this->print_paging_bar($this->numrecs, $this->page, $this->perpage,
                                "{$effective_url}&amp;sort={$this->sort}&amp;dir={$this->dir}&amp;" .
                                "perpage={$this->perpage}&amp;gas_gauge_page={$this->gas_gauge_page}{$args}&amp;");

        echo $this->get_interactive_filter_display();

        return $output;
    }
 /**
  * Formats a timestamp as desired based on a language string and the user's time zone
  *
  * @param   int     $timestamp  The timestamp to format
  * 
  * @return  string              The formatted date
  */
 function format_date($timestamp)
 {
     //determine the format
     $format = get_string('date_format', 'rlreport_course_completion_by_cluster');
     //figure out the correct timezone
     $timezone = 99;
     if ($user_record = get_record('user', 'id', $this->userid)) {
         //determine the user's timezone
         $timezone = php_report::get_user_timezone($user_record, $user_record->timezone);
     }
     //perform the formatting
     return userdate($timestamp, $format, $timezone, false);
 }
 /**
  * Takes a record and transforms it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The current report record
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The reformatted record
  */
 function transform_record($record, $export_format)
 {
     if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
         $user = new stdClass();
         $user->firstname = $record->firstname;
         $user->lastname = $record->r_student;
         $record->r_student = php_report::fullname($user);
     }
     $record->curriculum_name = $record->curriculum_name == '' ? get_string('na', $this->lang_file) : $record->curriculum_name;
     $record->r_startdate = $record->r_startdate == 0 ? get_string('na', $this->lang_file) : $this->userdate($record->r_startdate, get_string('strftimedaydate'));
     return $record;
 }
 /**
  * Formats a timestamp as desired based on a language string and the user's time zone
  *
  * @param   int     $timestamp  The timestamp to format
  *
  * @return  string              The formatted date
  */
 function format_date($timestamp)
 {
     //handle special cases
     if ($timestamp === '0') {
         //the zero timestamp
         return get_string('na', $this->languagefile);
     } else {
         if (empty($timestamp)) {
             //NULL column
             return '';
         }
     }
     //determine the format
     $format = get_string('date_format', $this->languagefile);
     //figure out the correct timezone
     $timezone = 99;
     if ($user_record = get_record('user', 'id', $this->userid)) {
         //determine the user's timezone
         $timezone = php_report::get_user_timezone($user_record, $user_record->timezone);
     }
     //perform the formatting
     return userdate($timestamp, $format, $timezone, false);
 }
Exemplo n.º 18
0
 * @package    local_eliscore
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/local/elisreports/php_report_base.php';
require_once dirname(__FILE__) . '/autocompletelib.php';
//require a report and a filter
$requested_report = required_param('report', PARAM_CLEAN);
$requested_filter = required_param('filter', PARAM_CLEAN);
$q = trim(optional_param('q', '', PARAM_CLEAN));
$mode = optional_param('mode', 'ui', PARAM_CLEAN);
//instantiate the report
$report = php_report::get_default_instance($requested_report);
if (empty($report)) {
    echo get_string('autocomplete_noreport', 'local_eliscore'), ' (Error0)';
    die;
}
//authenticate ability to view this report
if (!$report->is_available() || !$report->can_view_report()) {
    echo get_string('autocomplete_reportunavail', 'local_eliscore'), ' (Error1)';
    die;
}
//get the requested filter
$filters = $report->get_filters(false);
$found_filter = null;
foreach ($filters as $i => $filter) {
    if ($filter->uniqueid === $requested_filter) {
        $found_filter = $filter;
 /**
  * Transforms a heading element displayed above the columns into a listing of such heading elements
  *
  * @param   string array           $grouping_current  Mapping of field names to current values in the grouping
  * @param   table_report_grouping  $grouping          Object containing all info about the current level of grouping
  *                                                    being handled
  * @param   stdClass               $datum             The most recent record encountered
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  string array                              Set of text entries to display
  */
 function transform_grouping_header_label($grouping_current, $grouping, $datum, $export_format)
 {
     //TBD: dependencies for custom fields
     $labels = array();
     //user fullname
     if ($export_format == table_report::$EXPORT_FORMAT_HTML) {
         //label for this grouping element
         $text_label = get_string('grouping_name', $this->languagefile);
     } else {
         //label for all groupings
         $text_label = get_string('grouping_name_csv', $this->languagefile);
     }
     $fullname_text = php_report::fullname($datum);
     $labels[] = $this->add_grouping_header($text_label, $fullname_text, $export_format);
     $filters = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'filter-detailheaders', $this->filter);
     $headers = $filters[0]['value'];
     $this->_userfieldids = array();
     if (!empty($headers)) {
         foreach ($headers as $field => $active) {
             if ($active && substr($field, 0, 7) == 'custom_') {
                 $fieldid = substr($field, 7);
                 $this->_userfieldids[] = $fieldid;
             }
         }
     }
     //configured user custom fields
     if (!empty($this->_userfieldids)) {
         //only need to obtain the user information once
         $user = \local_elisprogram\context\user::instance($datum->userid);
         //add a row for each field
         foreach ($this->_userfieldids as $userfieldid) {
             $field = new field($userfieldid);
             //needed to store just the actual data value
             $rawdata = array();
             if ($customdata = field_data::get_for_context_and_field($user, $field)) {
                 //could potentially have multiple values
                 foreach ($customdata as $customdatum) {
                     if ($field->datatype == 'bool') {
                         //special display handling for boolean values
                         $rawdata[] = !empty($customdatum->data) ? get_string('yes') : get_string('no');
                     } else {
                         if (isset($field->owners['manual']) && ($manual = new field_owner($field->owners['manual'])) && $manual->param_control == 'datetime') {
                             //special display handling for datetime fields
                             $rawdata[] = $this->userdate($customdatum->data, get_string(!empty($manual->param_inctime) ? 'customfield_datetime_format' : 'customfield_date_format', $this->languagefile));
                         } else {
                             $rawdata[] = $customdatum->data;
                         }
                     }
                 }
             }
             $labels[] = $this->add_grouping_header($field->name . ': ', implode(', ', $rawdata), $export_format);
         }
     }
     //user address
     if (!empty($headers['user_address'])) {
         $text_label = get_string('grouping_address', $this->languagefile);
         $address_text = get_string('grouping_address_format', $this->languagefile, $datum);
         $labels[] = $this->add_grouping_header($text_label, $address_text, $export_format);
     }
     //user city / town
     if (!empty($headers['user_city'])) {
         $text_label = get_string('grouping_city', $this->languagefile);
         $labels[] = $this->add_grouping_header($text_label, $datum->city, $export_format);
     }
     //user state / province
     if (!empty($headers['user_state'])) {
         $text_label = get_string('grouping_state', $this->languagefile);
         $labels[] = $this->add_grouping_header($text_label, $datum->state, $export_format);
     }
     //user email address
     if (!empty($headers['user_email'])) {
         $text_label = get_string('grouping_email', $this->languagefile);
         $labels[] = $this->add_grouping_header($text_label, $datum->email, $export_format);
     }
     // Get the credit total
     $num_credits = $this->get_total_credits($grouping_current, $grouping, $datum, $export_format);
     //create the header item
     $text_label = get_string('grouping_credits', $this->languagefile);
     $labels[] = $this->add_grouping_header($text_label, $num_credits, $export_format);
     return $labels;
 }
 /**
  * Transforms a column-based header entry into the form required by the report
  *
  * @param   stdClass  $element        The record representing the current grouping row
  *                                    (including only fields that are part of that grouping row)
  * @param   stdClass  $datum          The record representing the current report row
  * @param   string    $export_format  The format being used to render the report
  * @uses    $CFG
  * @return  stdClass                  The current grouping row, in its final state
  */
 function transform_grouping_header_record($element, $datum, $export_format)
 {
     global $CFG;
     $induser_report_location = "{$CFG->wwwroot}/local/elisreports/render_report_page.php?report=individual_user&userid={$datum->userid}";
     //make this a link if we're in HTML format
     if ($export_format == php_report::$EXPORT_FORMAT_HTML) {
         $element->useridnumber = '<span class="external_report_link"><a href="' . $induser_report_location . '"" target="_blank">' . $element->useridnumber . '</a></span>';
     }
     if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
         //use the user's full name
         $element->firstname = php_report::fullname($datum);
     }
     //make this a link if we're in HTML format
     if ($export_format == php_report::$EXPORT_FORMAT_HTML) {
         $element->firstname = '<span class="external_report_link"><a href="' . $induser_report_location . '"" target="_blank">' . $element->firstname . '</a></span>';
     }
     return $element;
 }
Exemplo n.º 21
0
/**
 * Obtains a listing of report display names, grouped by category
 *
 * @param   boolean       $require_exportable  If true, only include reports that are considered to be exportable
 *                                             in the context of scheduling
 * @param  int|NULL       $userid              Id of the Moodle user who this report is being
 *                                             for
 * @param  int            $execution_mode      The mode in which this report is being executed
 *
 * @return  string array                       Mapping of category shortname to mappings of
 *                                             report shortnames to display names (category entries
 *                                             will exist but be empty if no reports are in that category)
 */
function block_php_report_get_names_by_category($require_exportable = false, $userid = NULL, $execution_mode = php_report::EXECUTION_MODE_INTERACTIVE)
{
    global $CFG;
    $category_members = array();
    //get a listing of the different categories
    $categories = block_php_report_get_category_mapping();
    //initialize a bucket to store a category's reports where applicable
    foreach ($categories as $category_key => $category_display) {
        $category_members[$category_key] = array();
    }
    //go through the directories
    if ($handle = opendir($CFG->dirroot . '/blocks/php_report/instances')) {
        while (false !== ($report_shortname = readdir($handle))) {
            //get the report instance (this inherently checks permissions and report availability)
            if ($instance = php_report::get_default_instance($report_shortname, $userid, $execution_mode)) {
                //determine if the export action is available in the context of scheduling
                $export_available = true;
                //check permissions and make sure access is not explicitly disallowed in the current execution mode
                if (!$instance->can_view_report()) {
                    $export_available = false;
                }
                //make sure there is at least one available export format
                $export_formats = $instance->get_export_formats();
                if (count($export_formats) == 0) {
                    $export_available = false;
                }
                if (!$require_exportable || $export_available) {
                    $category_shortname = $instance->get_category();
                    $report_shortname = $instance->get_report_shortname();
                    $category_members[$category_shortname][$report_shortname] = $instance->get_display_name();
                }
            }
        }
        //sort reports by display name within each category
        foreach ($category_members as $category_shortname => $bucket) {
            sort($bucket);
            $category_members[$category_shortname];
        }
    }
    return $category_members;
}
Exemplo n.º 22
0
    /**
     * Calculates the entire SQL query, including changes made
     * by the report engine
     *
     * @param   boolean  $use_limit  true if the paging-based limit clause should be included, otherwise false
     * @param   string   $sql        Fixed sql to replace parameters with - if null, obtain from report definition
     * @param   array    $params     the SQL query parameters
     * @return  array                The SQL query, and the appropriate sql filter information
     */
    function get_complete_sql_query($use_limit = true, $sql = null, $params = array()) {
        $columns = $this->get_select_columns();

        //used to track whether we're in the main report flow or not
        $in_main_report_flow = false;

        //query from the report implementation
        if ($sql === null) {
            list($sql, $params) = $this->get_report_sql($columns);
            $in_main_report_flow = true;
        }

        //determine if the special wildcard for adding filter sql is included
        $parameter_token_pos = strpos($sql, table_report::PARAMETER_TOKEN);
        if ($parameter_token_pos === false) {
            //no wildcard, so add filter sql to the end

            //determine if we need an add or where clause
            $has_where_clause = php_report::sql_has_where_clause($sql);

            $conditional_symbol = 'WHERE';
            if ($has_where_clause) {
                $conditional_symbol = 'AND';
            }

            //add filter sql
            list($additional_sql, $additional_params) = $this->get_filter_condition($conditional_symbol);
            $sql .= $additional_sql;
            $params = array_merge($params, $additional_params);
        } else {
            //wildcard, so do a find and replace
            //get the filter clause without adding WHERE or AND - it's up to the
            //report to include those in this case because parsing pieces of queries
            //is complex and error-prone
            list($filter_clause, $filter_params) = $this->get_filter_condition('');
            if (empty($filter_clause)) {
                $filter_clause = 'TRUE';
            }

            //replace the wildcard with the filter clause
            $sql = str_replace(table_report::PARAMETER_TOKEN, $filter_clause, $sql);
            // Check for duplicate named parameters
            foreach ($filter_params as $key => $value) {
                if (substr_count($sql, ":{$key}") > 1) {
                    $cnt = 0;
                    $sql_parts = explode(":{$key}", $sql);
                    foreach($sql_parts as $sql_part) {
                        if ($cnt++) {
                            $newkey = ($cnt == 1) ? $key : "{$key}_{$cnt}";
                            $new_sql .= ":{$newkey}{$sql_part}";
                            $filter_params[$newkey] = $value;
                        } else {
                            $new_sql = $sql_part;
                        }
                    }
                    $sql = $new_sql;
                }
            }
            $params = array_merge($params, $filter_params);
        }

        if ($in_main_report_flow) {
            //grouping
            $groups = $this->get_report_sql_groups();
            if (!empty($groups)) {
                $sql .= " GROUP BY {$groups}";
            }

            $this->set_num_recs($sql, $params);

            //ordering
            $sql .= $this->get_order_by_clause();
        }
        //error_log("table_report::get_complete_sql_query(): sql = {$sql}");
        return array($sql, $params);
    }
 /**
  * Get the block content
  *
  * @return  object  content items and icons arrays of what is to be displayed in this block
  */
 function get_content()
 {
     global $CFG, $COURSE, $USER;
     if (!isloggedin() || isguestuser()) {
         //user is not properly logged in
         return '';
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $siteContext = get_context_instance(CONTEXT_SYSTEM);
     if ($COURSE->id == SITEID) {
         $context = $siteContext;
     } else {
         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     }
     // make sure the user has the required role
     if (!empty($this->config->role)) {
         $sql = "SELECT r.id, r.name\n                      FROM {$CFG->prefix}role r\n                      JOIN {$CFG->prefix}role_assignments ra ON ra.roleid = r.id\n                      JOIN {$CFG->prefix}user u ON u.id = ra.userid\n                     WHERE ra.contextid = {$context->id}\n                           AND u.id = {$USER->id}\n                           AND ra.roleid = {$this->config->role}";
         if (!record_exists_sql($sql)) {
             $this->content->items = array();
             $this->content->icons = array();
             return $this->content;
         }
     }
     $items = array();
     $icons = array();
     $categories = array();
     if (isset($this->config->reports)) {
         // Require the php_report class
         require_once $CFG->dirroot . '/blocks/php_report/php_report_base.php';
         $params = array();
         // set the parameters that we can get from the environment
         // (currently only the course ID)
         if ($this->instance->pagetype == PAGE_COURSE_VIEW) {
             if ($this->instance->pageid != SITEID) {
                 $params['courseid'] = $this->instance->pageid;
             }
         }
         // TODO: figure out capability for showing scheduling icon
         $isediting = isediting($this->instance->pageid);
         // && has_capability('block/php_report:manageactivities', $context);
         $count = 0;
         // create links to the reports
         foreach ($this->config->reports as $report) {
             if (isset(block_elis_reports::$reports_map[$report->id])) {
                 $report->id = block_elis_reports::$reports_map[$report->id];
             }
             $report_instance = php_report::get_default_instance($report->id);
             //make sure the report shortname is valid
             if ($report_instance !== FALSE) {
                 if ($report_instance->is_available() && $report_instance->can_view_report()) {
                     $category = $report_instance->get_category();
                     if (!isset($categories[$category])) {
                         $categories[$category] = array();
                     }
                     $name = $report_instance->get_display_name();
                     $report_link = new moodle_url($CFG->wwwroot . '/blocks/php_report/render_report_page.php', $params + $report->params + array('report' => $report->id));
                     $categories[$category][$count]['item'] = '<a href="' . $report_link->out() . '">' . $name . '</a>';
                     //create an instance specifically for testing scheduling permissions
                     $test_scheduling_permissions_instance = php_report::get_default_instance($report->id, NULL, php_report::EXECUTION_MODE_SCHEDULED);
                     //get_default instance will return FALSE if we are not allowed access to scheduling
                     $can_schedule = $test_scheduling_permissions_instance !== FALSE;
                     if ($isediting && $can_schedule) {
                         // TODO: add permissions to this url
                         $link = new moodle_url('/blocks/php_report/schedule.php?report=' . $report->id . '&action=listinstancejobs&createifnone=1');
                         $image_link = '<a href="#" alt=\'' . get_string('schedule_this_report', 'block_php_report') . '\'  title=\'' . get_string('schedule_this_report', 'block_php_report') . '\' onclick="openpopup(\'' . $link->out() . '\', \'php_report_param_popup\', \'menubar=0,location=0,scrollbars,status,resizable,width=1600,height=600\');return false;">
                                         &nbsp;<img src="' . $CFG->wwwroot . '/blocks/php_report/pix/schedule.png"/>
                                         </a>';
                         $categories[$category][$count]['sched_icon'] = $image_link;
                     }
                     $categories[$category][$count]['icon'] = '<img src="' . $CFG->wwwroot . '/blocks/elis_reports/pix/report.png" />';
                     $count++;
                 }
             }
         }
         // Generates items and icons array
         $this->generate_content($categories, $this->content->items, $this->content->icons);
     }
     return $this->content;
 }
Exemplo n.º 24
0
 /**
  * Takes a record and transforms it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The current report record
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The reformatted record
  */
 function transform_record($record, $export_format)
 {
     $user = new stdClass();
     $user->firstname = $record->firstname;
     $user->lastname = $record->r_student;
     $fullname = php_report::fullname($user);
     if (property_exists($record, 'r_clst_name')) {
         //reformat userset name(s)
         if (empty($record->r_clst_name)) {
             $record->r_clst_name = get_string('na', 'local_elisreports');
         } elseif ($export_format == php_report::$EXPORT_FORMAT_EXCEL || $export_format == php_report::$EXPORT_FORMAT_CSV) {
             $record->r_clst_name = str_replace(',', '/', $record->r_clst_name);
         } else {
             $record->r_clst_name = str_replace(',', '<br>', $record->r_clst_name);
         }
     }
     if (isset($record->r_country)) {
         //get readable country
         $countries = get_string_manager()->get_list_of_countries();
         if (isset($countries[$record->r_country])) {
             $record->r_country = $countries[$record->r_country];
         }
     }
     if (isset($record->r_language)) {
         //get readable language
         $languages = get_string_manager()->get_list_of_languages();
         if (isset($languages[$record->r_language])) {
             $record->r_language = $languages[$record->r_language];
         }
     }
     if (isset($record->r_birthdate)) {
         //reformat the birthdate
         $record->r_birthdate = date('d F Y', strtotime($record->r_birthdate));
     }
     if (isset($record->r_gender)) {
         //get readable gender
         $record->r_gender = $record->r_gender == 'F' ? get_string('female', 'local_elisprogram') : get_string('male', 'local_elisprogram');
     }
     if (isset($record->r_inactive)) {
         //reformat inactive
         $record->r_inactive = $record->r_inactive ? get_string('yes') : get_string('no');
     }
     if ($export_format == php_report::$EXPORT_FORMAT_HTML) {
         $userpage = new userpage(array('id' => $record->cmuserid, 'action' => 'view'));
         $record->r_student = '<span class="external_report_link"><a href="' . $userpage->url . '">' . $fullname . '</a></span>';
     } else {
         if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
             $record->r_student = $fullname;
         }
     }
     return $record;
 }
Exemplo n.º 25
0
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once dirname(__FILE__) . '/../../config.php';
require_once $CFG->dirroot . '/blocks/php_report/parameter_form.class.php';
require_once $CFG->dirroot . '/curriculum/lib/filtering/lib.php';
require_once $CFG->libdir . '/formslib.php';
require_once $CFG->dirroot . '/blocks/php_report/lib/filtering.php';
//report shortname
$report_shortname = required_param('id', PARAM_CLEAN);
//optional action url for form
$action = optional_param('url', null);
//require dependencies for filters
php_report_filtering_require_dependencies();
//key report data
$instance = php_report::get_default_instance($report_shortname);
//NOTE: this is slow because it populates filter values
$filters = $instance->get_filters();
//obtain any necessary information regarding secondary filterings
$dynamic_report_filter_url = $CFG->wwwroot . '/blocks/php_report/dynamicreport.php?id=' . $report_shortname;
$secondary_filterings = $instance->get_secondary_filterings($dynamic_report_filter_url, $report_shortname, $report_shortname);
//when set, show the cancel button
$showcancel = optional_param('showcancel', 0, PARAM_INT);
//create the form, whose contents depend on on the current report's available filters
if (!empty($filters)) {
    //report has filters
    $dynamic_report_filter_url = $CFG->wwwroot . '/blocks/php_report/dynamicreport.php?id=' . $report_shortname;
    $filter_object = new php_report_default_capable_filtering($filters, $dynamic_report_filter_url, null, $report_shortname, $report_shortname, $secondary_filterings);
    $params = array('filterobject' => $filter_object, 'showcancel' => $showcancel);
    $parameter_form = new parameter_form($action, $params);
} else {
 /**
  * Calculates the data for a specified data series
  *
  * @param   unknown  $key  A key that uniquely identifies the series, as
  *                         specified by calculate_series_list
  *
  * @return  array          The numerical data for the specified series
  */
 function calculate_series($series_key)
 {
     $data = array();
     $points = $this->calculate_series_points($series_key);
     foreach ($points as $point) {
         $sql = $this->get_series_point_data_sql($series_key, $point);
         $has_where_clause = php_report::sql_has_where_clause($sql);
         $conditional_symbol = 'WHERE';
         if ($has_where_clause) {
             $conditional_symbol = 'AND';
         }
         if (!empty($this->filter)) {
             $sql_filter = $this->filter->get_sql_filter('', array(), $this->allow_interactive_filters(), $this->allow_configured_filters());
             if (!empty($sql_filter)) {
                 $sql .= " {$conditional_symbol} ({$sql_filter})";
             }
         }
         if ($point_data = get_field_sql($sql)) {
             $data[] = $point_data;
         } else {
             $data[] = 0;
         }
     }
     return $data;
 }
 /**
  * from /lib/moodlelib.php::userdate()
  * Returns a formatted string that represents a date in user time
  *
  * @param int    $date timestamp in GMT
  * @param string $format strftime format
  * @param bool   $fixday If true then the leading zero from %d is removed.
  *               If false (default) then the leading zero is mantained.
  * @return string
  */
 function userdate($date, $format = '', $fixday = false)
 {
     // TBD: false???
     $timezone = 99;
     if ($user_record = get_record('user', 'id', $this->userid)) {
         //determine the user's timezone
         $timezone = php_report::get_user_timezone($user_record, $user_record->timezone);
     }
     //perform the formatting
     return userdate($date, $format, $timezone, $fixday);
 }
 /**
  * Takes a summary row record and transoforms it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The last report record
  * @param   stdClass  $nextrecord     The next report record
  * @param   string    $export_format  The format being used to render the report
  * @return stdClass  The reformatted record
  */
 function transform_group_column_summary($record, $nextrecord, $export_format)
 {
     //$this->err_dump($record, 'transform_group_column_summary($record, $nextrecord, '. $export_format .')');
     $record->coursename = '';
     $record->classid = '';
     $prevfield = '';
     // clear all not required columns - saving 2nd last for label
     switch ($this->segment) {
         case 'noseg':
             $prevfield = 'gcslabel';
             // 'classid'
             break;
         case 'years':
             foreach ($this->months as $month) {
                 $record->{$month} = '';
                 $prevfield = $month;
             }
             break;
         case 'months':
             foreach ($this->weeks as $wk) {
                 $record->{$wk} = '';
                 $prevfield = $wk;
             }
             if (!empty($record->month)) {
                 $sparam = new stdClass();
                 $sparam->int_month = $record->month;
                 $sparam->str_month = get_string($this->months[$record->month - 1], $this->langfile);
                 $record->month = get_string('month_format', $this->langfile, $sparam);
             }
             break;
         case 'weeks':
             foreach ($this->wkdays as $day) {
                 $record->{$day} = '';
                 $prevfield = $day;
             }
             break;
         default:
             error_log("sitewide_time_summmary_report::transform_group_column_summary() - illegal segment: {$this->segment}");
     }
     if (empty($record->year)) {
         $record->year = get_string('no_time_logged', $this->langfile, strtolower(get_string('seg_years', $this->langfile)));
     }
     if (empty($record->year) || empty($record->month)) {
         $record->month = get_string('no_time_logged', $this->langfile, strtolower(get_string('seg_months', $this->langfile)));
     }
     if (empty($record->year) || empty($record->week)) {
         $record->week = get_string('no_time_logged', $this->langfile, strtolower(get_string('seg_weeks', $this->langfile)));
     }
     if (!empty($prevfield)) {
         $record->{$prevfield} = get_string('grouping_totaltime', $this->langfile);
     }
     $totaltime_fmt = $export_format == php_report::$EXPORT_FORMAT_CSV ? 'time_format' : 'totaltime_format';
     $record->totaltime = $this->format_time(get_string($totaltime_fmt, $this->langfile), $this->grouptotal);
     $this->grouptotal = 0;
     // reset for next time
     $record->user_id = php_report::fullname($record);
     return $record;
 }
Exemplo n.º 29
0
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/blocks/php_report/lib/filtering.php';
//report instance id can be a block instance id
//or a general report shortname
$id = required_param('id', PARAM_CLEAN);
//selected export format
$format = required_param('format', PARAM_CLEAN);
//load filter classes
php_report_filtering_require_dependencies();
$report = php_report::get_default_instance($id);
//permissions checking
if ($report->can_view_report()) {
    //NOTE: this is fast because it will not populate filter values
    $report->init_all($id);
    //require any necessary report-specific dependencies
    $report->require_dependencies();
    //make sure we have enough resources to export our report
    php_report::allocate_extra_resources();
    //initiate download using sql query without paging
    $report->download($format, $report->get_complete_sql_query(false));
}
Exemplo n.º 30
0
 /**
  * Transforms a column-based header entry into the form required by the report
  *
  * @param   stdClass  $element        The record representing the current grouping row
  *                                    (including only fields that are part of that grouping row)
  * @param   stdClass  $datum          The record representing the current report row
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The current grouping row, in its final state
  */
 function transform_grouping_header_record($element, $datum, $export_format)
 {
     global $CFG;
     /**
      * Correct formatting for certain fields
      **/
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/student.class.php';
     /**
      * Set up link to individual user report
      **/
     $single_student_report_url = "{$CFG->wwwroot}/local/elisreports/render_report_page.php?report=individual_user&userid={$datum->userid}";
     // Use the datum object to get first and last name for fullname
     $fullname = php_report::fullname($datum);
     if ($export_format == php_report::$EXPORT_FORMAT_HTML) {
         $element->lastname = "<span class=\"external_report_link\">\n                             <a href=\"{$single_student_report_url}\">{$fullname}</a>\n                             </span>";
     } else {
         if ($export_format != php_report::$EXPORT_FORMAT_CSV && $export_format != php_report::$EXPORT_FORMAT_EXCEL) {
             $element->lastname = $fullname;
         }
     }
     return $element;
 }