/** * Save a chartconfig entity to the database * * @param ChartConfig $config * @return boolean */ public function save(ChartConfig $config) { $id = $config->getId(); if (!empty($id)) { $query = $this->db->prepareQuery('UPDATE *PREFIX*uc_chartconfig SET created = ?, username = ?, charttype = ?, chartprovider = ?, metadata = ? WHERE id = ?'); $query->execute(array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider(), $config->getMetaData(), $config->getId())); } else { $query = $this->db->prepareQuery('INSERT INTO *PREFIX*uc_chartconfig(created, username, charttype, chartprovider, metadata) VALUES (?,?,?,?,?)'); $query->execute(array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider(), $config->getMetaData())); } return true; }
/** * @return array */ public function findAllPerMonth() { $sql = 'SELECT DISTINCT CONCAT(MONTH(`created`), \' \', YEAR(`created`)) as month, avg(`usage`) as average, username FROM oc_uc_storageusage WHERE `usage` > 0 GROUP BY username, month'; $query = $this->db->prepareQuery($sql); $result = $query->execute(); $entities = array(); while ($row = $result->fetch()) { if (!isset($entities[$row['username']])) { $entities[$row['username']] = array(); } $date = explode(' ', $row['month']); $dateTime = new \Datetime(); $dateTime->setDate($date[1], $date[0], 1); $entities[$row['username']] = array_merge($entities[$row['username']], array(new StorageUsage($dateTime, $row['average'], $row['username']))); } return $entities; }
/** * Save a chartconfig entity to the database * * @param ChartConfig $config */ public function save(ChartConfig $config) { $query = $this->db->prepareQuery('INSERT INTO oc_uc_chartconfig(created, username, charttype, chartprovider) VALUES (?,?,?,?)'); $query->execute(Array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider())); }
/** * @brief Add a set of tags for a bookmark * @param IDb $db Database Interface * @param int $bookmarkID The bookmark reference * @param array $tags Set of tags to add to the bookmark * @return null * */ private static function addTags(IDb $db, $bookmarkID, $tags) { $sql = 'INSERT INTO `*PREFIX*bookmarks_tags` (`bookmark_id`, `tag`) select ?, ? '; $dbtype = \OCP\Config::getSystemValue('dbtype', 'sqlite'); if ($dbtype === 'mysql') { $sql .= 'from dual '; } $sql .= 'where not exists(select * from `*PREFIX*bookmarks_tags` where `bookmark_id` = ? and `tag` = ?)'; $query = $db->prepareQuery($sql); foreach ($tags as $tag) { $tag = trim($tag); if (empty($tag)) { //avoid saving white spaces continue; } $params = array($bookmarkID, $tag, $bookmarkID, $tag); $query->execute($params); } }