Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-52242

Competencies listed in a completed plan must never change

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: None
    • Component/s: Competencies
    • Labels:
    • Testing Instructions:
      Hide

      User learning plan created from a template and completed doesn't change when the template is modified (add or remove competency)

      • Create a framework with competencies: Site Administration > Frameworks.
      • Create a template and associate it some competencies: Site Administration > learning plans.
      • Create a user plan from that template (click the number under Users plan and select a user).
      • In the user plans click on the plan created and check that competencies are identical to those in template.
      • Go back to the list of learning plans of that user. and change the status: Edit > Complete this learning plan. Status of plan become Complete.
      • Go to the template and add a competency to it.
      • Come back to the user learning plan and check the list of competencies didn't change.

      User learning plan created manually and completed can't be modified (add or remove competency)

      • Go to Profile > Learning plans and add a learning plan with the status active
      • Click on learning plan and add competencies to it.
      • Go back to the list of Learning plans list and change the status Edit > Complete this learning plan.
      • Click on the learning plan and check that buttons to remove and add competency aren't shown.
      Show
      User learning plan created from a template and completed doesn't change when the template is modified (add or remove competency) Create a framework with competencies: Site Administration > Frameworks. Create a template and associate it some competencies: Site Administration > learning plans. Create a user plan from that template (click the number under Users plan and select a user). In the user plans click on the plan created and check that competencies are identical to those in template. Go back to the list of learning plans of that user. and change the status: Edit > Complete this learning plan. Status of plan become Complete. Go to the template and add a competency to it. Come back to the user learning plan and check the list of competencies didn't change. User learning plan created manually and completed can't be modified (add or remove competency) Go to Profile > Learning plans and add a learning plan with the status active Click on learning plan and add competencies to it. Go back to the list of Learning plans list and change the status Edit > Complete this learning plan. Click on the learning plan and check that buttons to remove and add competency aren't shown.
    • Affected Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-52242_master
    • Story Points:
      2
    • Sprint:
      CBE Sprint 3

      Description

      When we get the competencies of a completed learning plan, we need to get the list of competencies from the archived we created when the plan was marked as complete. The reason for this is because while a plan cannot be changed once it's complete, a template could change and those changes would be reflected in the plan. Once a plan is complete it should be frozen.

      There are a few ways to fix this:

      1. Unlink the plan from its template upon completion (not recommended, heavy, relationship lost)
      2. Copy the template_competencies to plan_competencies (almost acts unlink, heavy, adds weird conditional getters in $plan->get_competencies()
      3. Add an additional condition to $plan->get_competencies() to generate the list of competencies from the archived competencies (sortorder of competencies is hard to figure out)

      I have started a patch for this, but tests failed because it broke the archiving mechanism.

      diff --git a/admin/tool/lp/classes/plan.php b/admin/tool/lp/classes/plan.php
      index f55d4a7..3d84889 100644
      --- a/admin/tool/lp/classes/plan.php
      +++ b/admin/tool/lp/classes/plan.php
      @@ -121,13 +121,19 @@ class plan extends persistent {
            */
           public function get_competencies() {
               $competencies = array();
      -        if ($this->get_templateid()) {
      +        if ($this->get_status() == self::STATUS_COMPLETE) {
      +            // Get the competencies from the archive of the plan.
      +            $competencies = user_competency_plan::list_competencies($this->get_id(), $this->get_userid());
      +
      +        } else if ($this->is_based_on_template()) {
                   // Get the competencies from the template.
                   $competencies = template_competency::list_competencies($this->get_templateid(), true);
      +
               } else {
                   // Get the competencies from the plan.
                   $competencies = plan_competency::list_competencies($this->get_id());
               }
      +
               return $competencies;
           }
       
      diff --git a/admin/tool/lp/classes/user_competency_plan.php b/admin/tool/lp/classes/user_competency_plan.php
      index f89ed1d..8315a69 100644
      --- a/admin/tool/lp/classes/user_competency_plan.php
      +++ b/admin/tool/lp/classes/user_competency_plan.php
      @@ -143,6 +143,38 @@ class user_competency_plan extends persistent {
           }
       
           /**
      +     * List the competencies in this plan.
      +     *
      +     * @param int $planid The plan ID
      +     * @param int $userid The user ID
      +     * @return competency[]
      +     */
      +    public static function list_competencies($planid, $userid) {
      +        global $DB;
      +
      +        // TODO Fix ordering. The order set in template_competency, or plan_competency is not applied here.
      +        // Perhaps we should have copied the sortorder here as well.
      +        $sql = 'SELECT c.*
      +                  FROM {' . competency::TABLE . '} c
      +                  JOIN {' . self::TABLE . '} ucp
      +                    ON ucp.competencyid = c.id
      +                   AND ucp.userid = :userid
      +                 WHERE ucp.planid = :planid';
      +        $params = array('userid' => $userid, 'planid' => $planid);
      +
      +        // TODO MDL-52229 Handle hidden competencies.
      +        $results = $DB->get_recordset_sql($sql, $params);
      +
      +        $instances = array();
      +        foreach ($results as $key => $result) {
      +            $instances[$key] = new competency(0, $result);
      +        }
      +        $results->close();
      +
      +        return $instances;
      +    }
      +
      +    /**
            * Get multiple user_competency_plan for a user.
            *
            * @param int $userid The user ID.
      
      

      Along with this, this issue should also ensure that a user can not:

      • Remove a competency from a completed plan
      • Add a new competency from a completed plan

        Attachments

          Activity

            People

            • Assignee:
              sergeg55 Serge Gauthier
              Reporter:
              fred Frédéric Massart
              Peer reviewer:
              Frédéric Massart
              Participants:
              Component watchers:
              Damyon Wiese, Jean-Philippe Gaudreau, Steve Massicotte, Serge Gauthier, Issam Taboubi, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: