Esempio n. 1
0
 public function index()
 {
     $template = new \WordPress\Tabulate\Template('home.html');
     $db = new \WordPress\Tabulate\DB\Database($this->wpdb);
     $template->tables = $db->get_tables();
     $template->views = $db->get_views();
     return $template->render();
 }
Esempio n. 2
0
 public function index()
 {
     $template = new \WordPress\Tabulate\Template('erd/display.html');
     $template->title = 'ERD';
     $template->tables = $this->tables;
     $template->selected_tables = $this->selected_tables;
     $dot = new \WordPress\Tabulate\Template('erd/erd.dot');
     $dot->tables = $this->tables;
     $dot->selected_tables = $this->selected_tables;
     $gv = new \TFO_Graphviz();
     $gv->init();
     $template->graphviz = $gv->shortcode(array(), $dot->render());
     return $template->render();
 }
 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();
 }
Esempio n. 4
0
 public function calendar($args)
 {
     // @todo Validate args.
     $yearNum = isset($args['year']) ? $args['year'] : date('Y');
     $monthNum = isset($args['month']) ? $args['month'] : date('m');
     $template = new \WordPress\Tabulate\Template('calendar.html');
     $table = $this->get_table($args['table']);
     $template->table = $table;
     $template->action = 'calendar';
     $template->record = $table->get_default_record();
     $factory = new \CalendR\Calendar();
     $template->weekdays = $factory->getWeek(new \DateTime('Monday this week'));
     $month = $factory->getMonth(new \DateTime($yearNum . '-' . $monthNum . '-01'));
     $template->month = $month;
     $records = array();
     foreach ($table->get_columns('date') as $dateCol) {
         $dateColName = $dateCol->get_name();
         // Filter to the just the requested month.
         $table->add_filter($dateColName, '>=', $month->getBegin()->format('Y-m-d'));
         $table->add_filter($dateColName, '<=', $month->getEnd()->format('Y-m-d'));
         foreach ($table->get_records() as $rec) {
             $dateVal = $rec->{$dateColName}();
             // Initialise the day's list of records.
             if (!isset($records[$dateVal])) {
                 $records[$dateVal] = array();
             }
             // Add this record to the day's list.
             $records[$dateVal][] = $rec;
         }
     }
     // $records is grouped by date, with each item in a single date being
     // an array like: ['record'=>Record, 'column'=>$name_of_date_column]
     $template->records = $records;
     return $template->render();
 }
Esempio n. 5
0
 public function delete($args)
 {
     $db = new \WordPress\Tabulate\DB\Database($this->wpdb);
     $table = $db->get_table($args['table']);
     $record_ident = isset($args['ident']) ? $args['ident'] : false;
     if (!$record_ident) {
         wp_redirect($table->get_url());
         exit;
     }
     // Ask for confirmation.
     if (!isset($_POST['confirm_deletion'])) {
         $template = new \WordPress\Tabulate\Template('record/delete.html');
         $template->table = $table;
         $template->record = $table->get_record($record_ident);
         return $template->render();
     }
     // Delete the record.
     try {
         $this->wpdb->query('BEGIN');
         $table->delete_record($record_ident);
         $this->wpdb->query('COMMIT');
     } catch (\Exception $e) {
         $template = $this->get_template($table);
         $template->record = $table->get_record($record_ident);
         $template->add_notice('error', $e->getMessage());
         return $template->render();
     }
     wp_redirect($table->get_url());
     exit;
 }
Esempio n. 6
0
    });
    return;
}
require __DIR__ . '/vendor/autoload.php';
// This file contains the only global usages of wpdb; it's injected from here to
// everywhere else.
global $wpdb;
// Set up the menus; their callbacks do the actual dispatching to controllers.
$menus = new \WordPress\Tabulate\Menus($wpdb);
$menus->init();
// Add grants-checking callback.
add_filter('user_has_cap', '\\WordPress\\Tabulate\\DB\\Grants::check', 0, 3);
// Activation hooks. (Uninstall is handled by uninstall.php.)
register_activation_hook(__FILE__, '\\WordPress\\Tabulate\\DB\\ChangeTracker::activate');
register_activation_hook(__FILE__, '\\WordPress\\Tabulate\\DB\\Reports::activate');
// Register JSON API.
add_action('rest_api_init', function () {
    global $wpdb;
    $apiController = new \WordPress\Tabulate\Controllers\ApiController($wpdb, $_GET);
    $apiController->register_routes();
});
// Shortcode.
$shortcode = new \WordPress\Tabulate\Controllers\ShortcodeController($wpdb);
add_shortcode(TABULATE_SLUG, array($shortcode, 'run'));
// Dashboard widget.
add_action('wp_dashboard_setup', function () {
    wp_add_dashboard_widget(TABULATE_SLUG . 'dashboard_widget', 'Tabulate', function () {
        $template = new \WordPress\Tabulate\Template('quick_jump.html');
        echo $template->render();
    });
});
 public function timeline($args)
 {
     $table = $this->get_table($args['table']);
     $template = new \WordPress\Tabulate\Template('timeline.html');
     $template->action = 'timeline';
     $template->table = $table;
     $start_date_arg = isset($args['start_date']) ? $args['start_date'] : date('Y-m-d');
     $end_date_arg = isset($args['end_date']) ? $args['end_date'] : date('Y-m-d');
     $start_date = new \DateTime($start_date_arg);
     $end_date = new \DateTime($end_date_arg);
     if ($start_date->diff($end_date, true)->d < 7) {
         // Add two weeks to the end date.
         $end_date->add(new \DateInterval('P14D'));
     }
     $date_period = new \DatePeriod($start_date, new \DateInterval('P1D'), $end_date);
     $template->start_date = $start_date->format('Y-m-d');
     $template->end_date = $end_date->format('Y-m-d');
     $template->date_period = $date_period;
     $data = array();
     foreach ($table->get_records(false) as $record) {
         if (!isset($data[$record->get_title()])) {
             $data[$record->get_title()] = array();
         }
         $data[$record->get_title()][] = $record;
     }
     $template->data = $data;
     return $template->render();
 }