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:
authordiosmosis <benaka@piwik.pro>2014-09-18 07:40:38 +0400
committerdiosmosis <benaka@piwik.pro>2014-09-18 07:40:38 +0400
commit41fabcb3488f00f5840dc2c231519488322b1837 (patch)
tree32021d167f45a4047e0195841fbb4fba8eed167f /core/Plugin/ComponentFactory.php
parentaafb07c75b86b7905da1d7525e2800c8dbad2cde (diff)
Adding new PivotByDimension DataTable filter that can pivot a report by (almost) any dimension. The filter can pivot reports by their subtable dimension and can also pivot by other dimensions (by using segments).
Notes: - in the UI, only pivoting by subtable is supported - change to CSV DataTable renderer so column names w/ commas & quotes can appear in text - change to XML DataTable renderer so column names w/ invalid XML characters can be rendered (bit of an iffy change, XML format needs an overhaul I think) - includes new config option 'pivot_by_filter_enable_fetch_by_segment' - includes additions to component metadata classes (ie, Report/Dimension)
Diffstat (limited to 'core/Plugin/ComponentFactory.php')
-rw-r--r--core/Plugin/ComponentFactory.php85
1 files changed, 74 insertions, 11 deletions
diff --git a/core/Plugin/ComponentFactory.php b/core/Plugin/ComponentFactory.php
index 02cb6083e1..68415e9397 100644
--- a/core/Plugin/ComponentFactory.php
+++ b/core/Plugin/ComponentFactory.php
@@ -37,20 +37,14 @@ class ComponentFactory
public static function factory($pluginName, $componentClassSimpleName, $componentTypeClass)
{
if (empty($pluginName) || empty($componentClassSimpleName)) {
+ Log::debug("ComponentFactory::%s: empty plugin name or component simple name requested (%s, %s)",
+ __FUNCTION__, $pluginName, $componentClassSimpleName);
+
return null;
}
- $pluginManager = PluginManager::getInstance();
-
- try {
- if (!$pluginManager->isPluginActivated($pluginName)) {
- return null;
- }
-
- $plugin = $pluginManager->getLoadedPlugin($pluginName);
- } catch (Exception $e) {
- Log::debug($e);
-
+ $plugin = self::getActivatedPlugin(__FUNCTION__, $pluginName);
+ if (empty($plugin)) {
return null;
}
@@ -63,6 +57,75 @@ class ComponentFactory
return new $class();
}
}
+
+ Log::debug("ComponentFactory::%s: Could not find requested component (args = ['%s', '%s', '%s']).",
+ __FUNCTION__, $pluginName, $componentClassSimpleName, $componentTypeClass);
+
+ return null;
+ }
+
+ /**
+ * Finds a component instance that satisfies a given predicate.
+ *
+ * @param string $componentTypeClass The fully qualified class name of the component type, eg,
+ * `"Piwik\Plugin\Report"`.
+ * @param string $pluginName|false The name of the plugin the component is expected to belong to,
+ * eg, `'UserSettings'`.
+ * @param callback $predicate
+ * @return mixed The component that satisfies $predicate or null if not found.
+ */
+ public static function getComponentIf($componentTypeClass, $pluginName, $predicate)
+ {
+ $pluginManager = PluginManager::getInstance();
+
+ // get components to search through
+ $subnamespace = $componentTypeClass::COMPONENT_SUBNAMESPACE;
+ if (empty($pluginName)) {
+ $components = $pluginManager->findMultipleComponents($subnamespace, $componentTypeClass);
+ } else {
+ $plugin = self::getActivatedPlugin(__FUNCTION__, $pluginName);
+ if (empty($plugin)) {
+ return null;
+ }
+
+ $components = $plugin->findMultipleComponents($subnamespace, $componentTypeClass);
+ }
+
+ // find component that satisfieds predicate
+ foreach ($components as $class) {
+ $component = new $class();
+ if ($predicate($component)) {
+ return $component;
+ }
+ }
+
+ Log::debug("ComponentFactory::%s: Could not find component that satisfies predicate (args = ['%s', '%s', '%s']).",
+ __FUNCTION__, $componentTypeClass, $pluginName, get_class($predicate));
+
return null;
}
+
+ /**
+ * @param string $function
+ * @param string $pluginName
+ * @return null|\Piwik\Plugin
+ */
+ private static function getActivatedPlugin($function, $pluginName)
+ {
+ $pluginManager = PluginManager::getInstance();
+ try {
+ if (!$pluginManager->isPluginActivated($pluginName)) {
+ Log::debug("ComponentFactory::%s: component for deactivated plugin ('%s') requested.",
+ $function, $pluginName);
+
+ return null;
+ }
+
+ return $pluginManager->getLoadedPlugin($pluginName);
+ } catch (Exception $e) {
+ Log::debug($e);
+
+ return null;
+ }
+ }
} \ No newline at end of file