Commit 66f8ac10 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1827000: count(): Parameter must be an array in statistics.php:2408

Also fixed problem on Content stats page when they have not been
generated by cron job

behatnotneeded

Change-Id: I6d1a1d5557ab99c9a1513196e2f83d7b2fb89e50
parent c17f02eb
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -895,7 +895,7 @@ function useragreement_stats_table($limit, $offset, $extra, $institution, $urlli

    $result['settings']['start'] = ($start) ? $start : null;
    $result['settings']['end'] = $end;
    $result['settings']['users'] = count($users);
    $result['settings']['users'] = !empty($users) ? count($users) : 0;

    if ($count < 1) {
        return $result;
@@ -1153,7 +1153,7 @@ function useractivity_stats_table($limit, $offset, $extra, $institution, $urllin

    $result['settings']['start'] = ($start) ? $start : null;
    $result['settings']['end'] = $end;
    $result['settings']['users'] = count($users);
    $result['settings']['users'] = !empty($users) ? count($users) : 0;

    if ($count < 1) {
        return $result;
@@ -2008,7 +2008,7 @@ function user_institution_graph($type = null) {
    require_once(get_config('libroot') . 'institution.php');

    $institutions = Institution::count_members(false, true);
    if (count($institutions) > 1) {
    if (is_array($institutions) && count($institutions) > 1) {
        $dataarray = array();
        foreach ($institutions as &$i) {
            if ($i->members) {
@@ -2405,7 +2405,7 @@ function group_type_graph($type = false) {
        ORDER BY groupcount DESC", array()
    );

    if (count($grouptypes) > 1) {
    if (is_array($grouptypes) && count($grouptypes) > 1) {
        $dataarray = array();
        foreach ($grouptypes as &$t) {
            $strtype = get_string('name', 'grouptype.' . $t->grouptype);
@@ -2567,7 +2567,7 @@ function view_stats_table($limit, $offset, $extra) {
    );
    $result['settings']['start'] = ($start) ? $start : null;
    $result['settings']['end'] = $end;
    $result['settings']['users'] = count($users);
    $result['settings']['users'] = !empty($users) ? count($users) : 0;
    if ($count < 1) {
        return $result;
    }
@@ -2685,7 +2685,7 @@ function view_type_graph($type = null) {
        array('dashboard')
    );

    if (count($viewtypes) > 1) {
    if (is_array($viewtypes) && count($viewtypes) > 1) {
        $dataarray = array();
        foreach ($viewtypes as &$t) {
            $dataarray[get_string(ucfirst($t->type), 'view')] = $t->views;
@@ -2792,7 +2792,7 @@ function institution_view_stats_table($limit, $offset, &$institutiondata, $extra
    );
    $result['settings']['start'] = ($start) ? $start : null;
    $result['settings']['end'] = $end;
    $result['settings']['users'] = count($users);
    $result['settings']['users'] = !empty($users) ? count($users) : 0;
    if ($count < 1) {
        return $result;
    }
@@ -2927,7 +2927,7 @@ function institution_view_type_graph($type = null, $institutiondata) {
        ) GROUP BY type', $values
    );

    if (count($viewtypes) > 1) {
    if (is_array($viewtypes) && count($viewtypes) > 1) {
        $dataarray = array();
        foreach ($viewtypes as &$t) {
            $dataarray[get_string($t->type, 'view')] = $t->views;
@@ -3067,7 +3067,7 @@ function content_stats_table($limit, $offset, $extra) {
                  AND sd.field NOT LIKE '%version'";
    $regdata = get_records_sql_array("SELECT DISTINCT sr.id, sr.time " . $fromsql . " ORDER BY sr.time DESC", $values);

    $count = count_records_sql("SELECT COUNT(*) " . $fromsql . " AND sr.id = " . $regdata[0]->id, $values);
    $count = ($regdata) ? count_records_sql("SELECT COUNT(*) " . $fromsql . " AND sr.id = " . $regdata[0]->id, $values) : 0;

    $pagination = build_pagination(array(
        'id' => 'stats_pagination',
@@ -3120,7 +3120,7 @@ function content_stats_table($limit, $offset, $extra) {
    $daterange = array_map(function ($obj) { return $obj->time; }, $regdata);
    $result['settings']['start'] = ($start) ? $start : min($daterange);

    if (count($regdata) > 1) {
    if (is_array($regdata) && count($regdata) > 1) {
        $firstweeks = get_records_sql_assoc(
            "SELECT sd.field, sd.value " . $fromsql . "
            AND sr.id = " . end($regdata)->id . "
@@ -3416,7 +3416,7 @@ function institution_content_stats_table($limit, $offset, &$institutiondata, $ex
    $daterange = array_map(function ($obj) { return $obj->time; }, $regdata);
    $result['settings']['start'] = ($start) ? $start : min($daterange);

    if (count($regdata) > 1) {
    if (is_array($regdata) && count($regdata) > 1) {
        $firstweeks = get_records_sql_assoc(
            "SELECT sd.field, sd.value " . $fromsql . "
            AND sr.id = " . end($regdata)->id . "
@@ -3556,7 +3556,7 @@ function masquerading_stats_table($limit, $offset, $extra, $institution, $urllin
    );
    $result['settings']['start'] = ($start) ? $start : null;
    $result['settings']['end'] = $end;
    $result['settings']['users'] = count($users);
    $result['settings']['users'] = !empty($users) ? count($users) : 0;
    if ($count < 1) {
        return $result;
    }
@@ -3726,7 +3726,7 @@ function accesslist_stats_table($limit, $offset, $extra, $institution, $urllink)
    );
    $result['settings']['start'] = ($start) ? $start : null;
    $result['settings']['end'] = $end;
    $result['settings']['users'] = count($users);
    $result['settings']['users'] = !empty($users) ? count($users) : 0;
    if ($count < 1) {
        return $result;
    }