Commit 8b2e743a authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '6050-review-interface-for-supann-affectation-role-and-subscription' into '1.4-dev'

Resolve "Review interface for SupAnn affectation, role and subscription"

See merge request fusiondirectory/fd-plugins!721
parents 81ec869c 4b85382c
......@@ -24,6 +24,8 @@ class supannAccount extends simplePlugin
{
protected $displayHeader = TRUE;
protected $entitesCache = [];
static function plInfo (): array
{
return [
......@@ -330,12 +332,13 @@ class supannAccount extends simplePlugin
/* list of entity stored in LDAP tree */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=supannEntite)', ['supannCodeEntite', 'ou', 'o','supannEtablissement','description']);
$ldap->search('(objectClass=supannEntite)', ['supannCodeEntite','supannTypeEntite','ou','o','supannEtablissement','description']);
$code_entites = [];
$label_entites = [];
$code_etablissements = [];
$label_etablissements = [];
$this->entitesCache = [];
while ($attrs = $ldap->fetch()) {
if (isset($attrs['supannCodeEntite'][0])) {
$code_entites[] = $attrs['supannCodeEntite'][0];
......@@ -359,13 +362,16 @@ class supannAccount extends simplePlugin
$label_etablissements[] = $attrs['o'][0].' ('.$attrs['supannEtablissement'][$i].')';
}
}
$this->entitesCache[$attrs['supannCodeEntite'][0]] = $attrs;
}
}
array_multisort($label_entites, $code_entites);
array_multisort($label_etablissements, $code_etablissements);
$this->attributesAccess['supannEntiteAffectation']->attribute->setChoices($code_entites, $label_entites);
$this->attributesAccess['supannEtuInscription']->attribute->attributes[6]->setChoices($code_entites, $label_entites);
$this->attributesAccess['supannEtablissement']->attribute->setChoices($code_etablissements, $label_etablissements);
$this->attributesAccess['supannEtuInscription']->attribute->attributes[0]->setChoices($code_etablissements, $label_etablissements);
$this->supannInit();
}
......@@ -389,23 +395,39 @@ class supannAccount extends simplePlugin
]);
$this->attributesAccess['supannEtuInscription']->setLinearRendering(FALSE);
$this->updateFieldsChoices();
$this->updateFieldsChoicesAndValues();
}
/* Update choices of fields which depends on other fields values */
function updateFieldsChoices ()
protected function updateFieldsChoicesAndValues ()
{
global $config;
/* Values */
$supannEtablissement = $this->supannEtablissement;
$supannEntiteAffectation = $this->supannEntiteAffectation;
foreach ($this->supannEtuInscription as $inscription) {
$values = $this->attributesAccess['supannEtuInscription']->attribute->readValues($inscription);
$supannEtablissement[] = $values[0];
$supannEntiteAffectation[] = $values[6];
}
$this->supannEtablissement = array_values(array_unique($supannEtablissement));
$this->supannEntiteAffectation = array_values(array_unique($supannEntiteAffectation));
$supannTypeEntiteAffectation = $this->supannTypeEntiteAffectation;
foreach ($this->supannEntiteAffectation as $code) {
if (isset($this->entitesCache[$code]['supannTypeEntite'][0])) {
$supannTypeEntiteAffectation[] = $this->entitesCache[$code]['supannTypeEntite'][0];
}
}
$this->supannTypeEntiteAffectation = array_values(array_unique($supannTypeEntiteAffectation));
/* Choices */
$code_ent = $this->attributesAccess['supannEntiteAffectation']->getValue();
$label_ent = $this->attributesAccess['supannEntiteAffectation']->getDisplayValues();
$this->attributesAccess['supannEntiteAffectationPrincipale']->setChoices(
$code_ent, $label_ent
);
$code_etab = $this->attributesAccess['supannEtablissement']->getValue();
$label_etab = $this->attributesAccess['supannEtablissement']->getDisplayValues();
// supannEtablissement
$this->attributesAccess['supannEtuInscription']->attribute->attributes[0]->setChoices($code_etab, $label_etab);
// supannEntiteAffectation
$this->attributesAccess['supannEtuInscription']->attribute->attributes[6]->setChoices($code_ent, $label_ent);
// supannEntiteAffectation
$this->attributesAccess['supannRoleEntite']->attribute->attributes[2]->setChoices($code_ent, $label_ent);
$code_tent = $this->attributesAccess['supannTypeEntiteAffectation']->getValue();
......@@ -434,13 +456,13 @@ class supannAccount extends simplePlugin
function save_object ()
{
parent::save_object();
$this->updateFieldsChoices();
$this->updateFieldsChoicesAndValues();
}
function adapt_from_template (array $attrs, array $skip = [])
{
parent::adapt_from_template($attrs, $skip);
$this->updateFieldsChoices();
$this->updateFieldsChoicesAndValues();
}
protected function prepare_save (): array
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment