Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/DataAccess/RawLogDao.php109
1 files changed, 109 insertions, 0 deletions
diff --git a/core/DataAccess/RawLogDao.php b/core/DataAccess/RawLogDao.php
new file mode 100644
index 0000000000..28f2a07978
--- /dev/null
+++ b/core/DataAccess/RawLogDao.php
@@ -0,0 +1,109 @@
+<?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 RawLogDao
+{
+ /**
+ * @param array $values
+ * @param string $idVisit
+ */
+ public function updateVisits(array $values, $idVisit)
+ {
+ $sql = "UPDATE " . Common::prefixTable('log_visit')
+ . " SET " . $this->getColumnSetExpressions(array_keys($values))
+ . " WHERE idvisit = ?";
+
+ $this->update($sql, $values, $idVisit);
+ }
+
+ /**
+ * @param array $values
+ * @param string $idVisit
+ */
+ public function updateConversions(array $values, $idVisit)
+ {
+ $sql = "UPDATE " . Common::prefixTable('log_conversion')
+ . " SET " . $this->getColumnSetExpressions(array_keys($values))
+ . " WHERE idvisit = ?";
+
+ $this->update($sql, $values, $idVisit);
+ }
+
+ /**
+ * @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);
+ }
+
+ /**
+ * @param array $columnsToSet
+ * @return string
+ */
+ protected function getColumnSetExpressions(array $columnsToSet)
+ {
+ $columnsToSet = array_map(
+ function ($column) {
+ return $column . ' = ?';
+ },
+ $columnsToSet
+ );
+
+ return implode(', ', $columnsToSet);
+ }
+
+ /**
+ * @param array $values
+ * @param $idVisit
+ * @param $sql
+ * @return \Zend_Db_Statement
+ * @throws \Exception
+ */
+ protected function update($sql, array $values, $idVisit)
+ {
+ return Db::query($sql, array_merge(array_values($values), array($idVisit)));
+ }
+} \ No newline at end of file