local:moodlescript:syntaxspecification

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
local:moodlescript:syntaxspecification [2018/03/06 14:17]
admin [Arguments, identifiers and variables]
local:moodlescript:syntaxspecification [2024/05/14 15:39] (current)
Line 106: Line 106:
 Called in a moodlescript stack context, it will compute the category idnumber of the current user, so we can write a moodlescript move instruction as follows, moving the current course to the adequate destination:​ Called in a moodlescript stack context, it will compute the category idnumber of the current user, so we can write a moodlescript move instruction as follows, moving the current course to the adequate destination:​
  
-    MOVE current TO idnumber:​func:​local_ent_installer@get_teacher_cat_idnumber ​+    MOVE COURSE ​current TO idnumber:​func:​local_ent_installer@get_teacher_cat_idnumber ​
  
 === Literal Argument === === Literal Argument ===
Line 136: Line 136:
 ==== Special keywords (metas) ==== ==== Special keywords (metas) ====
  
-===**current**===+==='current'===
  
 '​current'​ is a special keyword in place of an expected identifier that will resolve into the nearest current object in the executing environment. F.e, if the expected object is a user identifier, current will resolve to $USER->​id. If '​current'​ addresses a course identifier, it wil usually resolve as $COURSE->​id,​ unless another course id is given to the execution stack by the global context (for plugin developers). '​current'​ is a special keyword in place of an expected identifier that will resolve into the nearest current object in the executing environment. F.e, if the expected object is a user identifier, current will resolve to $USER->​id. If '​current'​ addresses a course identifier, it wil usually resolve as $COURSE->​id,​ unless another course id is given to the execution stack by the global context (for plugin developers).
Line 150: Line 150:
 For enrolling the current user (the $USER being executing the script) into the current course. For enrolling the current user (the $USER being executing the script) into the current course.
  
-===**last** or **first**===+==='last' ​or 'first'===
  
 this usually addresses the first available or last available item in the current syntax context. this is used f.e. for blocks location in a region, but might also address any object locaton being sorted with a sortorder attribute. this usually addresses the first available or last available item in the current syntax context. this is used f.e. for blocks location in a region, but might also address any object locaton being sorted with a sortorder attribute.
 +
 +==='​runtime'​===
 +
 +Usually identifiers and variable can be evaluated at parse time or at check time, because they are litterals in the script, or they come from some input or global context. But this is not true in all cases. Lets take an example:
 +
 +In the following scriptlet:
 +
 +   ADD CATEGORY "New category"​ TO idnumber:​EXISTINGCAT HAVING
 +   ​idnumber:​ NEWCAT
 +   
 +   MOVE COURSE idnumber:​SOMECOURSE TO idnumber:​NEWCAT
 +
 +We run into an issue because at parse time or at check time, NEWCAT category is not yet created. Thus we must tell the engine that in the second statement, we need the engine waiting the latest moment to evaulate the identifier to move the course in.
 +
 +This can be done by the special keywork runtime: and we'll rewrite the scriplet as follows:
 +
 +   ADD CATEGORY "New category"​ TO idnumber:​EXISTINGCAT HAVING
 +   ​idnumber:​ NEWCAT
 +   
 +   MOVE COURSE idnumber:​SOMECOURSE TO runtime:​idnumber:​NEWCAT
 +
 +Using the runtime: special keyword will prevent the parser to evaluate and resolve the identifier, and will store it's initial definition in the handler class. The handler will also NOT try to resolve it at check time, as check time only checks the conditions of execution of all the statements without executing them. At real execution time, the identifier will be resolved to get it's definitive actual value.
 +
 +Note that '​runtime'​ variables may raise a real error situation that cannot be recovered or anticipated by the engine and may terminate in a tecnhical failure of the script and the calling process. ​
  
 [[:​local:​moodlescript|Return to component index]] ​ [[:​local:​moodlescript|Return to component index]] ​
local/moodlescript/syntaxspecification.1520342249.txt.gz · Last modified: 2024/04/04 15:50 (external edit)