~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to mod/glossary/lib.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
335
335
    $cm = $modinfo->cms[$cmid];
336
336
    $context = context_module::instance($cm->id);
337
337
 
338
 
    if (!has_capability('mod/glossary:view', $context)) {
 
338
    if (!$cm->uservisible) {
339
339
        return;
340
340
    }
341
341
 
342
342
    $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
 
343
    // Groups are not yet supported for glossary. See MDL-10728 .
 
344
    /*
343
345
    $accessallgroups = has_capability('moodle/site:accessallgroups', $context);
344
346
    $groupmode = groups_get_activity_groupmode($cm, $course);
 
347
     */
345
348
 
346
349
    $params['timestart'] = $timestart;
347
350
 
361
364
        $groupjoin   = '';
362
365
    }
363
366
 
 
367
    $approvedselect = "";
 
368
    if (!has_capability('mod/glossary:approve', $context)) {
 
369
        $approvedselect = " AND ge.approved = 1 ";
 
370
    }
 
371
 
364
372
    $params['timestart'] = $timestart;
365
373
    $params['glossaryid'] = $cm->instance;
366
374
 
367
 
    $ufields = user_picture::fields('u', array('lastaccess', 'firstname', 'lastname', 'email', 'picture', 'imagealt'));
 
375
    $ufields = user_picture::fields('u', null, 'userid');
368
376
    $entries = $DB->get_records_sql("
369
 
              SELECT ge.id AS entryid, ge.*, $ufields
 
377
              SELECT ge.id AS entryid, ge.glossaryid, ge.concept, ge.definition, ge.approved,
 
378
                     ge.timemodified, $ufields
370
379
                FROM {glossary_entries} ge
371
380
                JOIN {user} u ON u.id = ge.userid
372
381
                     $groupjoin
373
382
               WHERE ge.timemodified > :timestart
374
383
                 AND ge.glossaryid = :glossaryid
 
384
                     $approvedselect
375
385
                     $userselect
376
386
                     $groupselect
377
387
            ORDER BY ge.timemodified ASC", $params);
381
391
    }
382
392
 
383
393
    foreach ($entries as $entry) {
 
394
        // Groups are not yet supported for glossary. See MDL-10728 .
 
395
        /*
384
396
        $usersgroups = null;
385
397
        if ($entry->userid != $USER->id) {
386
398
            if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
392
404
                        $usersgroups = array();
393
405
                    }
394
406
                }
395
 
                if (!array_intersect($usersgroups, $modinfo->get_groups($cm->id))) {
 
407
                if (!array_intersect($usersgroups, $modinfo->get_groups($cm->groupingid))) {
396
408
                    continue;
397
409
                }
398
410
            }
399
411
        }
 
412
         */
400
413
 
401
414
        $tmpactivity                       = new stdClass();
 
415
        $tmpactivity->user                 = user_picture::unalias($entry, null, 'userid');
 
416
        $tmpactivity->user->fullname       = fullname($tmpactivity->user, $viewfullnames);
402
417
        $tmpactivity->type                 = 'glossary';
403
418
        $tmpactivity->cmid                 = $cm->id;
404
419
        $tmpactivity->glossaryid           = $entry->glossaryid;
409
424
        $tmpactivity->content->entryid     = $entry->entryid;
410
425
        $tmpactivity->content->concept     = $entry->concept;
411
426
        $tmpactivity->content->definition  = $entry->definition;
412
 
        $tmpactivity->user                 = new stdClass();
413
 
        $tmpactivity->user->id             = $entry->userid;
414
 
        $tmpactivity->user->firstname      = $entry->firstname;
415
 
        $tmpactivity->user->lastname       = $entry->lastname;
416
 
        $tmpactivity->user->fullname       = fullname($entry, $viewfullnames);
417
 
        $tmpactivity->user->picture        = $entry->picture;
418
 
        $tmpactivity->user->imagealt       = $entry->imagealt;
419
 
        $tmpactivity->user->email          = $entry->email;
 
427
        $tmpactivity->content->approved    = $entry->approved;
420
428
 
421
429
        $activities[$index++] = $tmpactivity;
422
430
    }
446
454
    echo html_writer::start_tag('div', array('class'=>'glossary-activity-content'));
447
455
    echo html_writer::start_tag('div', array('class'=>'glossary-activity-entry'));
448
456
 
449
 
    $urlparams = array('g' => $activity->glossaryid, 'mode' => 'entry', 'hook' => $activity->content->entryid);
450
 
    echo html_writer::tag('a', strip_tags($activity->content->concept),
451
 
        array('href' => new moodle_url('/mod/glossary/view.php', $urlparams)));
 
457
    if (isset($activity->content->approved) && !$activity->content->approved) {
 
458
        $urlparams = array('g' => $activity->glossaryid, 'mode' => 'approval', 'hook' => $activity->content->concept);
 
459
        $class = array('class' => 'dimmed_text');
 
460
    } else {
 
461
        $urlparams = array('g' => $activity->glossaryid, 'mode' => 'entry', 'hook' => $activity->content->entryid);
 
462
        $class = array();
 
463
    }
 
464
    echo html_writer::link(new moodle_url('/mod/glossary/view.php', $urlparams),
 
465
            strip_tags($activity->content->concept), $class);
452
466
    echo html_writer::end_tag('div');
453
467
 
454
468
    $url = new moodle_url('/user/view.php', array('course'=>$courseid, 'id'=>$activity->user->id));
455
469
    $name = $activity->user->fullname;
456
 
    $link = html_writer::link($url, $name);
 
470
    $link = html_writer::link($url, $name, $class);
457
471
 
458
472
    echo html_writer::start_tag('div', array('class'=>'user'));
459
473
    echo $link .' - '. userdate($activity->timestamp);
1011
1025
        $bypassteacher = 0; //This means YES
1012
1026
    }
1013
1027
 
1014
 
    $conceptlower = textlib::strtolower(trim($concept));
 
1028
    $conceptlower = core_text::strtolower(trim($concept));
1015
1029
 
1016
1030
    $params = array('courseid1'=>$courseid, 'courseid2'=>$courseid, 'conceptlower'=>$conceptlower, 'concept'=>$concept);
1017
1031
 
1085
1099
 
1086
1100
    require_once($CFG->libdir . '/filelib.php');
1087
1101
 
1088
 
    echo '<h3>'. strip_tags($entry->concept) . ': </h3>';
 
1102
    echo $OUTPUT->heading(strip_tags($entry->concept), 4);
1089
1103
 
1090
1104
    $definition = $entry->definition;
1091
1105
 
1105
1119
}
1106
1120
 
1107
1121
/**
1108
 
 * Print glossary concept/term as a heading &lt;h3>
 
1122
 * Print glossary concept/term as a heading &lt;h4>
1109
1123
 * @param object $entry
1110
1124
 */
1111
1125
function  glossary_print_entry_concept($entry, $return=false) {
1112
1126
    global $OUTPUT;
1113
1127
 
1114
 
    $text = html_writer::tag('h3', format_string($entry->concept));
 
1128
    $text = $OUTPUT->heading(format_string($entry->concept), 4);
1115
1129
    if (!empty($entry->highlight)) {
1116
1130
        $text = highlight($entry->highlight, $text);
1117
1131
    }
1238
1252
            array('class' => 'glossary-hidden-note'));
1239
1253
    }
1240
1254
 
 
1255
    if (has_capability('mod/glossary:approve', $context) && !$glossary->defaultapproval && $entry->approved) {
 
1256
        $output = true;
 
1257
        $return .= '<a class="action-icon" title="' . get_string('disapprove', 'glossary').
 
1258
                   '" href="approve.php?newstate=0&amp;eid='.$entry->id.'&amp;mode='.$mode.
 
1259
                   '&amp;hook='.urlencode($hook).'&amp;sesskey='.sesskey().
 
1260
                   '"><img src="'.$OUTPUT->pix_url('t/block').'" class="smallicon" alt="'.
 
1261
                   get_string('disapprove','glossary').$altsuffix.'" /></a>';
 
1262
    }
 
1263
 
1241
1264
    $iscurrentuser = ($entry->userid == $USER->id);
1242
1265
 
1243
1266
    if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) {
2114
2137
 */
2115
2138
function glossary_sort_entries ( $entry0, $entry1 ) {
2116
2139
 
2117
 
    if ( textlib::strtolower(ltrim($entry0->concept)) < textlib::strtolower(ltrim($entry1->concept)) ) {
 
2140
    if ( core_text::strtolower(ltrim($entry0->concept)) < core_text::strtolower(ltrim($entry1->concept)) ) {
2118
2141
        return -1;
2119
 
    } elseif ( textlib::strtolower(ltrim($entry0->concept)) > textlib::strtolower(ltrim($entry1->concept)) ) {
 
2142
    } elseif ( core_text::strtolower(ltrim($entry0->concept)) > core_text::strtolower(ltrim($entry1->concept)) ) {
2120
2143
        return 1;
2121
2144
    } else {
2122
2145
        return 0;