/** * Updates content settings and does any necessary API requests * * @param TinypassContentSettings $contentSettings * @param array $updatedData Request array with updated content settings values * * @return TinypassContentSettings */ public function saveContentSettings(TinypassContentSettings $contentSettings, $updatedData) { // Get charge option before update $originalChargeOption = $contentSettings->chargeOption(); $chargeOption = isset($updatedData[$contentSettings->chargeOptionPropertyName()]) ? $updatedData[$contentSettings->chargeOptionPropertyName()] : ''; // Set possible values $contentSettings->chargeOption($chargeOption)->resourceIds(isset($updatedData[$chargeOption][$contentSettings->resourceIdsPropertyName()]) ? $updatedData[$chargeOption][$contentSettings->resourceIdsPropertyName()] : null)->pppPrice(isset($updatedData[$chargeOption][$contentSettings->pppPricePropertyName()]) ? $updatedData[$chargeOption][$contentSettings->pppPricePropertyName()] : null)->pppCurrency(isset($updatedData[$chargeOption][$contentSettings->pppCurrencyPropertyName()]) ? $updatedData[$chargeOption][$contentSettings->pppCurrencyPropertyName()] : null); // Check for valid settings and set to proper settings (if required) $contentSettings->validate($this->businessModel(), $this->enablePayPerPost(), $this->algorithmicKeyAvailable()); if ($this->algorithmicKeyAvailable()) { if ($originalChargeOption == $contentSettings::CHARGE_OPTION_ALGORITHMIC && $originalChargeOption != $contentSettings->chargeOption()) { // If algorithmic keying is enabled and if previously keying was set to "algorithmic" and now changed to something else - make request to unkey it $this->unwatchAlgorithmic($contentSettings); } elseif ($contentSettings->chargeOption() != $contentSettings::CHARGE_OPTION_ALGORITHMIC) { // If algorithmic keying is enabled and current charge option is not algorithmic - make request to unkey content $this->unkeyAlgorithmic($contentSettings); } } switch ($contentSettings->chargeOption()) { case $contentSettings::CHARGE_OPTION_ALGORITHMIC: // If algorithmic keying is enabled and it's the desired charge option - make request to save it $this->saveAlgorithmic($contentSettings); break; case $contentSettings::CHARGE_OPTION_SUBSCRIPTION: if ($contentSettings->hasPayPerPost()) { // If pay-per-post option was selected - save it $contentSettings = $this->savePayPerPost($contentSettings); } } return $contentSettings; }
public function sanitizeDefaultAccessSettings() { if (is_array(self::$default_access_settings)) { $contentSettings = new TinypassContentSettings(); $chargeOption = isset(self::$default_access_settings[$contentSettings->chargeOptionPropertyName()]) ? self::$default_access_settings[$contentSettings->chargeOptionPropertyName()] : null; $contentSettings->chargeOption($chargeOption)->resourceIds(isset(self::$default_access_settings[$chargeOption][$contentSettings->resourceIdsPropertyName()]) ? self::$default_access_settings[$chargeOption][$contentSettings->resourceIdsPropertyName()] : null)->pppPrice(isset(self::$default_access_settings[$chargeOption][$contentSettings->pppPricePropertyName()]) ? self::$default_access_settings[$chargeOption][$contentSettings->pppPricePropertyName()] : null)->pppCurrency(isset(self::$default_access_settings[$chargeOption][$contentSettings->pppCurrencyPropertyName()]) ? self::$default_access_settings[$chargeOption][$contentSettings->pppCurrencyPropertyName()] : null); $contentSettings->validate(self::$business_model, self::$enable_ppp, self::$tinypass->algorithmicKeyAvailable(), $this->getResources()); $this->setOption(self::OPTION_NAME_DEFAULT_ACCESS_SETTINGS, $contentSettings->toArray()); } }