diff --git a/cohort/index.php b/cohort/index.php index 0ce53bd872ff9..35d794ffb2c58 100644 --- a/cohort/index.php +++ b/cohort/index.php @@ -67,7 +67,18 @@ echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('cohortsin', 'cohort', print_context_name($context))); +$cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery); + +$count = ''; +if ($cohorts['allcohorts'] > 0) { + if ($searchquery === '') { + $count = ' ('.$cohorts['allcohorts'].')'; + } else { + $count = ' ('.$cohorts['totalcohorts'].'/'.$cohorts['allcohorts'].')'; + } +} + +echo $OUTPUT->heading(get_string('cohortsin', 'cohort', $context->get_context_name()).$count); // Add search form. $search = html_writer::start_tag('form', array('id'=>'searchcohortquery', 'method'=>'get')); @@ -79,7 +90,6 @@ $search .= html_writer::end_tag('form'); echo $search; -$cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery); // Output pagination bar. $params = array('page' => $page); diff --git a/cohort/lib.php b/cohort/lib.php index f2d425079ebc0..89a79e6b581d2 100644 --- a/cohort/lib.php +++ b/cohort/lib.php @@ -225,7 +225,7 @@ function cohort_get_visible_list($course, $onlyenrolled=true) { * @param int $page number of the current page * @param int $perpage items per page * @param string $search search string - * @return array Array(totalcohorts => int, cohorts => array) + * @return array Array(totalcohorts => int, cohorts => array, allcohorts => int) */ function cohort_get_cohorts($contextid, $page = 0, $perpage = 25, $search = '') { global $DB; @@ -250,8 +250,9 @@ function cohort_get_cohorts($contextid, $page = 0, $perpage = 25, $search = '') $sql = " FROM {cohort} WHERE $wherecondition"; $order = " ORDER BY name ASC, idnumber ASC"; + $allcohorts = $DB->count_records('cohort', array('contextid'=>$contextid)); $totalcohorts = $DB->count_records_sql($countfields . $sql, $params); $cohorts = $DB->get_records_sql($fields . $sql . $order, $params, $page*$perpage, $perpage); - return array('totalcohorts' => $totalcohorts, 'cohorts' => $cohorts); + return array('totalcohorts' => $totalcohorts, 'cohorts' => $cohorts, 'allcohorts'=>$allcohorts); } diff --git a/cohort/locallib.php b/cohort/locallib.php index cfc4b73efd8bf..b257223b667ae 100644 --- a/cohort/locallib.php +++ b/cohort/locallib.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot . '/cohot/lib.php'); +require_once($CFG->dirroot . '/cohort/lib.php'); require_once($CFG->dirroot . '/user/selector/lib.php'); diff --git a/cohort/tests/cohortlib_test.php b/cohort/tests/cohortlib_test.php index 7fb94603f4061..661684fa704fc 100644 --- a/cohort/tests/cohortlib_test.php +++ b/cohort/tests/cohortlib_test.php @@ -273,25 +273,31 @@ public function test_cohort_get_cohorts() { $result = cohort_get_cohorts(context_coursecat::instance($category2->id)->id); $this->assertEquals(0, $result['totalcohorts']); $this->assertEquals(0, count($result['cohorts'])); + $this->assertEquals(0, $result['allcohorts']); $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id); $this->assertEquals(3, $result['totalcohorts']); $this->assertEquals(array($cohort1->id=>$cohort1, $cohort2->id=>$cohort2, $cohort3->id=>$cohort3), $result['cohorts']); + $this->assertEquals(3, $result['allcohorts']); $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'arrrgh'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort3->id=>$cohort3), $result['cohorts']); + $this->assertEquals(3, $result['allcohorts']); $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'brrr'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']); + $this->assertEquals(3, $result['allcohorts']); $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 0, 100, 'grrr'); $this->assertEquals(1, $result['totalcohorts']); $this->assertEquals(array($cohort1->id=>$cohort1), $result['cohorts']); + $this->assertEquals(3, $result['allcohorts']); $result = cohort_get_cohorts(context_coursecat::instance($category1->id)->id, 1, 1, 'yyy'); $this->assertEquals(3, $result['totalcohorts']); $this->assertEquals(array($cohort2->id=>$cohort2), $result['cohorts']); + $this->assertEquals(3, $result['allcohorts']); } }