<?php

namespace App\Form\Input;

class Cloned_AutocompleteMiceProject extends \Engine\Form\Input\Cloned_Autocomplete
{

	protected $class = "clonedAutocomplete";

	/**
	 * The constructor for the cloned autocomplete MICE project.
	 * @param String $label
	 * @param String $name
	 * @param Array $value
	 */
	public function __construct($label=null, $name=null, $value=null)
	{
		parent::__construct($label, $name, $value);
		$this->url = \Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/RemoteData/AutocompleteFieldData', '', ['class'=>'MiceProject']);
	}


	protected function getTemplateParams($templateClass = null, $parentElement = null)
	{
		$params = parent::getTemplateParams($templateClass, $parentElement );

		if (is_array($params['value'])) {
			foreach($params['value'] as $key=>$elem) {
				if ($elem['id']) $params['value'][$key]['title']=\Entity\MiceProject::select($elem['id'])->name;
			}
		}

		return $params;

	}

}