original_string: public static function search_cohorts($query, $context, $includes = 'parents', $limitfrom = 0, $limitnum = 25) {
          global $CFG;
          require_once($CFG->dirroot . '/cohort/lib.php');
  
          $params = self::validate_parameters(self::search_cohorts_parameters(), array(
              'query' => $query,
              'context' => $context,
              'includes' => $includes,
              'limitfrom' => $limitfrom,
              'limitnum' => $limitnum,
          ));
          $query = $params['query'];
          $includes = $params['includes'];
          $context = self::get_context_from_params($params['context']);
          $limitfrom = $params['limitfrom'];
          $limitnum = $params['limitnum'];
  
          self::validate_context($context);
  
          $manager = has_capability('moodle/cohort:manage', $context);
          if (!$manager) {
              require_capability('moodle/cohort:view', $context);
          }
  
          // TODO Make this more efficient.
          if ($includes == 'self') {
              $results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
              $results = $results['cohorts'];
          } else if ($includes == 'parents') {
              $results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
              $results = $results['cohorts'];
              if (!$context instanceof context_system) {
                  $results = array_merge($results, cohort_get_available_cohorts($context, COHORT_ALL, $limitfrom, $limitnum, $query));
              }
          } else if ($includes == 'all') {
              $results = cohort_get_all_cohorts($limitfrom, $limitnum, $query);
              $results = $results['cohorts'];
          } else {
              throw new coding_exception('Invalid parameter value for \'includes\'.');
          }
  
          $cohorts = array();
          foreach ($results as $key => $cohort) {
              $cohortcontext = context::instance_by_id($cohort->contextid);
  
              // Only return theme when $CFG->allowcohortthemes is enabled.
              if (!empty($cohort->theme) && empty($CFG->allowcohortthemes)) {
                  $cohort->theme = null;
              }
  
              if (!isset($cohort->description)) {
                  $cohort->description = '';
              }
              if (!isset($cohort->descriptionformat)) {
                  $cohort->descriptionformat = FORMAT_PLAIN;
              }
  
              list($cohort->description, $cohort->descriptionformat) =
                  external_format_text($cohort->description, $cohort->descriptionformat,
                          $cohortcontext->id, 'cohort', 'description', $cohort->id);
  
              $cohorts[$key] = $cohort;
          }
  
          return array('cohorts' => $cohorts);
      }
code: public static function search_cohorts($query, $context, $includes = 'parents', $limitfrom = 0, $limitnum = 25) {
          global $CFG;
          require_once($CFG->dirroot . '/cohort/lib.php');
  
          $params = self::validate_parameters(self::search_cohorts_parameters(), array(
              'query' => $query,
              'context' => $context,
              'includes' => $includes,
              'limitfrom' => $limitfrom,
              'limitnum' => $limitnum,
          ));
          $query = $params['query'];
          $includes = $params['includes'];
          $context = self::get_context_from_params($params['context']);
          $limitfrom = $params['limitfrom'];
          $limitnum = $params['limitnum'];
  
          self::validate_context($context);
  
          $manager = has_capability('moodle/cohort:manage', $context);
          if (!$manager) {
              require_capability('moodle/cohort:view', $context);
          }
  
          // TODO Make this more efficient.
          if ($includes == 'self') {
              $results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
              $results = $results['cohorts'];
          } else if ($includes == 'parents') {
              $results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
              $results = $results['cohorts'];
              if (!$context instanceof context_system) {
                  $results = array_merge($results, cohort_get_available_cohorts($context, COHORT_ALL, $limitfrom, $limitnum, $query));
              }
          } else if ($includes == 'all') {
              $results = cohort_get_all_cohorts($limitfrom, $limitnum, $query);
              $results = $results['cohorts'];
          } else {
              throw new coding_exception('Invalid parameter value for \'includes\'.');
          }
  
          $cohorts = array();
          foreach ($results as $key => $cohort) {
              $cohortcontext = context::instance_by_id($cohort->contextid);
  
              // Only return theme when $CFG->allowcohortthemes is enabled.
              if (!empty($cohort->theme) && empty($CFG->allowcohortthemes)) {
                  $cohort->theme = null;
              }
  
              if (!isset($cohort->description)) {
                  $cohort->description = '';
              }
              if (!isset($cohort->descriptionformat)) {
                  $cohort->descriptionformat = FORMAT_PLAIN;
              }
  
              list($cohort->description, $cohort->descriptionformat) =
                  external_format_text($cohort->description, $cohort->descriptionformat,
                          $cohortcontext->id, 'cohort', 'description', $cohort->id);
  
              $cohorts[$key] = $cohort;
          }
  
          return array('cohorts' => $cohorts);
      }
code_tokens: public static function search_cohorts ( $ query , $ context , $ includes = 'parents' , $ limitfrom = 0 , $ limitnum = 25 ) { global $ CFG ; require_once ( $ CFG -> dirroot . '/cohort/lib.php' ) ; $ params = self :: validate_parameters ( self :: search_cohorts_parameters ( ) , array ( 'query' => $ query , 'context' => $ context , 'includes' => $ includes , 'limitfrom' => $ limitfrom , 'limitnum' => $ limitnum , ) ) ; $ query = $ params [ 'query' ] ; $ includes = $ params [ 'includes' ] ; $ context = self :: get_context_from_params ( $ params [ 'context' ] ) ; $ limitfrom = $ params [ 'limitfrom' ] ; $ limitnum = $ params [ 'limitnum' ] ; self :: validate_context ( $ context ) ; $ manager = has_capability ( 'moodle/cohort:manage' , $ context ) ; if ( ! $ manager ) { require_capability ( 'moodle/cohort:view' , $ context ) ; } // TODO Make this more efficient. if ( $ includes == 'self' ) { $ results = cohort_get_cohorts ( $ context -> id , $ limitfrom , $ limitnum , $ query ) ; $ results = $ results [ 'cohorts' ] ; } else if ( $ includes == 'parents' ) { $ results = cohort_get_cohorts ( $ context -> id , $ limitfrom , $ limitnum , $ query ) ; $ results = $ results [ 'cohorts' ] ; if ( ! $ context instanceof context_system ) { $ results = array_merge ( $ results , cohort_get_available_cohorts ( $ context , COHORT_ALL , $ limitfrom , $ limitnum , $ query ) ) ; } } else if ( $ includes == 'all' ) { $ results = cohort_get_all_cohorts ( $ limitfrom , $ limitnum , $ query ) ; $ results = $ results [ 'cohorts' ] ; } else { throw new coding_exception ( 'Invalid parameter value for \'includes\'.' ) ; } $ cohorts = array ( ) ; foreach ( $ results as $ key => $ cohort ) { $ cohortcontext = context :: instance_by_id ( $ cohort -> contextid ) ; // Only return theme when $CFG->allowcohortthemes is enabled. if ( ! empty ( $ cohort -> theme ) && empty ( $ CFG -> allowcohortthemes ) ) { $ cohort -> theme = null ; } if ( ! isset ( $ cohort -> description ) ) { $ cohort -> description = '' ; } if ( ! isset ( $ cohort -> descriptionformat ) ) { $ cohort -> descriptionformat = FORMAT_PLAIN ; } list ( $ cohort -> description , $ cohort -> descriptionformat ) = external_format_text ( $ cohort -> description , $ cohort -> descriptionformat , $ cohortcontext -> id , 'cohort' , 'description' , $ cohort -> id ) ; $ cohorts [ $ key ] = $ cohort ; } return array ( 'cohorts' => $ cohorts ) ; }
docstring: Search cohorts.
  
  @param string $query
  @param array $context
  @param string $includes
  @param int $limitfrom
  @param int $limitnum
  @return array
docstring_tokens: Search cohorts .