<?php
namespace Moto\Application\ContentSection; use Moto\Json\Server; use Moto\Json\Request; use Moto\Json\Response; use Moto\Application\Util; use Moto; use Zend; class Service extends Moto\Service\AbstractStaticService { protected static $_resourceName = 'contentSection'; protected static $_resourcePrivilegesMap = array( 'getSettings' => 'get', ); public static function getSettings($type = 'blog') { $settings = Moto\Website\Settings::get('content_section_' . $type); if (!$settings) { $settings = (object) array(); } return $settings; } public static function setSettings($value, $type = 'blog') { $type = trim($type); $type = strtolower($type); $type = strip_tags($type); if (!preg_match('/^[a-z]{1,6}$/', $type)) { throw new Server\Exception(Moto\System\Exception::ERROR_BAD_REQUEST_MESSAGE, Moto\System\Exception::ERROR_BAD_REQUEST_CODE, array('type' => array('badSectionType'))); } $filter = new Moto\Application\ContentSection\InputFilter\Save(); $value = (array) $value; $settings = Moto\Website\Settings::get('content_section_' . $type); $settings = json_decode(json_encode($settings), true); $value = Zend\Stdlib\ArrayUtils::merge($settings, $value); $filter->setData($value); if (!$filter->isValid()) { throw new Server\Exception(Moto\System\Exception::ERROR_BAD_REQUEST_MESSAGE, Moto\System\Exception::ERROR_BAD_REQUEST_CODE, $filter->getMessagesKeys()); } $values = $filter->getValues(); $settings = Zend\Stdlib\ArrayUtils::merge($settings, $values); $settings = json_decode(json_encode($settings)); Moto\Website\Settings::set('content_section_' . $type, $settings); return static::getSettings($type); } }