public function index($args)
 {
     $db = new Database($this->wpdb);
     $id = isset($args['id']) ? $args['id'] : Reports::DEFAULT_REPORT_ID;
     $reports = new Reports($db);
     $template = $reports->get_template($id);
     $out = $template->render();
     if ($template->file_extension) {
         $this->send_file($template->file_extension, $template->mime_type, $out, $template->title);
     } else {
         return $out;
     }
 }
示例#2
0
 /**
  * @testdox A report's Template inherits  the report's `file_extension`, `mime_type`, and `title` attributes.
  * @test
  */
 public function file_extension()
 {
     $reportsTable = $this->db->get_table(Reports::reports_table_name());
     $reports = new Reports($this->db);
     // 1. No file_extension attribute is set, but the others are.
     $report1 = $reportsTable->save_record(array('title' => 'Test Report 1', 'mime_type' => 'text/plain'));
     $template1 = $reports->get_template($report1->id());
     $this->assertNull($template1->file_extension);
     $this->assertEquals('text/plain', $template1->mime_type);
     // 2. A 'GPX' file extension is set, and the default mime_type.
     $report2 = $reportsTable->save_record(array('title' => 'Test Report 2', 'file_extension' => 'gpx'));
     $template2 = $reports->get_template($report2->id());
     $this->assertEquals('gpx', $template2->file_extension);
     $this->assertEquals('text/html', $template2->mime_type);
 }
 public function index()
 {
     $template = new \WordPress\Tabulate\Template('home.html');
     $template->title = 'Tabulate';
     $db = new \WordPress\Tabulate\DB\Database($this->wpdb);
     // Tables.
     $transient_name = TABULATE_SLUG . 'home_table_list';
     $table_info = get_transient($transient_name);
     if (!$table_info) {
         $table_info = array();
         foreach ($db->get_tables() as $table) {
             $table_info[] = array('title' => $table->get_title(), 'count' => $table->count_records(), 'url' => $table->get_url());
         }
         set_transient($transient_name, $table_info, MINUTE_IN_SECONDS * 5);
     }
     $template->tables = $table_info;
     // Views.
     $template->views = $db->get_views();
     // Reports.
     $reports_table = $db->get_table(\WordPress\Tabulate\DB\Reports::reports_table_name());
     $template->reports = $reports_table ? $reports_table->get_records(false) : array();
     return $template->render();
 }
示例#4
0
<?php

if (!defined('ABSPATH') || !defined('WP_UNINSTALL_PLUGIN')) {
    return false;
}
// Clear Grants' option.
$grants = new \WordPress\Tabulate\DB\Grants();
$grants->delete();
// Drop the ChangeTracker's and Reports' tables.
global $wpdb;
$wpdb->query('SET FOREIGN_KEY_CHECKS = 0');
foreach (\WordPress\Tabulate\DB\ChangeTracker::table_names() as $tbl) {
    $wpdb->query("DROP TABLE IF EXISTS `{$tbl}`;");
}
$wpdb->query("DROP TABLE IF EXISTS `" . \WordPress\Tabulate\DB\Reports::reports_table_name() . "`;");
$wpdb->query("DROP TABLE IF EXISTS `" . \WordPress\Tabulate\DB\Reports::report_sources_table_name() . "`;");
$wpdb->query('SET FOREIGN_KEY_CHECKS = 1');