diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-07-27 13:26:42 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-07-27 13:26:42 +0400 |
commit | 652eca35d707ef64faf4f518bdb82db817a9f63f (patch) | |
tree | f7fcff552b5f2668052d662561eb7bcc9c9dae68 /plugins/SitesManager | |
parent | 038771c897e7a91cb6f3aa5978dac0db0d0e11b4 (diff) |
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
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r-- | plugins/SitesManager/API.php | 33 | ||||
-rw-r--r-- | plugins/SitesManager/Model.php | 62 |
2 files changed, 72 insertions, 23 deletions
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; } diff --git a/plugins/SitesManager/Model.php b/plugins/SitesManager/Model.php new file mode 100644 index 0000000000..9e77f48888 --- /dev/null +++ b/plugins/SitesManager/Model.php @@ -0,0 +1,62 @@ +<?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\Plugins\SitesManager; + +use Piwik\Db; +use Piwik\Common; +use Exception; + +class Model +{ + /** + * Returns the list of websites from the ID array in parameters. + * + * @param array $idSites list of website ID + * @param bool $limit + * @return array + */ + public function getSitesFromIds($idSites, $limit = false) + { + 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"); + + return $sites; + } + + /** + * Returns the website information : name, main_url + * + * @throws Exception if the site ID doesn't exist or the user doesn't have access to it + * @param int $idSite + * @return array + */ + public function getSiteFromId($idSite) + { + $site = Db::get()->fetchRow("SELECT * + FROM " . Common::prefixTable("site") . " + WHERE idsite = ?", $idSite); + + return $site; + } +} |