* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBStatistic'); /** * Statistic module for VFS File views * * Simple interface to save file view statistic * * @version 0.1.2 * @package WB * @subpackage base */ class WBStatistic_VFSFile extends WBStatistic { /** * name of page view table */ const TABLE = 'vfsfileview'; /** * add file id * * Save id in statistic table * * @param string $path * @param string $namespace */ public function add($id) { if (!$this->enabled) { return; } if (empty($id)) { return; } $key = $this->table->getIdentifier('vfsfile'); $uid = $this->user->getId(); if (!$uid) { $uid = 0; } $save = array( 'trackid' => $this->getTrackingId(), $key => $id, 'addr' => $this->getAddress(), $this->uPrimary => $uid, ); if ($this->sess->has(WBStatistic::SESS_KEY_HINT)) { $save['hint'] = $this->sess->get(WBStatistic::SESS_KEY_HINT); } $this->table->save(self::TABLE, '__new', $save); } /** * count file views * * Count views of file in general or for specified user. * * @param string $id * @param string $user * @return int */ public function count($id, $user = null) { if (!$this->enabled) { return 0; } if (empty($id)) { return 0; } $clause = array(); if (!is_null($user)) { $clause[] = array( 'field' => $this->uPrimary, 'value' => $user ); } return $this->table->count(self::TABLE, null, $id, $clause); } } ?>