Problem with $DB query

Problem with $DB query

by Nik M -
Number of replies: 1

Hello !

I am creating an availability restriction plugin and I have the following problem.

In the is_available function I defined all the conditions but  I can't make  a correct query to the database.

I want to take all records from course_modules_completion table  which are selected in the restriction.

I have defined a   protected $selected_activities variable  which I use in the class (condition.php) to contain the values of the selected_activities.

I am using $this->selected_activities  as an array  from which I can get  the selected activities

My question is:  How I can store the values of these selected activities in  the query string. I am using the following code  but I receive a wrong query.     The 'coursemoduleid' key should  receive the correct $modID.   I have two variables for $passed_activities because I have  two kinds of 'completionstate'  which I have to use for my conditions.


foreach ($this->selected_activities as $modID) 

 {

    $passed_activities1 = $DB->get_records('course_modules_completion', ['coursemoduleid' => $modID,'userid' => $userid, 'completionstate' => 1]);

    $passed_activities2 = $DB->get_records('course_modules_completion', ['coursemoduleid' => $modID,'userid' => $userid, 'completionstate' => 2]);

 }



Thank you in advance ! 


Average of ratings: -