|
@@ -24,17 +24,29 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
|
|
|
// Currently selected choices
|
|
|
protected $selected = [];
|
|
|
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $webserviceParameter;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var boolean
|
|
|
+ */
|
|
|
+ protected $filterTenancy;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param Webservice $webservice
|
|
|
* @param TenancyService $tenancyService Contiene el servicio de tenencias.
|
|
|
*/
|
|
|
- public function __construct($webservice, $tenancyService)
|
|
|
+ public function __construct($webservice, $tenancyService, $webserviceParameter = 'client', $filterTenancy = true)
|
|
|
{
|
|
|
$this->webservice = $webservice;
|
|
|
$this->tenancyService = $tenancyService;
|
|
|
+ $this->webserviceParameter = $webserviceParameter;
|
|
|
+ $this->filterTenancy = $filterTenancy;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param FormBuilderInterface $builder
|
|
|
*/
|
|
@@ -81,9 +93,9 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
|
|
|
public function loadChoiceList($value = null)
|
|
|
{
|
|
|
$choices = $this->getChoicesList(false);
|
|
|
-
|
|
|
+
|
|
|
$missing_choices = array_flip($this->selected);
|
|
|
-
|
|
|
+
|
|
|
foreach ($choices as $label => $id) {
|
|
|
if (isset($missing_choices[$id])) {
|
|
|
unset($missing_choices[$id]);
|
|
@@ -135,6 +147,7 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
|
|
|
$result = [];
|
|
|
foreach ($choices as $id) {
|
|
|
if ($this->choiceExists($id)) {
|
|
|
+ $this->selected = array($id);
|
|
|
$result[] = $id;
|
|
|
}
|
|
|
}
|
|
@@ -154,9 +167,12 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
|
|
|
$params = array();
|
|
|
if ($filter !== false) {
|
|
|
$params['name'] = urlencode($filter);
|
|
|
- $params['tenancyId'] = $this->tenancyService->getTenancyIdCurrent();
|
|
|
+ if ($this->filterTenancy) {
|
|
|
+ $params['tenancyId'] = $this->tenancyService->getTenancyIdCurrent();
|
|
|
+ }
|
|
|
}
|
|
|
- $choices = $this->webservice->getChoices('client', $params);
|
|
|
+
|
|
|
+ $choices = $this->webservice->getChoices($this->webserviceParameter, $params);
|
|
|
|
|
|
$result = [];
|
|
|
$cnt = 0;
|
|
@@ -189,7 +205,7 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
|
|
|
*/
|
|
|
protected function getChoiceLabel($id)
|
|
|
{
|
|
|
- $label = array_search($id, $this->initChoices());
|
|
|
+ $label = array_search($id, $this->initChoices(array("id" => $id)));
|
|
|
|
|
|
return $label === false ? false : $label;
|
|
|
}
|
|
@@ -200,7 +216,7 @@ class ClientChoiceLoader implements ChoiceLoaderInterface
|
|
|
*/
|
|
|
protected function initChoices($params = array())
|
|
|
{
|
|
|
- return $this->webservice->getChoices('client', $params);
|
|
|
+ return $this->webservice->getChoices($this->webserviceParameter, $params);
|
|
|
}
|
|
|
|
|
|
}
|