public function grab(&$param_pool = NULL) { $result = new XMLElement($this->dsParamROOTELEMENT); $param_output = array(); $filters = array(); if (!empty($this->dsParamSECTIONS)) { $filters['item_type'] = $this->dsParamSECTIONS; } else { $filters['item_type'] = 'REGEXP "[[:digit:]]+"'; } if (!empty($this->dsParamACTIONS)) { $filters['action_type'] = $this->dsParamACTIONS; } // Fetch the activity $activities = Tracker::fetchActivities($filters, $this->dsParamLIMIT, 0, $this->dsParamSORT, $this->dsParamORDER); // Build the XML foreach ($activities as $activity) { // Capture the section and entry ID for output params $param_output[$activity['item_type']][] = $activity['item_id']; // Break the fallback description into useful bits $activity['fallback_description'] = explode(':::', $activity['fallback_description']); // Build the <activity> element $item = new XMLElement('activity', NULL, array('type' => $activity['action_type'], 'entry-id' => $activity['item_id'])); // Append Section info $item->appendChild(new XMLElement('section', $activity['fallback_description'][1], array('id' => $activity['item_type']))); // Append Author info $item->appendChild(new XMLElement('author', $activity['fallback_username'], array('id' => $activity['user_id']))); // Append Date info $item->appendChild(new XMLElement('date', DateTimeObj::get('Y-m-d', strtotime($activity['timestamp'] . ' GMT')), array('time' => DateTimeObj::get('H:i', strtotime($activity['timestamp'] . ' GMT')), 'weekday' => DateTimeObj::get('N', strtotime($activity['timestamp'] . ' GMT'))))); $result->appendChild($item); } // Build output params foreach ($param_output as $section => $ids) { $param_pool['ds-' . $this->dsParamROOTELEMENT . '-' . $section] = implode(', ', $ids); } return $result; }
public function renderPanel($context) { $config = $context['config']; $page = Administration::instance()->Page; switch ($context['type']) { case 'tracker_activity': // Build filter info $filters = array(); if (isset($config['filter_string'])) { list($column, $value) = explode(':', $config['filter_string'], 2); $values = explode(',', $value); $filters[$column] = array(); foreach ($values as $value) { $filters[$column][] = rawurldecode($value); } } // Check to see we are being called in the right context // Dashboard also has `contentExtensionDashboardPanel_Config` which extends `AjaxPage` if (method_exists($page, 'addStylesheetToHead')) { $page->addStylesheetToHead(URL . '/extensions/tracker/assets/dashboard.css', 'screen', 151); } $logs = Tracker::fetchActivities($filters, (int) $config['limit'], 0); $thead = array(array(__('Activity'), 'col'), array(__('Date'), 'col'), array(__('Time'), 'col')); $tbody = array(); // If there are no logs, display default message if (!is_array($logs) or empty($logs)) { $tbody = array(Widget::TableRow(array(Widget::TableData(__('No data available.'), 'inactive', null, count($thead))), 'odd')); } else { $bOdd = true; foreach ($logs as $activity) { // Format the date and time $date = DateTimeObj::get(__SYM_DATE_FORMAT__, strtotime($activity['timestamp'] . ' GMT')); $time = DateTimeObj::get(__SYM_TIME_FORMAT__, strtotime($activity['timestamp'] . ' GMT')); $description = Tracker::getDescription($activity); // Assemble the columns $col_date = Widget::TableData($date); $col_time = Widget::TableData($time); $col_desc = Widget::TableData($description); // Insert the row if (!is_null($description)) { $tbody[] = Widget::TableRow(array($col_desc, $col_date, $col_time), $bOdd ? 'odd' : NULL); $bOdd = !$bOdd; } } } // Assemble the table $table = Widget::Table(Widget::TableHead($thead), null, Widget::TableBody($tbody), null); $context['panel']->appendChild($table); break; } }
public function view() { // Start building the page $this->setPageType('index'); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Tracker Activity')))); // Add a button to clear all activity $clearform = new XMLElement('form'); $clearform->setAttribute('method', 'post'); $clearform->setAttribute('action', Symphony::Engine()->getCurrentPageURL()); $button = new XMLElement('button', __('Clear All')); $button->setAttribute('class', 'tracker confirm'); $button->setAttribute('title', __('Clear all Activity')); $button->setAttribute('name', 'action[clear-all]'); $clearform->appendChild($button); $this->appendSubheading(__('Tracker Activity'), $clearform); // Build pagination, sorting, and limiting info $current_page = isset($_REQUEST['pg']) && is_numeric($_REQUEST['pg']) ? max(1, intval($_REQUEST['pg'])) : 1; $start = (max(1, $current_page) - 1) * Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'); $limit = Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'); // Build filter info $filters = array(); if (isset($_REQUEST['filter'])) { list($column, $value) = explode(':', $_REQUEST['filter'], 2); $values = explode(',', $value); $filters[$column] = array(); foreach ($values as $value) { $filters[$column][] = rawurldecode($value); } } // Fetch activity logs $logs = Tracker::fetchActivities($filters, $limit, $start); // Build the table $thead = array(array(__('Activity'), 'col'), array(__('Date'), 'col'), array(__('Time'), 'col')); $tbody = array(); // If there are no logs, display default message if (!is_array($logs) or empty($logs)) { $tbody = array(Widget::TableRow(array(Widget::TableData(__('No data available.'), 'inactive', null, count($thead))), 'odd')); } else { $bOdd = true; foreach ($logs as $activity) { // Format the date and time $date = DateTimeObj::get(__SYM_DATE_FORMAT__, strtotime($activity['timestamp'] . ' GMT')); $time = DateTimeObj::get(__SYM_TIME_FORMAT__, strtotime($activity['timestamp'] . ' GMT')); $description = Tracker::getDescription($activity); // Assemble the columns $col_date = Widget::TableData($date); $col_time = Widget::TableData($time); $col_desc = Widget::TableData($description); $col_desc->appendChild(Widget::Input("items[{$activity['id']}]", null, 'checkbox')); // Insert the row if (!is_null($description)) { $tbody[] = Widget::TableRow(array($col_desc, $col_date, $col_time), $bOdd ? 'odd' : NULL); $bOdd = !$bOdd; } } } // Assemble the table $table = Widget::Table(Widget::TableHead($thead), null, Widget::TableBody($tbody), null); $table->setAttribute('class', 'selectable'); $this->Form->appendChild($table); // Append table actions $options = array(array(null, false, __('With Selected...')), array('delete', false, __('Delete'))); $tableActions = new XMLElement('div'); $tableActions->setAttribute('class', 'actions'); $tableActions->appendChild(Widget::Apply($options)); $this->Form->appendChild($tableActions); // Append pagination $filter_sql = Tracker::buildFilterSQL($filters); $sql = ' SELECT count(id) as `count` FROM `tbl_tracker_activity`' . $filter_sql; $per_page = Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'); $total_entries = Symphony::Database()->fetchVar('count', 0, $sql); $remaining_entries = max(0, $total_entries - ($start + $per_page)); $total_pages = max(1, ceil($total_entries * (1 / $per_page))); $remaining_pages = max(0, $total - pages - $current_page); if ($total_pages > 1) { $ul = new XMLElement('ul'); $ul->setAttribute('class', 'page'); // First $li = new XMLElement('li'); if ($current_page > 1) { $li->appendChild(Widget::Anchor(__('First'), Administration::instance()->getCurrentPageURL() . '?pg=1')); } else { $li->setValue(__('First')); } $ul->appendChild($li); // Previous $li = new XMLElement('li'); if ($current_page > 1) { $li->appendChild(Widget::Anchor(__('← Previous'), Administration::instance()->getCurrentPageURL() . '?pg=' . ($current_page - 1))); } else { $li->setValue(__('← Previous')); } $ul->appendChild($li); // Summary $li = new XMLElement('li', __('Page %1$s of %2$s', array($current_page, max($current_page, $total_pages)))); $li->setAttribute('title', __('Viewing %1$s - %2$s of %3$s entries', array($start, $current_page != $total_pages ? $current_page * Symphony::Configuration()->get('pagination_maximum_rows', 'symphony') : $total_entries, $total_entries))); $ul->appendChild($li); // Next $li = new XMLElement('li'); if ($current_page < $total_pages) { $li->appendChild(Widget::Anchor(__('Next →'), Administration::instance()->getCurrentPageURL() . '?pg=' . ($current_page + 1))); } else { $li->setValue(__('Next →')); } $ul->appendChild($li); // Last $li = new XMLElement('li'); if ($current_page < $total_pages) { $li->appendChild(Widget::Anchor(__('Last'), Administration::instance()->getCurrentPageURL() . '?pg=' . $total_pages)); } else { $li->setValue(__('Last')); } $ul->appendChild($li); $this->Form->appendChild($ul); } }