diff options
author | benakamoorthi <benaka.moorthi@gmail.com> | 2011-12-26 03:44:45 +0400 |
---|---|---|
committer | benakamoorthi <benaka.moorthi@gmail.com> | 2011-12-26 03:44:45 +0400 |
commit | 6e8ae94fc44bb42b34e5ed9070cbd10dcf01a3d4 (patch) | |
tree | d87850c41d4ea591b2bc299c2cb4a57fdb6bd95d /core/Site.php | |
parent | cea387bf2de590e6d7e4c4a79e01770bd4243e8e (diff) |
Fixes #2810. Refactored MultiSites plugin:
* Created MultiSites API w/ getAll method that gets visit/action/revenue & related evolution data for all sites.
* Modified MultiSites Controller to use aforementioned API.
* Fixed bug I introduced in integration tests, method doTest_TwoVisitors_twoWebsites_differentDays shouldn't allow tests to skip the API.getProcessedReport test.
* Added mergeChildren & related unit test to Piwik_DataTable_Array.
* Added static methods to Piwik_Site to get site data using an ID. Using it avoids having to create a new Piwik_Site instance.
* Modified ColumnCallbackAddColumnQuotient so it can be better extended and so it's possible to avoid processing rows if desired.
git-svn-id: http://dev.piwik.org/svn/trunk@5626 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/Site.php')
-rw-r--r-- | core/Site.php | 114 |
1 files changed, 112 insertions, 2 deletions
diff --git a/core/Site.php b/core/Site.php index 5619458934..8989c0123c 100644 --- a/core/Site.php +++ b/core/Site.php @@ -22,10 +22,10 @@ class Piwik_Site function __construct($idsite) { - $this->id = $idsite; + $this->id = (int)$idsite; if(!isset(self::$infoSites[$this->id])) { - self::$infoSites[$this->id] = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite); + self::$infoSites[$this->id] = Piwik_SitesManager_API::getInstance()->getSiteFromId($this->id); } } @@ -147,4 +147,114 @@ class Piwik_Site { self::$infoSites = array(); } + + /** + * Utility function. Returns the value of the specified field for the + * site with the specified ID. + * + * @param int|string $idsite The ID of the site whose data is being + * accessed. + * @param string $field The name of the field to get. + * @return mixed + */ + static protected function getFor($idsite, $field) + { + $idsite = (int)$idsite; + + if (!isset(self::$infoSites[$idsite])) + { + self::$infoSites[$idsite] = Piwik_SitesManager_API::getInstance()->getSiteFromId($idsite); + } + + return self::$infoSites[$idsite][$field]; + } + + /** + * Returns the name of the site with the specified ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getNameFor($idsite) + { + return self::getFor($idsite, 'name'); + } + + /** + * Returns the timezone of the site with the specified ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getTimezoneFor($idsite) + { + return self::getFor($idsite, 'timezone'); + } + + /** + * Returns the creation date of the site with the specified ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getCreationDateFor($idsite) + { + return self::getFor($idsite, 'ts_created'); + } + + /** + * Returns the url for the site with the specified ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getMainUrlFor($idsite) + { + return self::getFor($idsite, 'main_url'); + } + + /** + * Returns whether the site with the specified ID is ecommerce enabled + * + * @param int $idsite The site ID. + * @return string + */ + static public function isEcommerceEnabledFor($idsite) + { + return self::getFor($idsite, 'ecommerce') == 1; + } + + /** + * Returns the currency of the site with the specified ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getCurrencyFor($idsite) + { + return self::getFor($idsite, 'currency'); + } + + /** + * Returns the excluded IP addresses of the site with the specified ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getExcludedIpsFor($idsite) + { + return self::getFor($idsite, 'excluded_ips'); + } + + /** + * Returns the excluded query parameters for the site with the specified + * ID. + * + * @param int $idsite The site ID. + * @return string + */ + static public function getExcludedQueryParametersFor($idsite) + { + return self::getFor($idsite, 'excluded_parameters'); + } } |