Beispiel #1
0
 public function is_available($not, \core_availability\info $info, $grabthelot, $userid)
 {
     $context = \context_course::instance($info->get_course()->id);
     $allow = true;
     if (!has_capability('moodle/site:accessallgroups', $context, $userid)) {
         // If the activity has 'group members only' and you don't have accessallgroups...
         $groups = $info->get_modinfo()->get_groups($this->get_grouping_id($info));
         if (!$groups) {
             // ...and you don't belong to a group, then set it so you can't see/access it.
             $allow = false;
         }
         // The NOT condition applies before accessallgroups (i.e. if you
         // set something to be available to those NOT in grouping X,
         // people with accessallgroups can still access it even if
         // they are in grouping X).
         if ($not) {
             $allow = !$allow;
         }
     }
     return $allow;
 }
Beispiel #2
0
 public function is_available($not, \core_availability\info $info, $grabthelot, $userid)
 {
     $course = $info->get_course();
     $context = \context_course::instance($course->id);
     $allow = true;
     if (!has_capability('moodle/site:accessallgroups', $context, $userid)) {
         // Get all groups the user belongs to.
         $groups = $info->get_modinfo()->get_groups();
         if ($this->groupid) {
             $allow = in_array($this->groupid, $groups);
         } else {
             // No specific group. Allow if they belong to any group at all.
             $allow = $groups ? true : false;
         }
         // The NOT condition applies before accessallgroups (i.e. if you
         // set something to be available to those NOT in group X,
         // people with accessallgroups can still access it even if
         // they are in group X).
         if ($not) {
             $allow = !$allow;
         }
     }
     return $allow;
 }
 public function get_description($full, $not, \core_availability\info $info)
 {
     // Get name for module.
     $modinfo = $info->get_modinfo();
     if (!array_key_exists($this->cmid, $modinfo->cms)) {
         $modname = get_string('missing', 'availability_completion');
     } else {
         $modname = '<AVAILABILITY_CMNAME_' . $modinfo->cms[$this->cmid]->id . '/>';
     }
     // Work out which lang string to use.
     if ($not) {
         // Convert NOT strings to use the equivalent where possible.
         switch ($this->expectedcompletion) {
             case COMPLETION_INCOMPLETE:
                 $str = 'requires_' . self::get_lang_string_keyword(COMPLETION_COMPLETE);
                 break;
             case COMPLETION_COMPLETE:
                 $str = 'requires_' . self::get_lang_string_keyword(COMPLETION_INCOMPLETE);
                 break;
             default:
                 // The other two cases do not have direct opposites.
                 $str = 'requires_not_' . self::get_lang_string_keyword($this->expectedcompletion);
                 break;
         }
     } else {
         $str = 'requires_' . self::get_lang_string_keyword($this->expectedcompletion);
     }
     return get_string($str, 'availability_completion', $modname);
 }
 public function get_description($full, $not, \core_availability\info $info)
 {
     // Get name for module.
     $modinfo = $info->get_modinfo();
     if (!isset($this->expectedpublicprivate)) {
         $modname = get_string('missing', 'availability_publicprivate');
     }
     //        // Work out which lang string to use.
     //        if ($not) {
     //            // Convert NOT strings to use the equivalent where possible.
     //            switch ($this->expectedpublicprivate) {
     //                case COMPLETION_INCOMPLETE:
     //                    $str = 'requires_' . self::get_lang_string_keyword(COMPLETION_COMPLETE);
     //                    break;
     //                case COMPLETION_COMPLETE:
     //                    $str = 'requires_' . self::get_lang_string_keyword(COMPLETION_INCOMPLETE);
     //                    break;
     //                default:
     //                    // The other two cases do not have direct opposites.
     //                    $str = 'requires_not_' . self::get_lang_string_keyword($this->expectedpublicprivate);
     //                    break;
     //            }
     //        } else {
     //            $str = 'requires_' . self::get_lang_string_keyword($this->expectedpublicprivate);
     //        }
     if ($this->expectedpublicprivate === PUBLICPRIVATE_PRIVATE) {
         $str = 'requires_private';
     } else {
         $str = 'requires_public';
     }
     return get_string($str, 'availability_publicprivate');
 }