<?php
namespace Modules\Admin\EntityMngWsAccounts;

class View_Utils_SetAccess extends \App\Mvc\View_Utils_FormAbstract
{
	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		// new form
		$form = \Engine\Form\General::create();

		// get full list of entities and operations including plugins
		$accountAccessConfig = new \Modules\Admin\EntityMngWsAccounts\AccountAccessConfig();
		$accessLevelArr = $accountAccessConfig->getAccountAvailableAccess();

		// show checkboxes
		foreach($accessLevelArr as $entity => $operations) {

			$possibleValuesArr = [];
			$fieldset = \Engine\Form\Container\Fieldset::create();
			$checkbox = new \Engine\Form\Input\Checkboxes($this->lang['entities'][$entity], 'accessLevel['.$entity.']', $this->values['accessLevel'][$entity]);
			if (!$entity) {
				$checkbox = new \Engine\Form\Input\Checkboxes($this->lang['index']['generalOperations'], 'accessLevel[generalOperations]', $this->values['accessLevel']['generalOperations']);
			}

			foreach(array_keys($operations) as $operation) {
				$possibleValuesArr[$operation] = $this->lang['entityOperation'][$operation];
			}

			$checkbox->setPossibleValues($possibleValuesArr);
			$fieldset->addElement($checkbox);
			$form->addContainer($fieldset);
		}

		// submit button
		$form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1));

		return $form;
	}
}