getTypeFor() public static method

Returns the type of the site with the specified ID.
public static getTypeFor ( $idsite ) : string
$idsite
return string
Ejemplo n.º 1
0
 /**
  * Constructor.
  * @param int $idSite If creating settings for a new site that is not created yet, use idSite = 0
  * @param string|null $idMeasurableType If null, idType will be detected from idSite
  * @throws Exception
  */
 public function __construct($idSite, $idMeasurableType = null)
 {
     parent::__construct();
     $this->idSite = (int) $idSite;
     if (!empty($idMeasurableType)) {
         $this->idMeasurableType = $idMeasurableType;
     } elseif (!empty($idSite)) {
         $this->idMeasurableType = Site::getTypeFor($idSite);
     } else {
         throw new Exception('No idType specified for ' . get_class($this));
     }
     $this->init();
 }
Ejemplo n.º 2
0
 /**
  * one url => no change to alias urls
  */
 public function testUpdateSiteOneUrl()
 {
     $urls = array("http://piwiknew.com", "http://piwiknew.net", "http://piwiknew.org", "http://piwiknew.fr");
     $idsite = API::getInstance()->addSite("site1", $urls);
     $newMainUrl = "http://main.url";
     // Also test that the group was set to empty, and is searchable
     $websites = API::getInstance()->getSitesFromGroup('');
     $this->assertEquals(1, count($websites));
     // the Update doesn't change the group field
     API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl);
     $websites = API::getInstance()->getSitesFromGroup('');
     $this->assertEquals(1, count($websites));
     // Updating the group to something
     $group = 'something';
     API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = true, $ss_kwd = null, $ss_cat = '', $ips = null, $parametersExclude = null, $timezone = null, $currency = null, $group);
     $websites = API::getInstance()->getSitesFromGroup($group);
     $this->assertEquals(1, count($websites));
     $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($websites[0]['ts_created'])));
     // Updating the group to nothing
     $group = '';
     $type = 'mobileAppTest';
     API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = false, $ss_kwd = '', $ss_cat = null, $ips = null, $parametersExclude = null, $timezone = null, $currency = null, $group, $startDate = '2010-01-01', $excludedUserAgent = null, $keepUrlFragment = 1, $type);
     $websites = API::getInstance()->getSitesFromGroup($group);
     $this->assertEquals(1, count($websites));
     $this->assertEquals('2010-01-01', date('Y-m-d', strtotime($websites[0]['ts_created'])));
     // Test setting the website type
     $this->assertEquals($type, Site::getTypeFor($idsite));
     // Check Alias URLs contain only main url
     $allUrls = API::getInstance()->getSiteUrlsFromId($idsite);
     $this->assertEquals($newMainUrl, $allUrls[0]);
     $aliasUrls = array_slice($allUrls, 1);
     $this->assertEquals(array(), $aliasUrls);
 }
Ejemplo n.º 3
0
 /**
  * Update an existing website.
  * If only one URL is specified then only the main url will be updated.
  * If several URLs are specified, both the main URL and the alias URLs will be updated.
  *
  * @param int $idSite website ID defining the website to edit
  * @param string $siteName website name
  * @param string|array $urls the website URLs
  * @param int $ecommerce Whether Ecommerce is enabled, 0 or 1
  * @param null|int $siteSearch Whether site search is enabled, 0 or 1
  * @param string $searchKeywordParameters Comma separated list of search keyword parameter names
  * @param string $searchCategoryParameters Comma separated list of search category parameter names
  * @param string $excludedIps Comma separated list of IPs to exclude from being tracked (allows wildcards)
  * @param null|string $excludedQueryParameters
  * @param string $timezone Timezone
  * @param string $currency Currency code
  * @param string $group Group name where this website belongs
  * @param string $startDate Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
  * @param null|string $excludedUserAgents
  * @param int|null $keepURLFragments If 1, URL fragments will be kept when tracking. If 2, they
  *                                   will be removed. If 0, the default global behavior will be used.
  * @param string $type The Website type, default value is "website"
  * @param array|null $settings JSON serialized settings eg {settingName: settingValue, ...}
  * @throws Exception
  * @see getKeepURLFragmentsGlobal. If null, the existing value will
  *                                   not be modified.
  *
  * @return bool true on success
  */
 public function updateSite($idSite, $siteName = null, $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = null, $type = null, $settings = null)
 {
     Piwik::checkUserHasAdminAccess($idSite);
     $idSites = $this->getSitesId();
     if (!in_array($idSite, $idSites)) {
         throw new Exception("website id = {$idSite} not found");
     }
     // Build the SQL UPDATE based on specified updates to perform
     $bind = array();
     if (!is_null($siteName)) {
         $this->checkName($siteName);
         $bind['name'] = $siteName;
     }
     if (!is_null($urls)) {
         $urls = $this->cleanParameterUrls($urls);
         $this->checkUrls($urls);
         $this->checkAtLeastOneUrl($urls);
         $url = $urls[0];
         $bind['main_url'] = $url;
     }
     if (!is_null($currency)) {
         $currency = trim($currency);
         $this->checkValidCurrency($currency);
         $bind['currency'] = $currency;
     }
     if (!is_null($timezone)) {
         $timezone = trim($timezone);
         $this->checkValidTimezone($timezone);
         $bind['timezone'] = $timezone;
     }
     if (!is_null($group) && Piwik::hasUserSuperUserAccess()) {
         $bind['group'] = trim($group);
     }
     if (!is_null($ecommerce)) {
         $bind['ecommerce'] = (int) (bool) $ecommerce;
     }
     if (!is_null($startDate)) {
         $bind['ts_created'] = Date::factory($startDate)->getDatetime();
     }
     $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps);
     $bind['excluded_parameters'] = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters);
     $bind['excluded_user_agents'] = $this->checkAndReturnCommaSeparatedStringList($excludedUserAgents);
     if (!is_null($keepURLFragments)) {
         $keepURLFragments = (int) $keepURLFragments;
         self::checkKeepURLFragmentsValue($keepURLFragments);
         $bind['keep_url_fragment'] = $keepURLFragments;
     }
     $bind['sitesearch'] = $this->checkSiteSearch($siteSearch);
     list($searchKeywordParameters, $searchCategoryParameters) = $this->checkSiteSearchParameters($searchKeywordParameters, $searchCategoryParameters);
     $bind['sitesearch_keyword_parameters'] = $searchKeywordParameters;
     $bind['sitesearch_category_parameters'] = $searchCategoryParameters;
     if (!is_null($type)) {
         $bind['type'] = $this->checkAndReturnType($type);
     }
     if (!empty($settings)) {
         $this->validateMeasurableSettings(Site::getTypeFor($idSite), $settings);
     }
     $this->getModel()->updateSite($bind, $idSite);
     if (!empty($settings)) {
         $this->updateMeasurableSettings($idSite, $settings);
     }
     // we now update the main + alias URLs
     $this->getModel()->deleteSiteAliasUrls($idSite);
     if (count($urls) > 1) {
         $this->addSiteAliasUrls($idSite, array_slice($urls, 1));
     }
     $this->postUpdateWebsite($idSite);
 }