| Línea 206... |
Línea 206... |
| 206 |
* @param stdClass $dbrecord Workshop instance data from {workshop} table
|
206 |
* @param stdClass $dbrecord Workshop instance data from {workshop} table
|
| 207 |
* @param stdClass|cm_info $cm Course module record
|
207 |
* @param stdClass|cm_info $cm Course module record
|
| 208 |
* @param stdClass $course Course record from {course} table
|
208 |
* @param stdClass $course Course record from {course} table
|
| 209 |
* @param stdClass $context The context of the workshop instance
|
209 |
* @param stdClass $context The context of the workshop instance
|
| 210 |
*/
|
210 |
*/
|
| 211 |
public function __construct(stdclass $dbrecord, $cm, $course, stdclass $context=null) {
|
211 |
public function __construct(stdclass $dbrecord, $cm, $course, ?stdclass $context=null) {
|
| 212 |
$this->dbrecord = $dbrecord;
|
212 |
$this->dbrecord = $dbrecord;
|
| 213 |
foreach ($this->dbrecord as $field => $value) {
|
213 |
foreach ($this->dbrecord as $field => $value) {
|
| 214 |
if (property_exists('workshop', $field)) {
|
214 |
if (property_exists('workshop', $field)) {
|
| 215 |
$this->{$field} = $value;
|
215 |
$this->{$field} = $value;
|
| 216 |
}
|
216 |
}
|
| Línea 580... |
Línea 580... |
| 580 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
580 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
| 581 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
581 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
| 582 |
* @return array array[userid] => stdClass
|
582 |
* @return array array[userid] => stdClass
|
| 583 |
*/
|
583 |
*/
|
| 584 |
public function get_potential_authors($musthavesubmission=true, $groupid=0, $limitfrom=0, $limitnum=0) {
|
584 |
public function get_potential_authors($musthavesubmission=true, $groupid=0, $limitfrom=0, $limitnum=0) {
|
| 585 |
global $DB;
|
- |
|
| 586 |
|
- |
|
| 587 |
list($sql, $params) = $this->get_users_with_capability_sql('mod/workshop:submit', $musthavesubmission, $groupid);
|
585 |
return $this->get_users_with_capability(['mod/workshop:submit'], $musthavesubmission, $groupid, $limitfrom, $limitnum);
|
| 588 |
|
- |
|
| 589 |
if (empty($sql)) {
|
- |
|
| 590 |
return array();
|
- |
|
| 591 |
}
|
- |
|
| 592 |
|
- |
|
| 593 |
list($sort, $sortparams) = users_order_by_sql('tmp');
|
- |
|
| 594 |
$sql = "SELECT *
|
- |
|
| 595 |
FROM ($sql) tmp
|
- |
|
| 596 |
ORDER BY $sort";
|
- |
|
| 597 |
|
- |
|
| 598 |
return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum);
|
- |
|
| 599 |
}
|
586 |
}
|
| Línea 600... |
Línea 587... |
| 600 |
|
587 |
|
| 601 |
/**
|
588 |
/**
|
| 602 |
* Returns the total number of users that would be fetched by {@link self::get_potential_authors()}
|
589 |
* Returns the total number of users that would be fetched by {@link self::get_potential_authors()}
|
| 603 |
*
|
590 |
*
|
| 604 |
* @param bool $musthavesubmission if true, count only users who have already submitted
|
591 |
* @param bool $musthavesubmission if true, count only users who have already submitted
|
| 605 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
592 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
| 606 |
* @return int
|
593 |
* @return int
|
| 607 |
*/
|
594 |
*/
|
| 608 |
public function count_potential_authors($musthavesubmission=true, $groupid=0) {
|
- |
|
| 609 |
global $DB;
|
- |
|
| 610 |
|
595 |
public function count_potential_authors($musthavesubmission=true, $groupid=0) {
|
| 611 |
list($sql, $params) = $this->get_users_with_capability_sql('mod/workshop:submit', $musthavesubmission, $groupid);
|
- |
|
| 612 |
|
- |
|
| 613 |
if (empty($sql)) {
|
- |
|
| 614 |
return 0;
|
- |
|
| 615 |
}
|
- |
|
| 616 |
|
- |
|
| 617 |
$sql = "SELECT COUNT(*)
|
- |
|
| 618 |
FROM ($sql) tmp";
|
- |
|
| 619 |
|
- |
|
| 620 |
return $DB->count_records_sql($sql, $params);
|
596 |
return count($this->get_users_with_capability(['mod/workshop:submit'], $musthavesubmission, $groupid));
|
| Línea 621... |
Línea 597... |
| 621 |
}
|
597 |
}
|
| 622 |
|
598 |
|
| 623 |
/**
|
599 |
/**
|
| Línea 631... |
Línea 607... |
| 631 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
607 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
| 632 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
608 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
| 633 |
* @return array array[userid] => stdClass
|
609 |
* @return array array[userid] => stdClass
|
| 634 |
*/
|
610 |
*/
|
| 635 |
public function get_potential_reviewers($musthavesubmission=false, $groupid=0, $limitfrom=0, $limitnum=0) {
|
611 |
public function get_potential_reviewers($musthavesubmission=false, $groupid=0, $limitfrom=0, $limitnum=0) {
|
| 636 |
global $DB;
|
- |
|
| 637 |
|
- |
|
| 638 |
list($sql, $params) = $this->get_users_with_capability_sql('mod/workshop:peerassess', $musthavesubmission, $groupid);
|
612 |
return $this->get_users_with_capability(['mod/workshop:peerassess'], $musthavesubmission, $groupid, $limitfrom, $limitnum);
|
| 639 |
|
- |
|
| 640 |
if (empty($sql)) {
|
- |
|
| 641 |
return array();
|
- |
|
| 642 |
}
|
- |
|
| 643 |
|
- |
|
| 644 |
list($sort, $sortparams) = users_order_by_sql('tmp');
|
- |
|
| 645 |
$sql = "SELECT *
|
- |
|
| 646 |
FROM ($sql) tmp
|
- |
|
| 647 |
ORDER BY $sort";
|
- |
|
| 648 |
|
- |
|
| 649 |
return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum);
|
- |
|
| 650 |
}
|
613 |
}
|
| Línea 651... |
Línea 614... |
| 651 |
|
614 |
|
| 652 |
/**
|
615 |
/**
|
| 653 |
* Returns the total number of users that would be fetched by {@link self::get_potential_reviewers()}
|
616 |
* Returns the total number of users that would be fetched by {@link self::get_potential_reviewers()}
|
| 654 |
*
|
617 |
*
|
| 655 |
* @param bool $musthavesubmission if true, count only users who have already submitted
|
618 |
* @param bool $musthavesubmission if true, count only users who have already submitted
|
| 656 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
619 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
| 657 |
* @return int
|
620 |
* @return int
|
| 658 |
*/
|
621 |
*/
|
| 659 |
public function count_potential_reviewers($musthavesubmission=false, $groupid=0) {
|
- |
|
| 660 |
global $DB;
|
- |
|
| 661 |
|
622 |
public function count_potential_reviewers($musthavesubmission=false, $groupid=0) {
|
| 662 |
list($sql, $params) = $this->get_users_with_capability_sql('mod/workshop:peerassess', $musthavesubmission, $groupid);
|
- |
|
| 663 |
|
- |
|
| 664 |
if (empty($sql)) {
|
- |
|
| 665 |
return 0;
|
- |
|
| Línea 666... |
Línea -... |
| 666 |
}
|
- |
|
| 667 |
|
- |
|
| 668 |
$sql = "SELECT COUNT(*)
|
- |
|
| 669 |
FROM ($sql) tmp";
|
- |
|
| 670 |
|
623 |
return count($this->get_users_with_capability(['mod/workshop:peerassess'], $musthavesubmission, $groupid));
|
| Línea 671... |
Línea 624... |
| 671 |
return $DB->count_records_sql($sql, $params);
|
624 |
|
| 672 |
}
|
625 |
}
|
| 673 |
|
626 |
|
| Línea 684... |
Línea 637... |
| 684 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
637 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
| 685 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
638 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
| 686 |
* @return array array[userid] => stdClass
|
639 |
* @return array array[userid] => stdClass
|
| 687 |
*/
|
640 |
*/
|
| 688 |
public function get_participants($musthavesubmission=false, $groupid=0, $limitfrom=0, $limitnum=0) {
|
641 |
public function get_participants($musthavesubmission=false, $groupid=0, $limitfrom=0, $limitnum=0) {
|
| 689 |
global $DB;
|
- |
|
| 690 |
|
- |
|
| 691 |
list($sql, $params) = $this->get_participants_sql($musthavesubmission, $groupid);
|
- |
|
| 692 |
list($filteringsql, $filteringparams) = $this->get_users_with_initial_filtering_sql_where();
|
- |
|
| 693 |
$wheresql = "";
|
- |
|
| 694 |
|
- |
|
| 695 |
if ($filteringsql) {
|
- |
|
| 696 |
$wheresql .= $filteringsql;
|
- |
|
| 697 |
$params = array_merge($params, $filteringparams);
|
- |
|
| 698 |
}
|
- |
|
| 699 |
if (empty($sql)) {
|
- |
|
| 700 |
return array();
|
- |
|
| 701 |
}
|
- |
|
| Línea 702... |
Línea 642... |
| 702 |
|
642 |
|
| - |
|
643 |
// Get any users who have either of these 2 capabilities on the activity.
|
| 703 |
list($sort, $sortparams) = users_order_by_sql('tmp');
|
644 |
return $this->get_users_with_capability(['mod/workshop:submit', 'mod/workshop:peerassess'],
|
| Línea 704... |
Línea -... |
| 704 |
$sql = "SELECT * FROM ($sql) tmp";
|
- |
|
| 705 |
|
- |
|
| 706 |
if ($wheresql) {
|
- |
|
| 707 |
$sql .= " WHERE $wheresql";
|
- |
|
| 708 |
}
|
- |
|
| 709 |
$sql .= " ORDER BY $sort";
|
- |
|
| 710 |
|
645 |
$musthavesubmission, $groupid, $limitfrom, $limitnum);
|
| Línea 711... |
Línea 646... |
| 711 |
return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum);
|
646 |
|
| 712 |
}
|
647 |
}
|
| 713 |
|
648 |
|
| 714 |
/**
|
649 |
/**
|
| 715 |
* Returns the total number of records that would be returned by {@link self::get_participants()}
|
650 |
* Returns the total number of records that would be returned by {@link self::get_participants()}
|
| 716 |
*
|
651 |
*
|
| 717 |
* @param bool $musthavesubmission if true, return only users who have already submitted
|
652 |
* @param bool $musthavesubmission if true, return only users who have already submitted
|
| 718 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
653 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
| 719 |
* @return int
|
- |
|
| 720 |
*/
|
- |
|
| 721 |
public function count_participants($musthavesubmission=false, $groupid=0) {
|
654 |
* @return int
|
| 722 |
global $DB;
|
- |
|
| 723 |
|
- |
|
| 724 |
list($sql, $params) = $this->get_participants_sql($musthavesubmission, $groupid);
|
- |
|
| 725 |
|
- |
|
| 726 |
if (empty($sql)) {
|
- |
|
| 727 |
return 0;
|
- |
|
| 728 |
}
|
- |
|
| 729 |
|
- |
|
| 730 |
$sql = "SELECT COUNT(*)
|
- |
|
| 731 |
FROM ($sql) tmp";
|
655 |
*/
|
| Línea 732... |
Línea 656... |
| 732 |
|
656 |
public function count_participants($musthavesubmission=false, $groupid=0) {
|
| 733 |
return $DB->count_records_sql($sql, $params);
|
657 |
return count($this->get_participants($musthavesubmission, $groupid));
|
| 734 |
}
|
658 |
}
|
| 735 |
|
659 |
|
| 736 |
/**
|
660 |
/**
|
| 737 |
* Checks if the given user is an actively enrolled participant in the workshop
|
661 |
* Checks if the given user is an actively enrolled participant in the workshop
|
| 738 |
*
|
662 |
*
|
| - |
|
663 |
* @param int $userid, defaults to the current $USER
|
| 739 |
* @param int $userid, defaults to the current $USER
|
664 |
* @return boolean
|
| Línea 740... |
Línea 665... |
| 740 |
* @return boolean
|
665 |
*/
|
| 741 |
*/
|
666 |
public function is_participant($userid=null) {
|
| 742 |
public function is_participant($userid=null) {
|
667 |
|
| Línea -... |
Línea 668... |
| - |
|
668 |
global $USER;
|
| 743 |
global $USER, $DB;
|
669 |
|
| - |
|
670 |
if (is_null($userid)) {
|
| Línea 744... |
Línea -... |
| 744 |
|
- |
|
| 745 |
if (is_null($userid)) {
|
- |
|
| 746 |
$userid = $USER->id;
|
- |
|
| 747 |
}
|
- |
|
| 748 |
|
- |
|
| 749 |
list($sql, $params) = $this->get_participants_sql();
|
- |
|
| 750 |
|
- |
|
| 751 |
if (empty($sql)) {
|
- |
|
| 752 |
return false;
|
- |
|
| 753 |
}
|
- |
|
| 754 |
|
- |
|
| 755 |
$sql = "SELECT COUNT(*)
|
- |
|
| 756 |
FROM {user} uxx
|
- |
|
| 757 |
JOIN ({$sql}) pxx ON uxx.id = pxx.id
|
- |
|
| 758 |
WHERE uxx.id = :uxxid";
|
- |
|
| 759 |
$params['uxxid'] = $userid;
|
671 |
$userid = $USER->id;
|
| Línea 760... |
Línea 672... |
| 760 |
|
672 |
}
|
| 761 |
if ($DB->count_records_sql($sql, $params)) {
|
673 |
|
| 762 |
return true;
|
674 |
// Get the participants on this activity and see if the user exists in that array.
|
| Línea 860... |
Línea 772... |
| 860 |
}
|
772 |
}
|
| Línea 861... |
Línea 773... |
| 861 |
|
773 |
|
| 862 |
return $DB->count_records_sql($sql, $params);
|
774 |
return $DB->count_records_sql($sql, $params);
|
| Línea -... |
Línea 775... |
| - |
|
775 |
}
|
| - |
|
776 |
|
| - |
|
777 |
/**
|
| - |
|
778 |
* Returns the total number of assessments in the workshop.
|
| - |
|
779 |
*
|
| - |
|
780 |
* @param bool $onlygraded If true, count only graded assessments
|
| - |
|
781 |
* @param int|null $groupid If not null, return only assessments by reviewers in the specified group
|
| - |
|
782 |
* @return int Number of assessments
|
| - |
|
783 |
*/
|
| - |
|
784 |
public function count_assessments(bool $onlygraded = false, ?int $groupid = null): int {
|
| - |
|
785 |
global $DB;
|
| - |
|
786 |
|
| - |
|
787 |
$params = ['workshopid' => $this->id];
|
| - |
|
788 |
$sql = "SELECT COUNT(s.id)
|
| - |
|
789 |
FROM {workshop_assessments} s
|
| - |
|
790 |
JOIN {workshop_submissions} ws ON (s.submissionid = ws.id)
|
| - |
|
791 |
JOIN {user} u ON (ws.authorid = u.id)
|
| - |
|
792 |
JOIN {workshop} w ON (ws.workshopid = w.id)";
|
| - |
|
793 |
|
| - |
|
794 |
if ($groupid) {
|
| - |
|
795 |
$sql .= " JOIN {groups_members} gm ON (gm.userid = u.id AND gm.groupid = :groupid)";
|
| - |
|
796 |
$params['groupid'] = $groupid;
|
| - |
|
797 |
}
|
| - |
|
798 |
|
| - |
|
799 |
if ($onlygraded) {
|
| - |
|
800 |
$sql .= " WHERE s.grade IS NOT NULL AND w.id = :workshopid";
|
| - |
|
801 |
} else {
|
| - |
|
802 |
$sql .= " WHERE w.id = :workshopid";
|
| - |
|
803 |
}
|
| - |
|
804 |
|
| - |
|
805 |
return $DB->count_records_sql($sql, $params);
|
| Línea 863... |
Línea 806... |
| 863 |
}
|
806 |
}
|
| 864 |
|
807 |
|
| 865 |
|
808 |
|
| 866 |
/**
|
809 |
/**
|
| Línea 1798... |
Línea 1741... |
| 1798 |
* @param moodle_url $url absolute url as returned by {@see workshop::submission_url()} and friends
|
1741 |
* @param moodle_url $url absolute url as returned by {@see workshop::submission_url()} and friends
|
| 1799 |
* @param mixed $info additional info, usually id in a table
|
1742 |
* @param mixed $info additional info, usually id in a table
|
| 1800 |
* @param bool $return true to return the arguments for add_to_log.
|
1743 |
* @param bool $return true to return the arguments for add_to_log.
|
| 1801 |
* @return void|array array of arguments for add_to_log if $return is true
|
1744 |
* @return void|array array of arguments for add_to_log if $return is true
|
| 1802 |
*/
|
1745 |
*/
|
| 1803 |
public function log($action, moodle_url $url = null, $info = null, $return = false) {
|
1746 |
public function log($action, ?moodle_url $url = null, $info = null, $return = false) {
|
| 1804 |
debugging('The log method is now deprecated, please use event classes instead', DEBUG_DEVELOPER);
|
1747 |
debugging('The log method is now deprecated, please use event classes instead', DEBUG_DEVELOPER);
|
| Línea 1805... |
Línea 1748... |
| 1805 |
|
1748 |
|
| 1806 |
if (is_null($url)) {
|
1749 |
if (is_null($url)) {
|
| 1807 |
$url = $this->view_url();
|
1750 |
$url = $this->view_url();
|
| Línea 3445... |
Línea 3388... |
| 3445 |
}
|
3388 |
}
|
| 3446 |
}
|
3389 |
}
|
| 3447 |
}
|
3390 |
}
|
| Línea 3448... |
Línea 3391... |
| 3448 |
|
3391 |
|
| 3449 |
/**
|
3392 |
/**
|
| - |
|
3393 |
* This is a replacement for the old get_users_with_capability_sql method.
|
| - |
|
3394 |
* The old method returned huge amounts of SQL for large courses, potentially 10s of thousands of lines
|
| - |
|
3395 |
* with hundreds of UNIONS, which caused some poor performance. This new method aims to streamline it all
|
| 3450 |
* Returns SQL to fetch all enrolled users with the given capability in the current workshop
|
3396 |
* into one query.
|
| 3451 |
*
|
- |
|
| 3452 |
* The returned array consists of string $sql and the $params array. Note that the $sql can be
|
3397 |
*
|
| 3453 |
* empty if a grouping is selected and it has no groups.
|
3398 |
* Gets users with any of the specified capabilities on the workshop activity.
|
| 3454 |
*
|
3399 |
*
|
| 3455 |
* The list is automatically restricted according to any availability restrictions
|
3400 |
* The list is automatically restricted according to any availability restrictions
|
| 3456 |
* that apply to user lists (e.g. group, grouping restrictions).
|
3401 |
* that apply to user lists (e.g. group, grouping restrictions).
|
| 3457 |
*
|
3402 |
*
|
| 3458 |
* @param string $capability the name of the capability
|
3403 |
* @param array $capabilities array of capability names (If the user has ANY of them, it returns true for that user)
|
| 3459 |
* @param bool $musthavesubmission ff true, return only users who have already submitted
|
3404 |
* @param bool $musthavesubmission if true, return only users who have already submitted
|
| - |
|
3405 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
| - |
|
3406 |
* @param int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set)
|
| 3460 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
3407 |
* @param int $limitnum return a subset containing this number of records (optional, required if $limitfrom is set)
|
| 3461 |
* @return array of (string)sql, (array)params
|
3408 |
* @return array of users
|
| 3462 |
*/
|
3409 |
*/
|
| 3463 |
protected function get_users_with_capability_sql($capability, $musthavesubmission, $groupid) {
|
- |
|
| 3464 |
global $CFG;
|
- |
|
| 3465 |
/** @var int static counter used to generate unique parameter holders */
|
- |
|
| 3466 |
static $inc = 0;
|
- |
|
| 3467 |
$inc++;
|
- |
|
| 3468 |
|
- |
|
| 3469 |
// If the caller requests all groups and we are using a selected grouping,
|
- |
|
| 3470 |
// recursively call this function for each group in the grouping (this is
|
- |
|
| 3471 |
// needed because get_enrolled_sql only supports a single group).
|
- |
|
| 3472 |
if (empty($groupid) and $this->cm->groupingid) {
|
- |
|
| 3473 |
$groupingid = $this->cm->groupingid;
|
- |
|
| 3474 |
$groupinggroupids = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id'));
|
- |
|
| 3475 |
$sql = array();
|
- |
|
| 3476 |
$params = array();
|
- |
|
| 3477 |
foreach ($groupinggroupids as $groupinggroupid) {
|
- |
|
| 3478 |
if ($groupinggroupid > 0) { // just in case in order not to fall into the endless loop
|
- |
|
| 3479 |
list($gsql, $gparams) = $this->get_users_with_capability_sql($capability, $musthavesubmission, $groupinggroupid);
|
- |
|
| 3480 |
$sql[] = $gsql;
|
3410 |
protected function get_users_with_capability(array $capabilities, bool $musthavesubmission, int $groupid,
|
| 3481 |
$params = array_merge($params, $gparams);
|
- |
|
| 3482 |
}
|
- |
|
| 3483 |
}
|
- |
|
| 3484 |
$sql = implode(PHP_EOL." UNION ".PHP_EOL, $sql);
|
- |
|
| 3485 |
return array($sql, $params);
|
- |
|
| Línea 3486... |
Línea 3411... |
| 3486 |
}
|
3411 |
int $limitfrom = 0, int $limitnum = 0): array {
|
| Línea 3487... |
Línea 3412... |
| 3487 |
|
3412 |
|
| 3488 |
list($esql, $params) = get_enrolled_sql($this->context, $capability, $groupid, true);
|
- |
|
| Línea -... |
Línea 3413... |
| - |
|
3413 |
global $CFG, $DB;
|
| 3489 |
|
3414 |
|
| - |
|
3415 |
$params = [];
|
| - |
|
3416 |
|
| - |
|
3417 |
// This is from enrollib.php:get_enrolled_join(). It says it's better for caching to use round.
|
| - |
|
3418 |
$now = round(time(), -2);
|
| 3490 |
$userfieldsapi = \core_user\fields::for_userpic();
|
3419 |
$userfieldsapi = \core_user\fields::for_name()->with_userpic();
|
| - |
|
3420 |
|
| - |
|
3421 |
$sqlarray = [];
|
| 3491 |
$userfields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
|
3422 |
$sqlarray['select'] = "SELECT DISTINCT u.id" . $userfieldsapi->get_sql('u')->selects;
|
| - |
|
3423 |
$sqlarray['from'] = "FROM {user} u";
|
| - |
|
3424 |
$sqlarray['join'] = [];
|
| - |
|
3425 |
$sqlarray['join'][] = "JOIN {user_enrolments} ue ON ue.userid = u.id";
|
| - |
|
3426 |
$sqlarray['join'][] = "JOIN {enrol} e ON e.id = ue.enrolid AND e.courseid = :courseid";
|
| - |
|
3427 |
$sqlarray['where'] = [];
|
| - |
|
3428 |
$sqlarray['where'][] = "WHERE u.deleted = 0";
|
| - |
|
3429 |
$sqlarray['where'][] = "AND u.id <> :guestid";
|
| - |
|
3430 |
$sqlarray['where'][] = "AND ue.status = :activestatus";
|
| - |
|
3431 |
$sqlarray['where'][] = "AND e.status = :enabledstatus";
|
| - |
|
3432 |
$sqlarray['where'][] = "AND ue.timestart < :timestart";
|
| - |
|
3433 |
$sqlarray['where'][] = "AND (ue.timeend > :timeend OR ue.timeend = 0)";
|
| - |
|
3434 |
|
| - |
|
3435 |
// Apply sorting.
|
| - |
|
3436 |
[$sortby, $sortbyparams] = users_order_by_sql('u');
|
| - |
|
3437 |
$sqlarray['sort'] = "ORDER BY {$sortby}";
|
| - |
|
3438 |
|
| - |
|
3439 |
// Apply filtering.
|
| - |
|
3440 |
[$filtersql, $filterparams] = $this->get_users_with_initial_filtering_sql_where('u');
|
| - |
|
3441 |
if ($filtersql) {
|
| - |
|
3442 |
$sqlarray['where'][] = "AND {$filtersql}";
|
| - |
|
3443 |
$params = array_merge($params, $filterparams);
|
| - |
|
3444 |
}
|
| - |
|
3445 |
|
| - |
|
3446 |
$params['courseid'] = $this->context->get_course_context()->instanceid;
|
| - |
|
3447 |
$params['timestart'] = $now;
|
| Línea -... |
Línea 3448... |
| - |
|
3448 |
$params['timeend'] = $now;
|
| 3492 |
|
3449 |
$params['guestid'] = $CFG->siteguest;
|
| - |
|
3450 |
$params['activestatus'] = ENROL_USER_ACTIVE;
|
| 3493 |
$sql = "SELECT $userfields
|
3451 |
$params['enabledstatus'] = ENROL_INSTANCE_ENABLED;
|
| 3494 |
FROM {user} u
|
3452 |
|
| 3495 |
JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) ";
|
3453 |
// If we are filtering by users who have submitted.
|
| Línea 3496... |
Línea 3454... |
| 3496 |
|
3454 |
if ($musthavesubmission) {
|
| - |
|
3455 |
$sqlarray['join'][] = "JOIN {workshop_submissions} ws ON
|
| - |
|
3456 |
(ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid) ";
|
| - |
|
3457 |
$params['workshopid'] = $this->id;
|
| - |
|
3458 |
}
|
| 3497 |
if ($musthavesubmission) {
|
3459 |
|
| - |
|
3460 |
// Are we searching one specific group?
|
| - |
|
3461 |
if ($groupid > 0) {
|
| - |
|
3462 |
$sqlarray['join'][] = "JOIN {groups_members} gm ON (gm.userid = u.id AND gm.groupid = :groupid)";
|
| - |
|
3463 |
$params['groupid'] = $groupid;
|
| - |
|
3464 |
} else if ($this->cm->groupingid) {
|
| - |
|
3465 |
// If not, is there a groupingid set on the activity?
|
| 3498 |
$sql .= " JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) ";
|
3466 |
$sqlarray['join'][] = "JOIN {groupings_groups} gg ON gg.groupingid = :groupingid";
|
| 3499 |
$params['workshopid'.$inc] = $this->id;
|
3467 |
$sqlarray['join'][] = "JOIN {groups_members} gm ON (gm.userid = u.id AND gm.groupid = gg.groupid)";
|
| 3500 |
}
|
3468 |
$params['groupingid'] = $this->cm->groupingid;
|
| 3501 |
|
3469 |
}
|
| 3502 |
// If the activity is restricted so that only certain users should appear
|
3470 |
|
| 3503 |
// in user lists, integrate this into the same SQL.
|
3471 |
// Is the activity restricted so only certain users can access it?
|
| Línea -... |
Línea 3472... |
| - |
|
3472 |
$info = new \core_availability\info_module($this->cm);
|
| - |
|
3473 |
[$listsql, $listparams] = $info->get_user_list_sql(false);
|
| - |
|
3474 |
if ($listsql) {
|
| - |
|
3475 |
$sqlarray['join'][] = " JOIN ($listsql) restricted ON restricted.id = u.id";
|
| - |
|
3476 |
$params = array_merge($params, $listparams);
|
| - |
|
3477 |
}
|
| - |
|
3478 |
|
| - |
|
3479 |
// Join the role assignments to only return users with the right capabilities.
|
| - |
|
3480 |
$capjoin = get_with_capability_join($this->context, $capabilities, 'u.id');
|
| - |
|
3481 |
$sqlarray['join'][] = $capjoin->joins;
|
| - |
|
3482 |
|
| - |
|
3483 |
// Convert the sql array into a string.
|
| - |
|
3484 |
$sql = $this->build_sql($sqlarray);
|
| - |
|
3485 |
|
| - |
|
3486 |
// We actually query the users here instead of returning SQL like it used to.
|
| - |
|
3487 |
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
|
| - |
|
3488 |
|
| - |
|
3489 |
}
|
| - |
|
3490 |
|
| - |
|
3491 |
/**
|
| - |
|
3492 |
* Build SQL string from array of clauses
|
| - |
|
3493 |
*
|
| - |
|
3494 |
* @param array $sqlarray ['select' => '', 'from' => '', 'join' => [], 'where' => [], 'sort' => '']
|
| - |
|
3495 |
* @return string
|
| - |
|
3496 |
*/
|
| - |
|
3497 |
protected function build_sql(array $sqlarray): string {
|
| - |
|
3498 |
|
| - |
|
3499 |
$sql = "";
|
| - |
|
3500 |
foreach ($sqlarray as $el) {
|
| 3504 |
$info = new \core_availability\info_module($this->cm);
|
3501 |
if (is_array($el)) {
|
| - |
|
3502 |
$sql .= implode(" ", $el) . " ";
|
| 3505 |
list ($listsql, $listparams) = $info->get_user_list_sql(false);
|
3503 |
} else {
|
| Línea 3506... |
Línea 3504... |
| 3506 |
if ($listsql) {
|
3504 |
$sql .= " {$el} ";
|
| 3507 |
$sql .= " JOIN ($listsql) restricted ON restricted.id = u.id ";
|
3505 |
}
|
| 3508 |
$params = array_merge($params, $listparams);
|
3506 |
}
|
| - |
|
3507 |
|
| 3509 |
}
|
3508 |
return $sql;
|
| 3510 |
|
3509 |
|
| 3511 |
return array($sql, $params);
|
3510 |
}
|
| 3512 |
}
|
3511 |
|
| 3513 |
|
3512 |
/**
|
| 3514 |
/**
|
3513 |
* Returns SQL to fetch all enrolled users with the first name or last name.
|
| 3515 |
* Returns SQL to fetch all enrolled users with the first name or last name.
|
3514 |
*
|
| 3516 |
*
|
3515 |
* @param string $table Table alias for users table
|
| 3517 |
* @return array
|
3516 |
* @return array
|
| 3518 |
*/
|
3517 |
*/
|
| 3519 |
protected function get_users_with_initial_filtering_sql_where(): array {
|
3518 |
protected function get_users_with_initial_filtering_sql_where(string $table): array {
|
| 3520 |
global $DB;
|
3519 |
global $DB;
|
| 3521 |
$conditions = [];
|
3520 |
$conditions = [];
|
| 3522 |
$params = [];
|
3521 |
$params = [];
|
| 3523 |
$ifirst = $this->get_initial_first();
|
3522 |
$ifirst = $this->get_initial_first();
|
| 3524 |
$ilast = $this->get_initial_last();
|
3523 |
$ilast = $this->get_initial_last();
|
| 3525 |
if ($ifirst) {
|
3524 |
if ($ifirst) {
|
| 3526 |
$conditions[] = $DB->sql_like('LOWER(tmp.firstname)', ':i_first' , false, false);
|
3525 |
$conditions[] = $DB->sql_like('LOWER(' . $table . '.firstname)', ':i_first' , false, false);
|
| Línea 3527... |
Línea 3526... |
| 3527 |
$params['i_first'] = $DB->sql_like_escape($ifirst) . '%';
|
3526 |
$params['i_first'] = $DB->sql_like_escape($ifirst) . '%';
|
| 3528 |
}
|
- |
|
| 3529 |
if ($ilast) {
|
- |
|
| 3530 |
$conditions[] = $DB->sql_like('LOWER(tmp.lastname)', ':i_last' , false, false);
|
- |
|
| 3531 |
$params['i_last'] = $DB->sql_like_escape($ilast) . '%';
|
- |
|
| 3532 |
}
|
- |
|
| 3533 |
return [implode(" AND ", $conditions), $params];
|
- |
|
| 3534 |
}
|
- |
|
| 3535 |
|
- |
|
| 3536 |
/**
|
- |
|
| 3537 |
* Returns SQL statement that can be used to fetch all actively enrolled participants in the workshop
|
- |
|
| 3538 |
*
|
- |
|
| 3539 |
* @param bool $musthavesubmission if true, return only users who have already submitted
|
- |
|
| 3540 |
* @param int $groupid 0 means ignore groups, any other value limits the result by group id
|
- |
|
| 3541 |
* @return array of (string)sql, (array)params
|
- |
|
| 3542 |
*/
|
- |
|
| 3543 |
protected function get_participants_sql($musthavesubmission=false, $groupid=0) {
|
- |
|
| 3544 |
|
- |
|
| 3545 |
list($sql1, $params1) = $this->get_users_with_capability_sql('mod/workshop:submit', $musthavesubmission, $groupid);
|
- |
|
| 3546 |
list($sql2, $params2) = $this->get_users_with_capability_sql('mod/workshop:peerassess', $musthavesubmission, $groupid);
|
- |
|
| 3547 |
|
- |
|
| 3548 |
if (empty($sql1) or empty($sql2)) {
|
- |
|
| 3549 |
if (empty($sql1) and empty($sql2)) {
|
- |
|
| 3550 |
return array('', array());
|
- |
|
| 3551 |
} else if (empty($sql1)) {
|
- |
|
| 3552 |
$sql = $sql2;
|
- |
|
| 3553 |
$params = $params2;
|
- |
|
| 3554 |
} else {
|
- |
|
| 3555 |
$sql = $sql1;
|
- |
|
| 3556 |
$params = $params1;
|
- |
|
| 3557 |
}
|
- |
|
| 3558 |
} else {
|
3527 |
}
|
| 3559 |
$sql = $sql1.PHP_EOL." UNION ".PHP_EOL.$sql2;
|
3528 |
if ($ilast) {
|
| 3560 |
$params = array_merge($params1, $params2);
|
3529 |
$conditions[] = $DB->sql_like('LOWER(' . $table . '.lastname)', ':i_last' , false, false);
|
| 3561 |
}
|
3530 |
$params['i_last'] = $DB->sql_like_escape($ilast) . '%';
|
| 3562 |
|
3531 |
}
|