* @package WB * @subpackage content */ /** * Load required class */ WBClass::load('WBContent' , 'WBContent_TableEditor'); /** * Content component: TableEditor_TackId * * @version 0.1.0 * @package WB * @subpackage content */ class WBContent_TableEditor_TrackId extends WBContent_TableEditor { const TABLE_PAGEVIEW = 'pageview'; const TABLE_TRACKID = 'tracklink'; const TABLE_LINKTRACKING = 'linktracking'; /** * 2nd constructor * * Reset template folder */ protected function init() { parent::init(); $this->config['table'] = self::TABLE_TRACKID; $this->config['tmplDir'] = 'TableEditor'; } /** * Actually Run Action: Display * * @param array * @param string * @param string */ protected function runDisplay($p, $foreign, $tmplDir) { if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('TableEditor/anon', false); return; } $this->loadTemplates('display'); $this->tmpl->addGlobalVars($p); if ($this->tmpl->exists('most_list_entry')) { $count = $this->getCount(); $list = $this->getTrackedMost(); $this->tmpl->addGlobalVar('most_count', $count); $this->tmpl->addRows('most_list_entry', $list); } if ($this->tmpl->exists('most90_list_entry')) { $count = $this->getCount(90); $list = $this->getTrackedMost(90); $this->tmpl->addGlobalVar('most90_count', $count); $this->tmpl->addRows('most90_list_entry', $list); } if ($this->tmpl->exists('most28_list_entry')) { $count = $this->getCount(28); $list = $this->getTrackedMost(28); $this->tmpl->addGlobalVar('most28_count', $count); $this->tmpl->addRows('most28_list_entry', $list); } if ($this->tmpl->exists('most7_list_entry')) { $count = $this->getCount(7); $list = $this->getTrackedMost(7); $this->tmpl->addGlobalVar('most7_count', $count); $this->tmpl->addRows('most7_list_entry', $list); } } private function getCount($days = null) { $clause = array(); $opt = array( 'column' => array(), ); $opt['column'][] = array( 'table' => self::TABLE_PAGEVIEW, 'field' => 'path', 'function' => 'count', 'as' => 'cnt' ); $list = $this->getTrackinStat($days, $clause, $opt); if (1 != count($list)) { return 0; } return $list[0]['cnt']; } private function getTrackedMost($days = null) { $clause = array(); $opt = array( 'column' => array(), 'limit' => 200, 'groupby' => array( 'field' => 'path', 'table' => self::TABLE_PAGEVIEW ), 'order' => array( array( 'field' => 'field', 'native' => 'cnt', 'asc' => 0 ) ) ); $opt['column'][] = array( 'table' => self::TABLE_PAGEVIEW, 'field' => 'path' ); $opt['column'][] = array( 'table' => self::TABLE_PAGEVIEW, 'field' => 'path', 'function' => 'count', 'as' => 'cnt' ); return $this->getTrackinStat($days, $clause, $opt); } private function getTrackinStat($days = null, $clause = array(), $opt = array()) { $pLink = $this->table->getIdentifier(self::TABLE_TRACKID); $clause[] = array( 'table' => self::TABLE_LINKTRACKING, 'field' => $pLink, 'value' => $this->id ); $clause[] = array( 'table' => self::TABLE_PAGEVIEW, 'field' => 'namespace', 'value' => 'site' ); $clause[] = array( 'table' => self::TABLE_PAGEVIEW, 'field' => 'counter', 'value' => 1 ); if ($days) { $since = strtotime('-' . $days . 'days'); $clause[] = array( 'table' => self::TABLE_PAGEVIEW, 'field' => 'created', 'relation' => 'ge', 'value' => gmdate('Y-m-d 00:00:00', $since) ); } if (!isset($opt['join'])) { $opt['join'] = array(); } $opt['join'][] = array( 'table' => self::TABLE_LINKTRACKING, 'using' => 'trackid', ); return $this->table->get(self::TABLE_PAGEVIEW, null, null, $clause, $opt); } }