Criteres and $GLOBALS

Hello dear SPIP Community.

I’m working on a project where certain information is defined in PHP’s the $GLOBALS variable at runtime.

It’s possible to create custom criteria for boucles, in « mes_fonctions.php » file.

However, even through the page I am opening in the browser is defining the $GLOBALS[‹ list_challenges ›] variable before the criteria is called in the boucle, the variable is empty inside the criteria.

Is it possible to work with GLOBALS inside criteria functions?

Example:

<BOUCLE_mission(MISSIONS){missions_completed}>

#ID_MISSION

</BOUCLE_mission>

The criteria is defined as such:

function critere_mission_completed($idb, &$boucles, $crit) {
$boucle = &$boucles[$idb];

$list_challenges = $GLOBALS[‹ list_challenges ›];

$boucle->where[] = array("‹ id_mission IN ($list_challenges) ›");

}

Expected: $list_challenges contains the global variable defied earlier.

Actual: $list_challenges is empty, as global variable is not defined for some reason.

Cheers,

Urs

Le 02/08/2018 à 16:41, Urs Riggenbach via spip-en a écrit :

I'm working on a project where certain information is defined in PHP's the $GLOBALS variable at runtime.
It's possible to create custom criteria for boucles, in "mes_fonctions.php" file.
However, even through the page I am opening in the browser is defining the $GLOBALS['list_challenges'] variable before the criteria is called in the boucle, the variable is empty inside the criteria.
*Is it possible to work with GLOBALS inside criteria functions?*

Dont forget SPIP caches all of its results.
Criteria are evaluated once and wont be evaluated again whenever the global changes, but only when the cache expires.
Can't this explain your issue ?

so your solution probably depends on "when" the list_challenges is set or changed.

JL

Example:

<BOUCLE_mission(MISSIONS){*missions_completed*}>

#ID_MISSION

</BOUCLE_mission>

The criteria is defined as such:

function critere_*mission_completed*($idb, &$boucles, $crit) {
$boucle = &$boucles[$idb];

 $list\_challenges = \*$GLOBALS\[&#39;list\_challenges&#39;\];\*

 $boucle\-&gt;where\[\] = array\(&quot;&#39;id\_mission IN \($list\_challenges\)&#39;&quot;\);

}

Expected: $list_challenges contains the global variable defied earlier.

Actual: $list_challenges is empty, as global variable is not defined for some reason.

Cheers,

Urs

--
Urs Riggenbach
Energy - Webdesign - Consulting

Weissensteinstrasse 76
4500 Solothurn
Switzerland

+41 79 918 0663 (CH)
+358 45 872 3836 (FI)

https://ursrig.com

Important: This email is confidential and may be privileged.
If you are not the intended recipient, please delete
it and notify us immediately; you should not copy
or use it for any purpose, nor disclose its contents
to any other person. Thank you.