Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 22... Línea 22...
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
24
namespace core_competency;
24
namespace core_competency;
25
defined('MOODLE_INTERNAL') || die();
25
defined('MOODLE_INTERNAL') || die();
Línea -... Línea 26...
-
 
26
 
26
 
27
use core\invalid_persistent_exception;
27
use stdClass;
28
use stdClass;
28
use cm_info;
29
use cm_info;
29
use context;
30
use context;
30
use context_helper;
31
use context_helper;
Línea 119... Línea 120...
119
                    OR c.id IS NOT NULL";
120
                    OR c.id IS NOT NULL";
120
        return $DB->record_exists_sql($sql, ['scaleid1' => $scaleid, 'scaleid2' => $scaleid]);
121
        return $DB->record_exists_sql($sql, ['scaleid1' => $scaleid, 'scaleid2' => $scaleid]);
121
    }
122
    }
Línea 122... Línea 123...
122
 
123
 
123
    /**
124
    /**
124
     * Validate if current user have acces to the course_module if hidden.
125
     * Validate if current user has access to the course_module if hidden.
125
     *
126
     *
126
     * @param mixed $cmmixed The cm_info class, course module record or its ID.
127
     * @param mixed $cmmixed The cm_info class, course module record or its ID.
127
     * @param bool $throwexception Throw an exception or not.
128
     * @param bool $throwexception Throw an exception or not.
128
     * @return bool
129
     * @return bool
Línea 149... Línea 150...
149
 
150
 
150
        return true;
151
        return true;
Línea 151... Línea 152...
151
    }
152
    }
152
 
153
 
153
    /**
154
    /**
154
     * Validate if current user have acces to the course if hidden.
155
     * Validate if current user has access to the course if hidden.
155
     *
156
     *
156
     * @param mixed $courseorid The course or it ID.
157
     * @param mixed $courseorid The course or it ID.
157
     * @param bool $throwexception Throw an exception or not.
158
     * @param bool $throwexception Throw an exception or not.
Línea 451... Línea 452...
451
 
452
 
452
        return $result;
453
        return $result;
Línea 453... Línea 454...
453
    }
454
    }
454
 
455
 
455
    /**
456
    /**
456
     * Read a the details for a single competency and return a record.
457
     * Read the details for a single competency and return a record.
457
     *
458
     *
458
     * Requires moodle/competency:competencyview capability at the system context.
459
     * Requires moodle/competency:competencyview capability at the system context.
459
     *
460
     *
Línea 481... Línea 482...
481
 
482
 
482
        return $competency;
483
        return $competency;
Línea 483... Línea 484...
483
    }
484
    }
484
 
485
 
485
    /**
486
    /**
486
     * Perform a text search based and return all results and their parents.
487
     * Perform a search based on a text and return all results and their parents.
487
     *
488
     *
488
     * Requires moodle/competency:competencyview capability at the framework context.
489
     * Requires moodle/competency:competencyview capability at the framework context.
489
     *
490
     *
Línea 612... Línea 613...
612
            // Adding the suffix copy to the shortname.
613
            // Adding the suffix copy to the shortname.
613
            $framework->set('shortname', get_string('duplicateditemname', 'core_competency', $framework->get('shortname')));
614
            $framework->set('shortname', get_string('duplicateditemname', 'core_competency', $framework->get('shortname')));
614
            $framework->set('id', 0);
615
            $framework->set('id', 0);
615
            $framework = $framework->create();
616
            $framework = $framework->create();
Línea 616... Línea 617...
616
 
617
 
617
            // Array that match the old competencies ids with the new one to use when copying related competencies.
618
            // Array that matches the old competencies ids with the new one to use when copying related competencies.
618
            $frameworkcompetency = competency::get_framework_tree($id);
619
            $frameworkcompetency = competency::get_framework_tree($id);
Línea 619... Línea 620...
619
            $matchids = self::duplicate_competency_tree($framework->get('id'), $frameworkcompetency, 0, 0);
620
            $matchids = self::duplicate_competency_tree($framework->get('id'), $frameworkcompetency, 0, 0);
620
 
621
 
Línea 702... Línea 703...
702
        }
703
        }
Línea 703... Línea 704...
703
 
704
 
704
        // Commit the transaction.
705
        // Commit the transaction.
Línea 705... Línea 706...
705
        $transaction->allow_commit();
706
        $transaction->allow_commit();
706
 
707
 
Línea 707... Línea 708...
707
        // If all operations are successfull then trigger the delete event.
708
        // If all operations are successful then trigger the delete event.
708
        $event->trigger();
709
        $event->trigger();
709
 
710
 
Línea 741... Línea 742...
741
 
742
 
742
        return $framework->update();
743
        return $framework->update();
Línea 743... Línea 744...
743
    }
744
    }
744
 
745
 
745
    /**
746
    /**
746
     * Read a the details for a single competency framework and return a record.
747
     * Read the details for a single competency framework and return a record.
747
     *
748
     *
748
     * Requires moodle/competency:competencyview capability at the system context.
749
     * Requires moodle/competency:competencyview capability at the system context.
749
     *
750
     *
Línea 760... Línea 761...
760
        }
761
        }
761
        return $framework;
762
        return $framework;
762
    }
763
    }
Línea 763... Línea 764...
763
 
764
 
764
    /**
765
    /**
765
     * Logg the competency framework viewed event.
766
     * Log the competency framework viewed event.
766
     *
767
     *
767
     * @param competency_framework|int $frameworkorid The competency_framework object or competency framework id
768
     * @param competency_framework|int $frameworkorid The competency_framework object or competency framework id
768
     * @return bool
769
     * @return bool
769
     */
770
     */
Línea 781... Línea 782...
781
        \core\event\competency_framework_viewed::create_from_framework($framework)->trigger();
782
        \core\event\competency_framework_viewed::create_from_framework($framework)->trigger();
782
        return true;
783
        return true;
783
    }
784
    }
Línea 784... Línea 785...
784
 
785
 
785
    /**
786
    /**
786
     * Logg the competency viewed event.
787
     * Log the competency viewed event.
787
     *
788
     *
788
     * @param competency|int $competencyorid The competency object or competency id
789
     * @param competency|int $competencyorid The competency object or competency id
789
     * @return bool
790
     * @return bool
790
     */
791
     */
Línea 901... Línea 902...
901
     *                          - parents: All parents, grand parents, etc...
902
     *                          - parents: All parents, grand parents, etc...
902
     *                          - self: Context passed only.
903
     *                          - self: Context passed only.
903
     * @param array $hasanycapability Array of capabilities passed to {@link has_any_capability()} in each context.
904
     * @param array $hasanycapability Array of capabilities passed to {@link has_any_capability()} in each context.
904
     * @return context[] An array of contexts where keys are context IDs.
905
     * @return context[] An array of contexts where keys are context IDs.
905
     */
906
     */
906
    public static function get_related_contexts($context, $includes, array $hasanycapability = null) {
907
    public static function get_related_contexts($context, $includes, ?array $hasanycapability = null) {
907
        global $DB;
908
        global $DB;
908
        static::require_enabled();
909
        static::require_enabled();
Línea 909... Línea 910...
909
 
910
 
910
        if (!in_array($includes, array('children', 'parents', 'self'))) {
911
        if (!in_array($includes, array('children', 'parents', 'self'))) {
Línea 1022... Línea 1023...
1022
        $cm = $cmorid;
1023
        $cm = $cmorid;
1023
        if (!is_object($cmorid)) {
1024
        if (!is_object($cmorid)) {
1024
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1025
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1025
        }
1026
        }
Línea 1026... Línea 1027...
1026
 
1027
 
1027
        // Check the user have access to the course module.
1028
        // Check the user has access to the course module.
1028
        self::validate_course_module($cm);
1029
        self::validate_course_module($cm);
Línea 1029... Línea 1030...
1029
        $context = context_module::instance($cm->id);
1030
        $context = context_module::instance($cm->id);
1030
 
1031
 
Línea 1081... Línea 1082...
1081
     * @param int $userid The id of the user to check.
1082
     * @param int $userid The id of the user to check.
1082
     * @return int
1083
     * @return int
1083
     */
1084
     */
1084
    public static function count_proficient_competencies_in_course_for_user($courseid, $userid) {
1085
    public static function count_proficient_competencies_in_course_for_user($courseid, $userid) {
1085
        static::require_enabled();
1086
        static::require_enabled();
1086
        // Check the user have access to the course.
1087
        // Check the user has access to the course.
1087
        self::validate_course($courseid);
1088
        self::validate_course($courseid);
Línea 1088... Línea 1089...
1088
 
1089
 
1089
        // First we do a permissions check.
1090
        // First we do a permissions check.
Línea 1104... Línea 1105...
1104
     * @param int $courseid The id of the course to check.
1105
     * @param int $courseid The id of the course to check.
1105
     * @return int
1106
     * @return int
1106
     */
1107
     */
1107
    public static function count_competencies_in_course($courseid) {
1108
    public static function count_competencies_in_course($courseid) {
1108
        static::require_enabled();
1109
        static::require_enabled();
1109
        // Check the user have access to the course.
1110
        // Check the user has access to the course.
1110
        self::validate_course($courseid);
1111
        self::validate_course($courseid);
Línea 1111... Línea 1112...
1111
 
1112
 
1112
        // First we do a permissions check.
1113
        // First we do a permissions check.
Línea 1135... Línea 1136...
1135
        $course = $courseorid;
1136
        $course = $courseorid;
1136
        if (!is_object($courseorid)) {
1137
        if (!is_object($courseorid)) {
1137
            $course = get_course($courseorid);
1138
            $course = get_course($courseorid);
1138
        }
1139
        }
Línea 1139... Línea 1140...
1139
 
1140
 
1140
        // Check the user have access to the course.
1141
        // Check the user has access to the course.
1141
        self::validate_course($course);
1142
        self::validate_course($course);
Línea 1142... Línea 1143...
1142
        $context = context_course::instance($course->id);
1143
        $context = context_course::instance($course->id);
1143
 
1144
 
Línea 1214... Línea 1215...
1214
        $cm = $cmorid;
1215
        $cm = $cmorid;
1215
        if (!is_object($cmorid)) {
1216
        if (!is_object($cmorid)) {
1216
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1217
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1217
        }
1218
        }
Línea 1218... Línea 1219...
1218
 
1219
 
1219
        // Check the user have access to the course module.
1220
        // Check the user has access to the course module.
1220
        self::validate_course_module($cm);
1221
        self::validate_course_module($cm);
Línea 1221... Línea 1222...
1221
        $context = context_module::instance($cm->id);
1222
        $context = context_module::instance($cm->id);
1222
 
1223
 
Línea 1242... Línea 1243...
1242
        $cm = $cmorid;
1243
        $cm = $cmorid;
1243
        if (!is_object($cmorid)) {
1244
        if (!is_object($cmorid)) {
1244
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1245
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1245
        }
1246
        }
Línea 1246... Línea 1247...
1246
 
1247
 
1247
        // Check the user have access to the course module.
1248
        // Check the user has access to the course module.
1248
        self::validate_course_module($cm);
1249
        self::validate_course_module($cm);
Línea 1249... Línea 1250...
1249
        $context = context_module::instance($cm->id);
1250
        $context = context_module::instance($cm->id);
1250
 
1251
 
Línea 1454... Línea 1455...
1454
        $cm = $cmorid;
1455
        $cm = $cmorid;
1455
        if (!is_object($cmorid)) {
1456
        if (!is_object($cmorid)) {
1456
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1457
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1457
        }
1458
        }
Línea 1458... Línea 1459...
1458
 
1459
 
1459
        // Check the user have access to the course module.
1460
        // Check the user has access to the course module.
Línea 1460... Línea 1461...
1460
        self::validate_course_module($cm);
1461
        self::validate_course_module($cm);
1461
 
1462
 
Línea 1496... Línea 1497...
1496
        static::require_enabled();
1497
        static::require_enabled();
1497
        $cm = $cmorid;
1498
        $cm = $cmorid;
1498
        if (!is_object($cmorid)) {
1499
        if (!is_object($cmorid)) {
1499
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1500
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1500
        }
1501
        }
1501
        // Check the user have access to the course module.
1502
        // Check the user has access to the course module.
1502
        self::validate_course_module($cm);
1503
        self::validate_course_module($cm);
Línea 1503... Línea 1504...
1503
 
1504
 
1504
        // First we do a permissions check.
1505
        // First we do a permissions check.
Línea 1532... Línea 1533...
1532
        static::require_enabled();
1533
        static::require_enabled();
1533
        $cm = $cmorid;
1534
        $cm = $cmorid;
1534
        if (!is_object($cmorid)) {
1535
        if (!is_object($cmorid)) {
1535
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1536
            $cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
1536
        }
1537
        }
1537
        // Check the user have access to the course module.
1538
        // Check the user has access to the course module.
1538
        self::validate_course_module($cm);
1539
        self::validate_course_module($cm);
Línea 1539... Línea 1540...
1539
 
1540
 
1540
        // First we do a permissions check.
1541
        // First we do a permissions check.
Línea 1613... Línea 1614...
1613
     * @param int $competencyid The id of the competency
1614
     * @param int $competencyid The id of the competency
1614
     * @return bool
1615
     * @return bool
1615
     */
1616
     */
1616
    public static function add_competency_to_course($courseid, $competencyid) {
1617
    public static function add_competency_to_course($courseid, $competencyid) {
1617
        static::require_enabled();
1618
        static::require_enabled();
1618
        // Check the user have access to the course.
1619
        // Check the user has access to the course.
1619
        self::validate_course($courseid);
1620
        self::validate_course($courseid);
Línea 1620... Línea 1621...
1620
 
1621
 
1621
        // First we do a permissions check.
1622
        // First we do a permissions check.
Línea 1627... Línea 1628...
1627
        $record->courseid = $courseid;
1628
        $record->courseid = $courseid;
1628
        $record->competencyid = $competencyid;
1629
        $record->competencyid = $competencyid;
Línea 1629... Línea 1630...
1629
 
1630
 
Línea 1630... Línea 1631...
1630
        $competency = new competency($competencyid);
1631
        $competency = new competency($competencyid);
1631
 
1632
 
1632
        // Can not add a competency that belong to a hidden framework.
1633
        // Can not add a competency that belongs to a hidden framework.
1633
        if ($competency->get_framework()->get('visible') == false) {
1634
        if ($competency->get_framework()->get('visible') == false) {
Línea 1634... Línea 1635...
1634
            throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
1635
            throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
Línea 1652... Línea 1653...
1652
     * @param int $competencyid The id of the competency
1653
     * @param int $competencyid The id of the competency
1653
     * @return bool
1654
     * @return bool
1654
     */
1655
     */
1655
    public static function remove_competency_from_course($courseid, $competencyid) {
1656
    public static function remove_competency_from_course($courseid, $competencyid) {
1656
        static::require_enabled();
1657
        static::require_enabled();
1657
        // Check the user have access to the course.
1658
        // Check the user has access to the course.
1658
        self::validate_course($courseid);
1659
        self::validate_course($courseid);
Línea 1659... Línea 1660...
1659
 
1660
 
1660
        // First we do a permissions check.
1661
        // First we do a permissions check.
Línea 1689... Línea 1690...
1689
     * @param int $competencyidto The id of the competency we are moving to.
1690
     * @param int $competencyidto The id of the competency we are moving to.
1690
     * @return boolean
1691
     * @return boolean
1691
     */
1692
     */
1692
    public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) {
1693
    public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) {
1693
        static::require_enabled();
1694
        static::require_enabled();
1694
        // Check the user have access to the course.
1695
        // Check the user has access to the course.
1695
        self::validate_course($courseid);
1696
        self::validate_course($courseid);
Línea 1696... Línea 1697...
1696
 
1697
 
1697
        // First we do a permissions check.
1698
        // First we do a permissions check.
Línea 1951... Línea 1952...
1951
 
1952
 
1952
        return $success;
1953
        return $success;
Línea 1953... Línea 1954...
1953
    }
1954
    }
1954
 
1955
 
1955
    /**
1956
    /**
1956
     * Read a the details for a single learning plan template and return a record.
1957
     * Read the details for a single learning plan template and return a record.
1957
     *
1958
     *
1958
     * Requires moodle/competency:templateview capability at the system context.
1959
     * Requires moodle/competency:templateview capability at the system context.
1959
     *
1960
     *
Línea 2194... Línea 2195...
2194
        $record->templateid = $templateid;
2195
        $record->templateid = $templateid;
2195
        $record->competencyid = $competencyid;
2196
        $record->competencyid = $competencyid;
Línea 2196... Línea 2197...
2196
 
2197
 
Línea 2197... Línea 2198...
2197
        $competency = new competency($competencyid);
2198
        $competency = new competency($competencyid);
2198
 
2199
 
2199
        // Can not add a competency that belong to a hidden framework.
2200
        // Can not add a competency that belongs to a hidden framework.
2200
        if ($competency->get_framework()->get('visible') == false) {
2201
        if ($competency->get_framework()->get('visible') == false) {
Línea 2201... Línea 2202...
2201
            throw new coding_exception('A competency belonging to hidden framework can not be added');
2202
            throw new coding_exception('A competency belonging to hidden framework can not be added');
Línea 2683... Línea 2684...
2683
        // The user must be allowed to manage the plans of the user, nothing about the template.
2684
        // The user must be allowed to manage the plans of the user, nothing about the template.
2684
        if (!$plan->can_manage()) {
2685
        if (!$plan->can_manage()) {
2685
            throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
2686
            throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
2686
        }
2687
        }
Línea 2687... Línea 2688...
2687
 
2688
 
2688
        // Only plan with status DRAFT or ACTIVE can be unliked..
2689
        // Only plan with status DRAFT or ACTIVE can be unlinked..
2689
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
2690
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
2690
            throw new coding_exception('Only draft or active plan can be unliked from a template');
2691
            throw new coding_exception('Only draft or active plan can be unlinked from a template');
Línea 2691... Línea 2692...
2691
        }
2692
        }
2692
 
2693
 
2693
        // Early exit, it's already done...
2694
        // Early exit, it's already done...
Línea 3360... Línea 3361...
3360
        } else if ($plan->is_based_on_template()) {
3361
        } else if ($plan->is_based_on_template()) {
3361
            throw new coding_exception('A competency can not be added to a learning plan based on a template');
3362
            throw new coding_exception('A competency can not be added to a learning plan based on a template');
3362
        }
3363
        }
Línea 3363... Línea 3364...
3363
 
3364
 
3364
        if (!$plan->can_be_edited()) {
3365
        if (!$plan->can_be_edited()) {
3365
            throw new coding_exception('A competency can not be added to a learning plan completed');
3366
            throw new coding_exception('A competency can not be added to a completed learning plan');
Línea 3366... Línea 3367...
3366
        }
3367
        }
Línea 3367... Línea 3368...
3367
 
3368
 
Línea 3403... Línea 3404...
3403
        } else if ($plan->is_based_on_template()) {
3404
        } else if ($plan->is_based_on_template()) {
3404
            throw new coding_exception('A competency can not be removed from a learning plan based on a template');
3405
            throw new coding_exception('A competency can not be removed from a learning plan based on a template');
3405
        }
3406
        }
Línea 3406... Línea 3407...
3406
 
3407
 
3407
        if (!$plan->can_be_edited()) {
3408
        if (!$plan->can_be_edited()) {
3408
            throw new coding_exception('A competency can not be removed from a learning plan completed');
3409
            throw new coding_exception('A competency can not be removed from a completed learning plan');
Línea 3409... Línea 3410...
3409
        }
3410
        }
3410
 
3411
 
3411
        $link = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
3412
        $link = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
Línea 3437... Línea 3438...
3437
        } else if ($plan->is_based_on_template()) {
3438
        } else if ($plan->is_based_on_template()) {
3438
            throw new coding_exception('A competency can not be reordered in a learning plan based on a template');
3439
            throw new coding_exception('A competency can not be reordered in a learning plan based on a template');
3439
        }
3440
        }
Línea 3440... Línea 3441...
3440
 
3441
 
3441
        if (!$plan->can_be_edited()) {
3442
        if (!$plan->can_be_edited()) {
3442
            throw new coding_exception('A competency can not be reordered in a learning plan completed');
3443
            throw new coding_exception('A competency can not be reordered in a completed learning plan');
Línea 3443... Línea 3444...
3443
        }
3444
        }
3444
 
3445
 
3445
        $down = true;
3446
        $down = true;
Línea 3489... Línea 3490...
3489
        $context = context_user::instance($userid);
3490
        $context = context_user::instance($userid);
3490
        $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
3491
        $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
3491
        if (!$uc || !$uc->can_read()) {
3492
        if (!$uc || !$uc->can_read()) {
3492
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
3493
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
3493
        } else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
3494
        } else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
3494
            throw new coding_exception('The competency can not be cancel review request at this stage.');
3495
            throw new coding_exception('The competency review request can not be cancelled at this stage.');
3495
        } else if (!$uc->can_request_review()) {
3496
        } else if (!$uc->can_request_review()) {
3496
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyrequestreview', 'nopermissions', '');
3497
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyrequestreview', 'nopermissions', '');
3497
        }
3498
        }
Línea 3498... Línea 3499...
3498
 
3499
 
Línea 3634... Línea 3635...
3634
            throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
3635
            throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
3635
                'nopermissions', '');
3636
                'nopermissions', '');
3636
        }
3637
        }
3637
        $plan = new plan($planid);
3638
        $plan = new plan($planid);
3638
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
3639
        if ($plan->get('status') == plan::STATUS_COMPLETE) {
3639
            throw new coding_exception('To log the user competency in completed plan use user_competency_plan_viewed method.');
3640
            throw new coding_exception('To log the user competency in a completed plan use the user_competency_plan_viewed method.');
3640
        }
3641
        }
Línea 3641... Línea 3642...
3641
 
3642
 
3642
        \core\event\competency_user_competency_viewed_in_plan::create_from_user_competency_viewed_in_plan($uc, $planid)->trigger();
3643
        \core\event\competency_user_competency_viewed_in_plan::create_from_user_competency_viewed_in_plan($uc, $planid)->trigger();
3643
        return true;
3644
        return true;
Línea 3767... Línea 3768...
3767
     */
3768
     */
3768
    public static function remove_related_competency($competencyid, $relatedcompetencyid) {
3769
    public static function remove_related_competency($competencyid, $relatedcompetencyid) {
3769
        static::require_enabled();
3770
        static::require_enabled();
3770
        $competency = new competency($competencyid);
3771
        $competency = new competency($competencyid);
Línea 3771... Línea 3772...
3771
 
3772
 
3772
        // This only check if we have the permission in either competency because both competencies
3773
        // This only checks if we have the permission in either competency because both competencies
3773
        // should belong to the same framework.
3774
        // should belong to the same framework.
Línea 3774... Línea 3775...
3774
        require_capability('moodle/competency:competencymanage', $competency->get_context());
3775
        require_capability('moodle/competency:competencymanage', $competency->get_context());
3775
 
3776
 
Línea 4321... Línea 4322...
4321
                // The logic here goes like this:
4322
                // The logic here goes like this:
4322
                //
4323
                //
4323
                // if rating outside a course
4324
                // if rating outside a course
4324
                // - set the default grade and proficiency ONLY if there is no current grade
4325
                // - set the default grade and proficiency ONLY if there is no current grade
4325
                // else we are in a course
4326
                // else we are in a course
4326
                // - set the defautl grade and proficiency in the course ONLY if there is no current grade in the course
4327
                // - set the default grade and proficiency in the course ONLY if there is no current grade in the course
4327
                // - then check the course settings to see if we should push the rating outside the course
4328
                // - then check the course settings to see if we should push the rating outside the course
4328
                // - if we should push it
4329
                // - if we should push it
4329
                // --- push it only if the user_competency (outside the course) has no grade
4330
                // --- push it only if the user_competency (outside the course) has no grade
4330
                // Done.
4331
                // Done.
Línea 4560... Línea 4561...
4560
     * @param  user_competency $usercompetency The user competency recently completed.
4561
     * @param  user_competency $usercompetency The user competency recently completed.
4561
     * @param  competency|null $competency     The competency of the user competency, useful to avoid unnecessary read.
4562
     * @param  competency|null $competency     The competency of the user competency, useful to avoid unnecessary read.
4562
     * @return void
4563
     * @return void
4563
     */
4564
     */
4564
    protected static function apply_competency_rules_from_usercompetency(user_competency $usercompetency,
4565
    protected static function apply_competency_rules_from_usercompetency(user_competency $usercompetency,
4565
                                                                         competency $competency = null, $overridegrade = false) {
4566
                                                                         ?competency $competency = null, $overridegrade = false) {
Línea 4566... Línea 4567...
4566
 
4567
 
4567
        // Perform some basic checks.
4568
        // Perform some basic checks.
4568
        if (!$usercompetency->get('proficiency')) {
4569
        if (!$usercompetency->get('proficiency')) {
4569
            throw new coding_exception('The user competency passed is not completed.');
4570
            throw new coding_exception('The user competency passed is not completed.');