<?php
namespace Moto\Application\Widgets; use Moto; use Moto\Json\Request; use Moto\Json\Server; use Moto\Json\Response; class Service extends Moto\Service\AbstractStaticService { protected static $_resourceName = 'widgets'; public static function deleteStorageFile($request = null) { if (null === $request) { $request = static::getRequest()->getParams(); } $inputFilter = new InputFilter\DeleteStorageFile(); $inputFilter->setData($request); if (!$inputFilter->isValid()) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_BAD_REQUEST_MESSAGE, Moto\System\Exception::ERROR_BAD_REQUEST_CODE, $inputFilter->getMessagesKeys()); } $value = $inputFilter->getValue('id'); if (Moto\System\Widgets\Storage::isExists($value)) { return Moto\System\Widgets\Storage::deleteById($value); } throw new Moto\System\Exception(Moto\System\Exception::ERROR_NOT_FOUND_MESSAGE, Moto\System\Exception::ERROR_NOT_FOUND_CODE); } public static function saveStorageFile($request = null) { if (null === $request) { $request = static::getRequest()->getParams(); } if (empty($request['widget']) || !is_array($request['widget'])) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_BAD_REQUEST_MESSAGE, Moto\System\Exception::ERROR_BAD_REQUEST_CODE, array( 'widget' => 'invalidFormat', )); } $widget = Moto\System\Widgets\Factory::create($request['widget']); if (!$widget) { throw new Moto\System\Exception(Moto\System\Exception::ERROR_NOT_FOUND_MESSAGE, Moto\System\Exception::ERROR_NOT_FOUND_CODE); } if (method_exists($widget, 'saveStorageFile')) { return $widget->saveStorageFile(true); } return false; } }