From 652eca35d707ef64faf4f518bdb82db817a9f63f Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Sun, 27 Jul 2014 11:26:42 +0200 Subject: refs #5887 use a model so we do not have to expose the method in the API. I tried to write a test for this but was not able to since lots of IntegrationTest magic --- plugins/SitesManager/API.php | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'plugins/SitesManager/API.php') diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 5c1702ad8b..8eca58f47b 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -180,14 +180,18 @@ class API extends \Piwik\Plugin\API public function getSiteFromId($idSite) { Piwik::checkUserHasViewAccess($idSite); - $site = Db::get()->fetchRow("SELECT * - FROM " . Common::prefixTable("site") . " - WHERE idsite = ?", $idSite); + + $site = $this->getModel()->getSiteFromId($idSite); Site::setSitesFromArray(array($site)); return $site; } + private function getModel() + { + return new Model(); + } + /** * Returns the list of alias URLs registered for the given idSite. * The website ID must be valid when calling this method! @@ -419,29 +423,12 @@ class API extends \Piwik\Plugin\API * @param bool $limit * @return array */ - public function getSitesFromIds($idSites, $limit = false) + private function getSitesFromIds($idSites, $limit = false) { - Piwik::checkUserHasViewAccess($idSites); - - if (count($idSites) === 0) { - return array(); - } - - if ($limit) { - $limit = "LIMIT " . (int)$limit; - } else { - $limit = ''; - } - - $idSites = array_map('intval', $idSites); - - $db = Db::get(); - $sites = $db->fetchAll("SELECT * - FROM " . Common::prefixTable("site") . " - WHERE idsite IN (" . implode(", ", $idSites) . ") - ORDER BY idsite ASC $limit"); + $sites = $this->getModel()->getSitesFromIds($idSites, $limit); Site::setSitesFromArray($sites); + return $sites; } -- cgit v1.2.3