Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-07-29 17:01:51 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-08-13 19:01:54 +0300
commit19a191af410868ab034cab4266f4234cbdd8a01f (patch)
tree385e47054289d9565b23e26ca2e6fea8af0d10ed /plugins/SitesManager
parent3306ffe5b65f83c075a1541a1578a0ebf3adbbde (diff)
refs #7700 return all websites my default for API method Sites.getPatternMatchSites
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r--plugins/SitesManager/API.php30
-rw-r--r--plugins/SitesManager/tests/System/ApiTest.php24
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager__SitesManager.getNumWebsitesToDisplayPerPage.xml2
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManagerwithLimit__SitesManager.getPatternMatchSites.xml39
4 files changed, 87 insertions, 8 deletions
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index 43f5b65661..8c182c47a5 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -1515,20 +1515,46 @@ class API extends \Piwik\Plugin\API
return true;
}
- public function getPatternMatchSites($pattern)
+ /**
+ * Find websites matching the given pattern.
+ *
+ * Any website will be returned that matches the pattern in the name, URL or group.
+ * To limit the number of returned sites you can either specify `filter_limit` as usual or `limit` which is
+ * faster.
+ *
+ * @param string $pattern
+ * @param int|false $limit
+ * @return array
+ */
+ public function getPatternMatchSites($pattern, $limit = false)
{
$ids = $this->getSitesIdWithAtLeastViewAccess();
if (empty($ids)) {
return array();
}
- $limit = SettingsPiwik::getWebsitesCountToDisplay();
$sites = $this->getModel()->getPatternMatchSites($ids, $pattern, $limit);
return $sites;
}
/**
+ * Returns the number of websites to display per page.
+ *
+ * For example this is used in the All Websites Dashboard, in the Website Selector etc. If multiple websites are
+ * shown somewhere, one should request this method to detect how many websites should be shown per page when
+ * using paging. To use paging is always recommended since some installations have thousands of websites.
+ *
+ * @return int
+ */
+ public function getNumWebsitesToDisplayPerPage()
+ {
+ Piwik::checkUserHasSomeViewAccess();
+
+ return SettingsPiwik::getWebsitesCountToDisplay();
+ }
+
+ /**
* Utility function that throws if a value is not valid for the 'keep_url_fragment'
* column of the piwik_site table.
*
diff --git a/plugins/SitesManager/tests/System/ApiTest.php b/plugins/SitesManager/tests/System/ApiTest.php
index 0f9301fdf5..d4cc198888 100644
--- a/plugins/SitesManager/tests/System/ApiTest.php
+++ b/plugins/SitesManager/tests/System/ApiTest.php
@@ -9,7 +9,6 @@
namespace Piwik\Plugins\SitesManager\tests\System;
use Piwik\Plugins\SitesManager\tests\Fixtures\ManySites;
-use Piwik\Plugins\SitesManager\tests\Fixtures\SimpleFixtureTrackFewVisits;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
/**
@@ -34,12 +33,25 @@ class ApiTest extends SystemTestCase
public function getApiForTesting()
{
- $api = array(
- 'SitesManager.getPatternMatchSites',
- );
-
$apiToTest = array();
- $apiToTest[] = array($api,
+ $apiToTest[] = array(array('SitesManager.getPatternMatchSites'),
+ array(
+ 'idSite' => 1,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => array('day'),
+ 'otherRequestParameters' => array('pattern' => 'SiteTest1')
+ )
+ );
+ $apiToTest[] = array(array('SitesManager.getPatternMatchSites'),
+ array(
+ 'idSite' => 1,
+ 'date' => self::$fixture->dateTime,
+ 'periods' => array('day'),
+ 'otherRequestParameters' => array('pattern' => 'SiteTest1', 'limit' => 2),
+ 'testSuffix' => 'withLimit'
+ )
+ );
+ $apiToTest[] = array(array('SitesManager.getNumWebsitesToDisplayPerPage'),
array(
'idSite' => 1,
'date' => self::$fixture->dateTime,
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager__SitesManager.getNumWebsitesToDisplayPerPage.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager__SitesManager.getNumWebsitesToDisplayPerPage.xml
new file mode 100644
index 0000000000..af45d2f01b
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager__SitesManager.getNumWebsitesToDisplayPerPage.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>15</result> \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManagerwithLimit__SitesManager.getPatternMatchSites.xml b/plugins/SitesManager/tests/System/expected/test_SitesManagerwithLimit__SitesManager.getPatternMatchSites.xml
new file mode 100644
index 0000000000..19de347831
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManagerwithLimit__SitesManager.getPatternMatchSites.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>
+ <row>
+ <idsite>1</idsite>
+ <name>SiteTest1</name>
+ <main_url>http://piwik.net</main_url>
+ <ts_created>2010-01-02 11:22:33</ts_created>
+ <ecommerce>0</ecommerce>
+ <sitesearch>1</sitesearch>
+ <sitesearch_keyword_parameters />
+ <sitesearch_category_parameters />
+ <timezone>UTC</timezone>
+ <currency>USD</currency>
+ <excluded_ips />
+ <excluded_parameters />
+ <excluded_user_agents />
+ <group />
+ <type>website</type>
+ <keep_url_fragment>0</keep_url_fragment>
+ </row>
+ <row>
+ <idsite>10</idsite>
+ <name>SiteTest10</name>
+ <main_url>http://piwik.net</main_url>
+ <ts_created>2010-01-02 11:22:33</ts_created>
+ <ecommerce>0</ecommerce>
+ <sitesearch>1</sitesearch>
+ <sitesearch_keyword_parameters />
+ <sitesearch_category_parameters />
+ <timezone>UTC</timezone>
+ <currency>USD</currency>
+ <excluded_ips />
+ <excluded_parameters />
+ <excluded_user_agents />
+ <group />
+ <type>website</type>
+ <keep_url_fragment>0</keep_url_fragment>
+ </row>
+</result> \ No newline at end of file