primo commit
This commit is contained in:
		
							
								
								
									
										130
									
								
								api/components/com_modules/src/Controller/ModulesController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								api/components/com_modules/src/Controller/ModulesController.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,130 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.API | ||||
|  * @subpackage  com_modules | ||||
|  * | ||||
|  * @copyright   (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Modules\Api\Controller; | ||||
|  | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\MVC\Controller\ApiController; | ||||
| use Joomla\Component\Modules\Administrator\Model\SelectModel; | ||||
| use Joomla\Component\Modules\Api\View\Modules\JsonapiView; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * The modules controller | ||||
|  * | ||||
|  * @since  4.0.0 | ||||
|  */ | ||||
| class ModulesController extends ApiController | ||||
| { | ||||
|     /** | ||||
|      * The content type of the item. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $contentType = 'modules'; | ||||
|  | ||||
|     /** | ||||
|      * The default view for the display method. | ||||
|      * | ||||
|      * @var    string | ||||
|      * @since  3.0 | ||||
|      */ | ||||
|     protected $default_view = 'modules'; | ||||
|  | ||||
|     /** | ||||
|      * Basic display of an item view | ||||
|      * | ||||
|      * @param   integer  $id  The primary key to display. Leave empty if you want to retrieve data from the request | ||||
|      * | ||||
|      * @return  static  A \JControllerLegacy object to support chaining. | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function displayItem($id = null) | ||||
|     { | ||||
|         $this->modelState->set('client_id', $this->getClientIdFromInput()); | ||||
|  | ||||
|         return parent::displayItem($id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Basic display of a list view | ||||
|      * | ||||
|      * @return  static  A \JControllerLegacy object to support chaining. | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function displayList() | ||||
|     { | ||||
|         $this->modelState->set('client_id', $this->getClientIdFromInput()); | ||||
|  | ||||
|         return parent::displayList(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return module items types | ||||
|      * | ||||
|      * @return  static  A \JControllerLegacy object to support chaining. | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function getTypes() | ||||
|     { | ||||
|         $viewType   = $this->app->getDocument()->getType(); | ||||
|         $viewName   = $this->input->get('view', $this->default_view); | ||||
|         $viewLayout = $this->input->get('layout', 'default', 'string'); | ||||
|  | ||||
|         try { | ||||
|             /** @var JsonapiView $view */ | ||||
|             $view = $this->getView( | ||||
|                 $viewName, | ||||
|                 $viewType, | ||||
|                 '', | ||||
|                 ['base_path' => $this->basePath, 'layout' => $viewLayout, 'contentType' => $this->contentType] | ||||
|             ); | ||||
|         } catch (\Exception $e) { | ||||
|             throw new \RuntimeException($e->getMessage()); | ||||
|         } | ||||
|  | ||||
|         /** @var SelectModel $model */ | ||||
|         $model = $this->getModel('select', '', ['ignore_request' => true]); | ||||
|  | ||||
|         if (!$model) { | ||||
|             throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE')); | ||||
|         } | ||||
|  | ||||
|         $model->setState('client_id', $this->getClientIdFromInput()); | ||||
|  | ||||
|         $view->setModel($model, true); | ||||
|  | ||||
|         $view->document = $this->app->getDocument(); | ||||
|  | ||||
|         $view->displayListTypes(); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get client id from input | ||||
|      * | ||||
|      * @return string | ||||
|      * | ||||
|      * @since 4.0.0 | ||||
|      */ | ||||
|     private function getClientIdFromInput() | ||||
|     { | ||||
|         return $this->input->exists('client_id') ? | ||||
|             $this->input->get('client_id') : $this->input->post->get('client_id'); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										141
									
								
								api/components/com_modules/src/View/Modules/JsonapiView.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								api/components/com_modules/src/View/Modules/JsonapiView.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,141 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.API | ||||
|  * @subpackage  com_modules | ||||
|  * | ||||
|  * @copyright   (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| namespace Joomla\Component\Modules\Api\View\Modules; | ||||
|  | ||||
| use Joomla\CMS\MVC\View\JsonApiView as BaseApiView; | ||||
| use Joomla\CMS\Router\Exception\RouteNotFoundException; | ||||
| use Joomla\Component\Modules\Administrator\Model\SelectModel; | ||||
|  | ||||
| // phpcs:disable PSR1.Files.SideEffects | ||||
| \defined('_JEXEC') or die; | ||||
| // phpcs:enable PSR1.Files.SideEffects | ||||
|  | ||||
| /** | ||||
|  * The modules view | ||||
|  * | ||||
|  * @since  4.0.0 | ||||
|  */ | ||||
| class JsonapiView extends BaseApiView | ||||
| { | ||||
|     /** | ||||
|      * The fields to render item in the documents | ||||
|      * | ||||
|      * @var  array | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $fieldsToRenderItem = [ | ||||
|         'id', | ||||
|         'typeAlias', | ||||
|         'asset_id', | ||||
|         'title', | ||||
|         'note', | ||||
|         'content', | ||||
|         'ordering', | ||||
|         'position', | ||||
|         'checked_out', | ||||
|         'checked_out_time', | ||||
|         'publish_up', | ||||
|         'publish_down', | ||||
|         'published', | ||||
|         'module', | ||||
|         'access', | ||||
|         'showtitle', | ||||
|         'params', | ||||
|         'client_id', | ||||
|         'language', | ||||
|         'assigned', | ||||
|         'assignment', | ||||
|         'xml', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|      * The fields to render items in the documents | ||||
|      * | ||||
|      * @var  array | ||||
|      * @since  4.0.0 | ||||
|      */ | ||||
|     protected $fieldsToRenderList = [ | ||||
|         'id', | ||||
|         'title', | ||||
|         'note', | ||||
|         'position', | ||||
|         'module', | ||||
|         'language', | ||||
|         'checked_out', | ||||
|         'checked_out_time', | ||||
|         'published', | ||||
|         'enabled', | ||||
|         'access', | ||||
|         'ordering', | ||||
|         'publish_up', | ||||
|         'publish_down', | ||||
|         'language_title', | ||||
|         'language_image', | ||||
|         'editor', | ||||
|         'access_level', | ||||
|         'pages', | ||||
|         'name', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|      * Execute and display a template script. | ||||
|      * | ||||
|      * @param   object  $item  Item | ||||
|      * | ||||
|      * @return  string | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function displayItem($item = null) | ||||
|     { | ||||
|         /** @var \Joomla\CMS\MVC\Model\AdminModel $model */ | ||||
|         $model = $this->getModel(); | ||||
|  | ||||
|         if ($item === null) { | ||||
|             $item  = $this->prepareItem($model->getItem()); | ||||
|         } | ||||
|  | ||||
|         if ($item->id === null) { | ||||
|             throw new RouteNotFoundException('Item does not exist'); | ||||
|         } | ||||
|  | ||||
|         if ((int) $model->getState('client_id') !== $item->client_id) { | ||||
|             throw new RouteNotFoundException('Item does not exist'); | ||||
|         } | ||||
|  | ||||
|         return parent::displayItem($item); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Execute and display a list modules types. | ||||
|      * | ||||
|      * @return  string | ||||
|      * | ||||
|      * @since   4.0.0 | ||||
|      */ | ||||
|     public function displayListTypes() | ||||
|     { | ||||
|         /** @var SelectModel $model */ | ||||
|         $model = $this->getModel(); | ||||
|         $items = []; | ||||
|  | ||||
|         foreach ($model->getItems() as $item) { | ||||
|             $item->id = $item->extension_id; | ||||
|             unset($item->extension_id); | ||||
|  | ||||
|             $items[] = $item; | ||||
|         } | ||||
|  | ||||
|         $this->fieldsToRenderList = ['id', 'name', 'module', 'xml', 'desc']; | ||||
|  | ||||
|         return $this->displayList($items); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user