The Context of Markup vs Expressions of Equality in Determining the Meaning of Angled Brackets

In the WordPress editor (html mode) you’ll need to become friends with < and > if you plan on showing any code (php, html… xml, most languages actually) that readers will want to understand.

I never thought about it, but assumed that the lt and gt stood for left, and gt, well, i couldn’t quite place it, respectively. But alas, it dawned on me. Lt = less than while gt = greater than. Seems obvious now, but when you are thinking about angled brackets as markup, rather than as logic in an expression, the meaning that has value happens to be left vs. right.

Context is important.

How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function

After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of the shark infested, murky water that is the Moodle code base .

How do I check if a user is a course creator for a given course? I’m still not 100% sure, the access control policy seems needlessly confusing on first glance and even after reading the heady and mostly pointless, expose on how roles/perms are calculated (Available Here: http://docs.moodle.org/en/How_permissions_are_calculated ) If you notice the section titled “Some Practical Examples” is 100% empty! (I’ve added my code to the wiki so not 100% empty any longer) The most useful part of the docs are completely empty! Instead boatloads of time went into a treatise on the internals and lovely graphs like this one

But you could always hop into the forum dedicated just to this chunk of the code base (Available here: http://moodle.org/mod/forum/view.php?f=941&page=0) and search through the 500 topics w/ 5000+(i didn’t actually count) nested discussions (including version 1.7 of moodle as well).

No, instead, ACK came to the rescue and I found a snippet that performed the task.

Without further ado

$context = get_context_instance(CONTEXT_COURSE, $course-&gt;id);
if (has_capability('moodle/course:update', $coursecontext)) {
  /** do stuff here */
}

There it is. That could have saved me an hour if mentioned in the docs!