I need to extract a specific value from a table knowing the id of the row in moodle
screenshot of the table
I tried previously to get the variable from another php class but no matter what it gives null so I get the idea if there is a method to get this value directly from the database table
the table name ‘mdl_course_modules’
the id is the same as course module id
and need to extract this value from the column ‘availability’
Edit
I tried to use the following
$viewslim = $DB->get_field_select('course_modules', 'availability' , "`availability` LIKE '%maxviews%' AND `id` = '$cm->id'",['id' => $cm->id], IGNORE_MISSING);
preg_match_all('/(d+)/', $viewslim , $matches);
echo '<pre>'; var_dump($matches); echo '</pre>';
it worked fine but if there is another integer in the line due to another active availability plugin, so how to get only the value after viewlimit only not any other possible integer in the line
{"op":"&","c":[{"type":"maxviews","viewslimit":"1"}],"showc":[true]}
that is what I get from var_dump
array(2) {
[0]=>
array(1) {
[0]=>
string(1) "1"
}
[1]=>
array(1) {
[0]=>
string(1) "1"
}
}
2
Answers
I get it, I hope it works fine till the end
and it results exactly what I need
There might be more than one availability condition, including more than one maxviews
Maybe use the existing availability code instead of a database query – it looks like you already know the
$cm->id
so will go from there