Skip to content
Snippets Groups Projects
TsrefController.php 4.14 KiB
Newer Older
damjan's avatar
damjan committed
<?php
damjan's avatar
damjan committed
namespace SGalinski\TypoScriptReferenceFrontend\Controller;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "SGalinski.TypoScriptReferenceFrontend".*
 *                                                                        *
 *                                                                        */

use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Attribute;
use SGalinski\TypoScriptReferenceFrontend\Service\TsrefRestService;
damjan's avatar
damjan committed
use SGalinski\TypoScriptReferenceFrontend\Utilities\Conversion;
damjan's avatar
damjan committed
use TYPO3\Flow\Annotations as Flow;

class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
damjan's avatar
damjan committed
	/**
	 * @var TsrefRestService
	 */
	protected $tsrefRestService;

	/**
	 * The constructor is used for dependency injection.
	 *
	 * @param TsrefRestService $service
	 */
	public function __construct(TsrefRestService $service) {
		$this->tsrefRestService = $service;
	}

	/**
	 * The action which fetches the data for typoScript reference page, and displays the page.
	 * @param int $typeId
	 * @return void
damjan's avatar
damjan committed
	 */
	public function indexAction($typeId = NULL) {
			$selectedType = $this->tsrefRestService->getAttributeById($typeId);
			$properties = $this->tsrefRestService->getPropertiesByParentId($typeId);
			$this->view->assign('properties', $properties);
			$this->view->assign('selectedType', $selectedType);
damjan's avatar
damjan committed
			$this->view->assign('selectedTypeId', $typeId);
			// If the type extends a type (superType), the superType name is being fetched among other fields
			if (isset($selectedType->parent_id)) {
				$superType = $this->tsrefRestService->getAttributeById($selectedType->parent_id);
				$this->view->assign('superType', $superType);
			}
damjan's avatar
damjan committed
		$types = Conversion::toAssociativeIdNamesArray($this->tsrefRestService->getTypes());
		$this->view->assign('types', $types);
damjan's avatar
damjan committed
	}

	/**
	 * Adds a new type.
	 *
	 * @param Attribute $theType
damjan's avatar
damjan committed
	 * @param boolean $editForm
	 * @return void
	 */
damjan's avatar
damjan committed
	public function submitTypeAction(Attribute $theType, $editForm) {
		if ($editForm) {
			$result = $this->tsrefRestService->editAttribute($theType);
damjan's avatar
damjan committed
		} else {
			$result = $this->tsrefRestService->addNewAttribute($theType);
damjan's avatar
damjan committed
		}
damjan's avatar
damjan committed
		// TODO: Return error message. Or success message.
damjan's avatar
damjan committed
		$this->forward('index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend');
	}

	/**
	 * Prepares and opens the page for adding new / editing the type
	 * @param int $theTypeId
	 */
	public function editTypeAction($theTypeId = NULL) {
		$theType = new Attribute();

		if ($theTypeId !== NULL) {
			// Edit type
			$selectedTypeAsStdClass = $this->tsrefRestService->getAttributeById($theTypeId);
			$theType->initialiseAttribute($selectedTypeAsStdClass);
			$this->view->assign('selectedType', $selectedTypeAsStdClass);
damjan's avatar
damjan committed
			$this->view->assign('selectedTypeId', $theTypeId);
		}

		$types = $this->tsrefRestService->getTypes();
damjan's avatar
damjan committed
		$associativeTypes = Conversion::toAssociativeIdNamesArray($types);
		$typo3Groups = $this->tsrefRestService->getAllTypo3Groups();

		$this->view->assign('typo3Groups', $typo3Groups);
damjan's avatar
damjan committed
		$this->view->assign('types', $associativeTypes);
		$this->view->assign('theType', $theType);
		$this->view->assign('editForm', ($theTypeId !== NULL));
damjan's avatar
damjan committed

	/**
	 * Prepares and opens the page for adding new / editing the property
	 *
	 * @param int $parentTypeId
	 * @param int $thePropertyId
	 */
	public function editPropertyAction($parentTypeId, $thePropertyId = NULL) {
//		$theProperty = new Attribute();
//
//		if ($thePropertyId !== NULL) {
//			// Edit type
//			$selectedPropertyAsStdClass = $this->tsrefRestService->getAttributeById($thePropertyId);
//			$theProperty->initialiseAttribute($selectedPropertyAsStdClass);
//			$this->view->assign('selectedType', $selectedTypeAsStdClass);
//		}
//
//		$types = $this->tsrefRestService->getTypes();
//		$associativeTypes = Conversion::toAssociativeIdNamesArray($types);
//		$typo3Groups = $this->tsrefRestService->getAllTypo3Groups();
//
//		$this->view->assign('typo3Groups', $typo3Groups);
//		$this->view->assign('types', $associativeTypes);
//		$this->view->assign('theType', $theProperty);
//		$this->view->assign('editForm', ($thePropertyId !== NULL));
	}
damjan's avatar
damjan committed
}