| <?php |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Plugins\CustomVariables; |
|
|
| use Piwik\Tracker\Cache; |
|
|
| class CustomVariables extends \Piwik\Plugin |
| { |
| public const MAX_NUM_CUSTOMVARS_CACHEKEY = 'CustomVariables.MaxNumCustomVariables'; |
|
|
| |
| |
| |
| public function registerEvents() |
| { |
| return array( |
| 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', |
| 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', |
| 'Dimension.addDimensions' => 'addDimensions', |
| 'Actions.getCustomActionDimensionFieldsAndJoins' => 'provideActionDimensionFields', |
| 'Tracker.setTrackerCacheGeneral' => 'getCacheGeneral', |
| 'Tracker.getVisitFieldsToPersist' => 'getVisitFieldsToPersist' |
| ); |
| } |
|
|
| public function install() |
| { |
| Model::install(); |
| } |
|
|
| public function uninstall() |
| { |
| Model::uninstall(); |
| } |
|
|
| public function addDimensions(&$instances) |
| { |
| foreach (Model::getScopes() as $scope) { |
| $model = new Model($scope); |
| try { |
| $highestIndex = $model->getHighestCustomVarIndex(); |
| } catch (\Exception $e) { |
| continue; |
| } |
|
|
| foreach (range(1, $highestIndex) as $index) { |
| $custom = new CustomDimension(); |
| $custom->initCustomDimension($index, $model); |
| $instances[] = $custom; |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| public static function getMaxLengthCustomVariables() |
| { |
| return 200; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public static function getNumUsableCustomVariables() |
| { |
| $cache = Cache::getCacheGeneral(); |
| $cacheKey = self::MAX_NUM_CUSTOMVARS_CACHEKEY; |
|
|
| if (isset($cache[$cacheKey])) { |
| return $cache[$cacheKey]; |
| } |
|
|
| return 0; |
| } |
|
|
| public function getCacheGeneral(&$cacheContent) |
| { |
| $cacheContent[self::MAX_NUM_CUSTOMVARS_CACHEKEY] = self::fetchNumMaxCustomVariables(); |
| } |
|
|
| private static function fetchNumMaxCustomVariables() |
| { |
| $minCustomVar = null; |
|
|
| foreach (Model::getScopes() as $scope) { |
| $model = new Model($scope); |
| $highestIndex = $model->getHighestCustomVarIndex(); |
|
|
| if (!isset($minCustomVar)) { |
| $minCustomVar = $highestIndex; |
| } |
|
|
| if ($highestIndex < $minCustomVar) { |
| $minCustomVar = $highestIndex; |
| } |
| } |
|
|
| if (!isset($minCustomVar)) { |
| $minCustomVar = 0; |
| } |
|
|
| return $minCustomVar; |
| } |
|
|
| public function getClientSideTranslationKeys(&$translationKeys) |
| { |
| $translationKeys[] = 'CustomVariables_CustomVariables'; |
| $translationKeys[] = 'CustomVariables_ManageDescription'; |
| $translationKeys[] = 'CustomVariables_ScopeX'; |
| $translationKeys[] = 'CustomVariables_Index'; |
| $translationKeys[] = 'CustomVariables_Usages'; |
| $translationKeys[] = 'CustomVariables_Unused'; |
| $translationKeys[] = 'CustomVariables_CreateNewSlot'; |
| $translationKeys[] = 'CustomVariables_UsageDetails'; |
| $translationKeys[] = 'CustomVariables_CurrentAvailableCustomVariables'; |
| $translationKeys[] = 'CustomVariables_ToCreateCustomVarExecute'; |
| $translationKeys[] = 'CustomVariables_CreatingCustomVariableTakesTime'; |
| $translationKeys[] = 'CustomVariables_SlotsReportIsGeneratedOverTime'; |
| $translationKeys[] = 'General_Loading'; |
| $translationKeys[] = 'General_TrackingScopeVisit'; |
| $translationKeys[] = 'General_TrackingScopePage'; |
| } |
|
|
| public function getStylesheetFiles(&$stylesheets) |
| { |
| $stylesheets[] = "plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.less"; |
| } |
|
|
| public function provideActionDimensionFields(&$fields, &$joins) |
| { |
| $maxCustomVariables = CustomVariables::getNumUsableCustomVariables(); |
|
|
| for ($i = 1; $i <= $maxCustomVariables; $i++) { |
| $fields[] = 'custom_var_k' . $i; |
| $fields[] = 'custom_var_v' . $i; |
| } |
| } |
|
|
| public function getVisitFieldsToPersist(&$fields) |
| { |
| for ($index = 1; $index <= CustomVariables::getNumUsableCustomVariables(); $index++) { |
| $fields[] = 'custom_var_k' . $index; |
| $fields[] = 'custom_var_v' . $index; |
| } |
| } |
| } |
|
|