idSite = $idSite; $this->idType = $idType; $this->storage = new Storage(Db::get(), $this->idSite); $this->pluginName = 'MeasurableSettings'; $this->init(); } protected function init() { $typeManager = new TypeManager(); $type = $typeManager->getType($this->idType); $type->configureMeasurableSettings($this); /** * This event is posted when generating settings for a Measurable (website). You can add any Measurable settings * that you wish to be shown in the Measurable manager (websites manager). If you need to add settings only for * eg MobileApp measurables you can use eg `$type->getId() === Piwik\Plugins\MobileAppMeasurable\Type::ID` and * add only settings if the condition is true. * * @since Piwik 2.14.0 * @deprecated will be removed in Piwik 3.0.0 * * @param MeasurableSettings $this * @param \Piwik\Measurable\Type $type * @param int $idSite */ Piwik::postEvent('Measurable.initMeasurableSettings', array($this, $type, $this->idSite)); } public function addSetting(Setting $setting) { if ($this->idSite && $setting instanceof MeasurableSetting) { $setting->writableByCurrentUser = Piwik::isUserHasAdminAccess($this->idSite); } parent::addSetting($setting); } public function save() { Piwik::checkUserHasAdminAccess($this->idSite); $typeManager = new TypeManager(); $type = $typeManager->getType($this->idType); /** * Triggered just before Measurable settings are about to be saved. You can use this event for example * to validate not only one setting but multiple ssetting. For example whether username * and password matches. * * @since Piwik 2.14.0 * @deprecated will be removed in Piwik 3.0.0 * * @param MeasurableSettings $this * @param \Piwik\Measurable\Type $type * @param int $idSite */ Piwik::postEvent('Measurable.beforeSaveSettings', array($this, $type, $this->idSite)); $this->storage->save(); } }