diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/DataAccess/RawLogFetcher.php | 55 | ||||
-rw-r--r-- | core/DataAccess/RawLogUpdater.php | 79 |
2 files changed, 134 insertions, 0 deletions
diff --git a/core/DataAccess/RawLogFetcher.php b/core/DataAccess/RawLogFetcher.php new file mode 100644 index 0000000000..ec1f7d14ce --- /dev/null +++ b/core/DataAccess/RawLogFetcher.php @@ -0,0 +1,55 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\DataAccess; + +use Piwik\Common; +use Piwik\Db; + +/** + * DAO that queries log tables. + */ +class RawLogFetcher +{ + /** + * @param string $from + * @param string $to + * @param array $fields + * @param int $fromId + * @param int $limit + * @return array + */ + public function getVisitsWithDatesLimit($from, $to, $fields = array(), $fromId = 0, $limit = 1000) + { + $sql = "SELECT " . implode(', ', $fields) + . " FROM " . Common::prefixTable('log_visit') + . " WHERE visit_first_action_time >= ? AND visit_last_action_time < ?" + . " AND idvisit > ?" + . sprintf(" LIMIT %d", $limit); + + $bind = array($from, $to, $fromId); + + return Db::fetchAll($sql, $bind); + } + + /** + * @param string $from + * @param string $to + * @return int + */ + public function countVisitsWithDatesLimit($from, $to) + { + $sql = "SELECT COUNT(*) AS num_rows" + . " FROM " . Common::prefixTable('log_visit') + . " WHERE visit_first_action_time >= ? AND visit_last_action_time < ?"; + + $bind = array($from, $to); + + return (int) Db::fetchOne($sql, $bind); + } +}
\ No newline at end of file diff --git a/core/DataAccess/RawLogUpdater.php b/core/DataAccess/RawLogUpdater.php new file mode 100644 index 0000000000..72337c6ad4 --- /dev/null +++ b/core/DataAccess/RawLogUpdater.php @@ -0,0 +1,79 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\DataAccess; + +use Piwik\Common; +use Piwik\Db; + +class RawLogUpdater +{ + /** + * @param array $values + * @param string $idVisit + */ + public function updateVisits(array $values, $idVisit) + { + $sql = array( + "UPDATE " . Common::prefixTable('log_visit'), + "SET " . $this->getColumnBinds(array_keys($values)), + "WHERE idvisit = ?" + ); + + $this->executeQuery($sql, $values, $idVisit); + } + + /** + * @param array $values + * @param string $idVisit + */ + public function updateConversions(array $values, $idVisit) + { + $sql = array( + "UPDATE " . Common::prefixTable('log_conversion'), + "SET " . $this->getColumnBinds(array_keys($values)), + "WHERE idvisit = ?" + ); + + $this->executeQuery($sql, $values, $idVisit); + } + + /** + * @param array $columnsToSet + * @return string + */ + protected function getColumnBinds(array $columnsToSet) + { + $columnsToSet = array_map( + function ($column) { + return sprintf('%s = ?', $column); + }, + $columnsToSet + ); + + return implode(', ', $columnsToSet); + } + + /** + * @param array $values + * @param $idVisit + * @param $sql + * @return \Zend_Db_Statement + * @throws \Exception + */ + protected function executeQuery($sql, array $values, $idVisit) + { + return Db::query( + implode(' ', $sql), + array_merge( + array_values($values), + array($idVisit) + ) + ); + } +}
\ No newline at end of file |