Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 331... Línea 331...
331
            return $templatecontext;
331
            return $templatecontext;
332
        }
332
        }
333
    }
333
    }
Línea 334... Línea 334...
334
 
334
 
335
    /**
-
 
336
     * First checks the cached language strings, then returns match if found, or uses get_string()
-
 
337
     * to get it from the DB, caches it then returns it.
-
 
338
     *
335
    /**
339
     * @deprecated since 4.2
-
 
340
     * @todo MDL-77307 This will be deleted in Moodle 4.6.
-
 
341
     * @param string $strcode
-
 
342
     * @param string $section Optional language section
-
 
343
     * @return string
336
     * @deprecated since 4.2
344
     */
-
 
345
    public function get_lang_string($strcode, $section=null) {
337
     */
346
        debugging('grade_report::get_lang_string() is deprecated, please use' .
-
 
347
            ' get_string() instead.', DEBUG_DEVELOPER);
-
 
348
 
338
    #[\core\attribute\deprecated('get_string', since: '4.2', mdl: 'MDL-77033', final: true)]
349
        if (empty($this->lang_strings[$strcode])) {
339
    public function get_lang_string(): void {
350
            $this->lang_strings[$strcode] = get_string($strcode, $section);
-
 
351
        }
-
 
352
        return $this->lang_strings[$strcode];
340
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 353... Línea 341...
353
    }
341
    }
354
 
342
 
355
    /**
343
    /**
Línea 483... Línea 471...
483
            $this->userwheresql_params['uid'] = $this->userid;
471
            $this->userwheresql_params['uid'] = $this->userid;
484
        }
472
        }
Línea 485... Línea 473...
485
 
473
 
486
        // A user wants to return a subset of learners that match their search criteria.
474
        // A user wants to return a subset of learners that match their search criteria.
487
        if ($this->usersearch !== '' && $this->userid === -1) {
-
 
488
            // Get the fields for all contexts because there is a special case later where it allows
-
 
489
            // matches of fields you can't access if they are on your own account.
-
 
490
            $userfields = fields::for_identity(null, false)->with_userpic();
-
 
491
            ['mappings' => $mappings]  = (array)$userfields->get_sql('u', true);
475
        if ($this->usersearch !== '' && $this->userid === -1) {
492
            [
476
            [
493
                'where' => $keywordswhere,
477
                'where' => $keywordswhere,
494
                'params' => $keywordsparams,
478
                'params' => $keywordsparams,
495
            ] = $this->get_users_search_sql($mappings, $userfields->get_required_fields());
479
            ] = \core_user::get_users_search_sql($this->context, $this->usersearch);
496
            $this->userwheresql .= " AND $keywordswhere";
480
            $this->userwheresql .= " AND $keywordswhere";
497
            $this->userwheresql_params = array_merge($this->userwheresql_params, $keywordsparams);
481
            $this->userwheresql_params = array_merge($this->userwheresql_params, $keywordsparams);
498
        }
482
        }
Línea 499... Línea 483...
499
    }
483
    }
500
 
-
 
501
    /**
-
 
502
     * Prepare SQL where clause and associated parameters for any user searching being performed.
-
 
503
     * This mostly came from core_user\table\participants_search with some slight modifications four our use case.
-
 
504
     *
-
 
505
     * @param array $mappings Array of field mappings (fieldname => SQL code for the value)
-
 
506
     * @param array $userfields An array that we cast from user profile fields to search within.
-
 
507
     * @return array SQL query data in the format ['where' => '', 'params' => []].
-
 
508
     */
-
 
509
    protected function get_users_search_sql(array $mappings, array $userfields): array {
-
 
510
        global $DB, $USER;
-
 
511
 
-
 
512
        $canviewfullnames = has_capability('moodle/site:viewfullnames', $this->context);
-
 
513
 
-
 
514
        $params = [];
-
 
515
        $searchkey1 = 'search01';
-
 
516
        $searchkey2 = 'search02';
-
 
517
        $searchkey3 = 'search03';
-
 
518
 
-
 
519
        $conditions = [];
-
 
520
 
-
 
521
        // Search by fullname.
-
 
522
        [$fullname, $fullnameparams] = fields::get_sql_fullname('u', $canviewfullnames);
-
 
523
        $conditions[] = $DB->sql_like($fullname, ':' . $searchkey1, false, false);
-
 
524
        $params = array_merge($params, $fullnameparams);
-
 
525
 
-
 
526
        // Search by email.
-
 
527
        $email = $DB->sql_like('email', ':' . $searchkey2, false, false);
-
 
528
 
-
 
529
        if (!in_array('email', $userfields)) {
-
 
530
            $maildisplay = 'maildisplay0';
-
 
531
            $userid1 = 'userid01';
-
 
532
            // Prevent users who hide their email address from being found by others
-
 
533
            // who aren't allowed to see hidden email addresses.
-
 
534
            $email = "(". $email ." AND (" .
-
 
535
                "u.maildisplay <> :$maildisplay " .
-
 
536
                "OR u.id = :$userid1". // Users can always find themselves.
-
 
537
                "))";
-
 
538
            $params[$maildisplay] = core_user::MAILDISPLAY_HIDE;
-
 
539
            $params[$userid1] = $USER->id;
-
 
540
        }
-
 
541
 
-
 
542
        $conditions[] = $email;
-
 
543
 
-
 
544
        // Search by idnumber.
-
 
545
        $idnumber = $DB->sql_like('idnumber', ':' . $searchkey3, false, false);
-
 
546
 
-
 
547
        if (!in_array('idnumber', $userfields)) {
-
 
548
            $userid2 = 'userid02';
-
 
549
            // Users who aren't allowed to see idnumbers should at most find themselves
-
 
550
            // when searching for an idnumber.
-
 
551
            $idnumber = "(". $idnumber . " AND u.id = :$userid2)";
-
 
552
            $params[$userid2] = $USER->id;
-
 
553
        }
-
 
554
 
-
 
555
        $conditions[] = $idnumber;
-
 
556
 
-
 
557
        // Search all user identify fields.
-
 
558
        $extrasearchfields = fields::get_identity_fields(null, false);
-
 
559
        foreach ($extrasearchfields as $fieldindex => $extrasearchfield) {
-
 
560
            if (in_array($extrasearchfield, ['email', 'idnumber', 'country'])) {
-
 
561
                // Already covered above.
-
 
562
                continue;
-
 
563
            }
-
 
564
            // The param must be short (max 32 characters) so don't include field name.
-
 
565
            $param = $searchkey3 . '_ident' . $fieldindex;
-
 
566
            $fieldsql = $mappings[$extrasearchfield];
-
 
567
            $condition = $DB->sql_like($fieldsql, ':' . $param, false, false);
-
 
568
            $params[$param] = "%$this->usersearch%";
-
 
569
 
-
 
570
            if (!in_array($extrasearchfield, $userfields)) {
-
 
571
                // User cannot see this field, but allow match if their own account.
-
 
572
                $userid3 = 'userid03_ident' . $fieldindex;
-
 
573
                $condition = "(". $condition . " AND u.id = :$userid3)";
-
 
574
                $params[$userid3] = $USER->id;
-
 
575
            }
-
 
576
            $conditions[] = $condition;
-
 
577
        }
-
 
578
 
-
 
579
        $where = "(". implode(" OR ", $conditions) .") ";
-
 
580
        $params[$searchkey1] = "%$this->usersearch%";
-
 
581
        $params[$searchkey2] = "%$this->usersearch%";
-
 
582
        $params[$searchkey3] = "%$this->usersearch%";
-
 
583
 
-
 
584
        return [
-
 
585
            'where' => $where,
-
 
586
            'params' => $params,
-
 
587
        ];
-
 
588
    }
-
 
589
 
484
 
590
    /**
485
    /**
591
     * Returns an arrow icon inside an <a> tag, for the purpose of sorting a column.
486
     * Returns an arrow icon inside an <a> tag, for the purpose of sorting a column.
592
     * @param string $direction
487
     * @param string $direction
593
     * @param moodle_url|null $sortlink
488
     * @param moodle_url|null $sortlink