Example #1
0
    } else {
        $data[] = clean_text($row->sitename);
    }
    $data[] = number_format($row->users);
    $data[] = number_format($row->courses);
    $table->data[] = $data;
}
echo html_writer::table($table);
*/
echo html_writer::end_tag('div');
/**
 * Display the major and minor registrations for the past 6 months
 */
echo $OUTPUT->heading(get_string('versionsused', 'local_hub'));
$partialminorchartexists = check_for_existing_cached_chart($CFG->dirroot . '/' . STATS_DIR . '/cache/partial.minor.versions.' . date('Ymd') . '.png');
$fullminorchartexists = check_for_existing_cached_chart($CFG->dirroot . '/' . STATS_DIR . '/cache/full.minor.versions.' . date('Ymd') . '.png');
if (!$partialminorchartexists || !$fullminorchartexists) {
    // This is a VERY costly query... VERRRRRRRRY costly
    // Only run this query is we NEED to generate
    $versioninfo = gather_version_information(0, 2, 0);
    // Last 2 months
    $fullversioninfo = gather_version_information(99, 0, 0);
    // Last 99 years
} else {
    // Generate a dummy array we won't generate the graph anyway
    $tempversion = array();
    $tempversion['version'] = '2.0.0';
    $tempversion['major'] = '2';
    $tempversion['minor'] = '0';
    $tempversion['release'] = '0';
    $tempversion['count'] = 1;
Example #2
0
/**
 * Used to find the latest cached version of the chart to display
 *
 * Usually this will only be called should there be an error with CURL
 * such that google charts didn't return an image, or couldn't be reached!
 *
 * @param string $filepath The directory where cached images exist
 * @param string $filename The filename for the cached images
 * @return string The new filename tp request
 */
function find_latest_cached_graph($filepath, $filename)
{
    // First check if it already exists, saves us time if it does
    $fileexists = check_for_existing_cached_chart($filepath . $filename);
    if ($fileexists === true) {
        return $filename;
    }
    // The cache directory doesn't exist we can't even proceed here
    if (!file_exists($filepath) || !is_dir($filepath) || !is_readable($filepath)) {
        return false;
    }
    // Open the directory for browsing
    $dir = dir($filepath);
    $possibilities = array();
    // Build the regular expression to recognise similar files
    $regexp = preg_replace('#\\.\\d{6,8}\\.png$#', '.(\\d){6,8}.png', $filename);
    $regexp = '#' . preg_replace('#([\\+\\.\\-\\_\\#])#', '\\\\$1', $regexp) . '#';
    // Recurse the directory
    while (false !== ($file = $dir->read())) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        // Check if each file is a matches the regexp
        if (preg_match($regexp, $file) && is_file($filepath . $file)) {
            $possibilities[] = $file;
        }
    }
    // Sort the possibile files and then return the top one :)
    if (count($possibilities) == 0) {
        return $filename;
    }
    rsort($possibilities);
    return $possibilities[0];
}