Returns user evaluation data for a given leaf competency.

@param Competency $competency
@param User       $user

@return mixed
547336
public function listLeafCompetencyLogs(Competency $competency, User $user)
    {
        return $this->abilityRepo->findEvaluationsByCompetency($competency, $user);
    }
1066112
protected static function export_user_data_learning_plans(context_user $context) {
        global $DB;

        $userid = $context->instanceid;
        $path = [get_string('competencies', 'core_competency'), get_string('privacy:path:plans', 'core_competency')];
        $helper = new performance_helper();
        $pfields = plan::get_sql_fields('p', 'p_');
        $pcfields = plan_competency::get_sql_fields('pc', 'pc_');
        $cfields = competency::get_sql_fields('c', 'c_');
        $ucfields = user_competency::get_sql_fields('uc', 'uc_');
        $ucpfields = user_competency_plan::get_sql_fields('ucp', 'ucp_');

        // The user's learning plans.
        $sql = "
            SELECT $pfields, $pcfields, $cfields, $ucfields, $ucpfields
              FROM {" . plan::TABLE . "} p
         LEFT JOIN {" . plan_competency::TABLE . "} pc
                ON p.id = pc.planid
               AND p.templateid IS NULL
               AND p.status != :complete1
         LEFT JOIN {" . template_competency::TABLE . "} tc
                ON tc.templateid = p.templateid
               AND p.templateid IS NOT NULL
               AND p.status != :complete2
         LEFT JOIN {" . user_competency_plan::TABLE . "} ucp
                ON ucp.planid = p.id
               AND p.status = :complete3
         LEFT JOIN {" . competency::TABLE . "} c
                ON c.id = pc.competencyid
                OR c.id = tc.competencyid
                OR c.id = ucp.competencyid
         LEFT JOIN {" . user_competency::TABLE . "} uc
                ON uc.userid = p.userid
               AND (uc.competencyid = pc.competencyid OR uc.competencyid = tc.competencyid)
             WHERE p.userid = :userid
          ORDER BY p.id, c.id";
        $params = [
            'userid' => $userid,
            'complete1' => plan::STATUS_COMPLETE,
            'complete2' => plan::STATUS_COMPLETE,
            'complete3' => plan::STATUS_COMPLETE,
        ];

        $recordset = $DB->get_recordset_sql($sql, $params);
        static::recordset_loop_and_export($recordset, 'p_id', null, function($carry, $record) use ($userid, $helper, $context) {
            $iscomplete = $record->p_status == plan::STATUS_COMPLETE;

            if ($carry === null) {
                $plan = new plan(null, plan::extract_record($record, 'p_'));
                $options = ['context' => $context];
                $carry = [
                    'name' => format_string($plan->get('name'), true, $options),
                    'description' => format_text($plan->get('description'), $plan->get('descriptionformat'), $options),
                    'status' => $plan->get_statusname(),
                    'duedate' => $plan->get('duedate') ? transform::datetime($plan->get('duedate')) : '-',
                    'reviewerid' => $plan->get('reviewerid') ? transform::user($plan->get('reviewerid')) : '-',
                    'timecreated' => transform::datetime($plan->get('timecreated')),
                    'timemodified' => transform::datetime($plan->get('timemodified')),
                    'competencies' => [],
                ];
            }

            // The plan is empty.
            if (empty($record->c_id)) {
                return $carry;
            }

            $competency = new competency(null, competency::extract_record($record, 'c_'));
            $rating = null;

            if ($iscomplete) {
                // When the plan is complete, we should always found the user_competency_plan.
                $ucp = new user_competency_plan(null, user_competency_plan::extract_record($record, 'ucp_'));
                $rating = static::transform_user_competency($userid, $ucp, $competency, $helper);

            } else if (!empty($record->uc_id)) {
                // When the plan is complete, there are still records of user_competency but we do not
                // export them here, we export them as part of the competencies structure. The reason why
                // we try to get the user_competency when the plan is not complete is to give the most accurate
                // representation of the plan as possible.
                $uc = new user_competency(null, user_competency::extract_record($record, 'uc_'));
                $rating = static::transform_user_competency($userid, $uc, $competency, $helper);
            }

            $carry['competencies'][] = array_merge(static::transform_competency_brief($competency), ['rating' => $rating]);
            return $carry;

        }, function($planid, $data) use ($context, $path) {
            $planpath = array_merge($path, [$data['name'] . ' (' . $planid . ')']);
            \core_comment\privacy\provider::export_comments($context, 'competency', 'plan', $planid, $planpath, false);
            writer::with_context($context)->export_data($planpath, (object) $data);
        });
    }
1089340
public function render_user_competency_summary_in_course(user_competency_summary_in_course $page) {
        $data = $page->export_for_template($this);
        return parent::render_from_template('tool_lp/user_competency_summary_in_course', $data);
    }
1272473
public static function data_for_user_competency_summary_in_plan($competencyid, $planid) {
        global $PAGE;
        $params = self::validate_parameters(self::data_for_user_competency_summary_in_plan_parameters(), array(
            'competencyid' => $competencyid,
            'planid' => $planid
        ));

        $plan = api::read_plan($params['planid']);
        $context = $plan->get_context();
        self::validate_context($context);
        $output = $PAGE->get_renderer('tool_lp');

        $renderable = new user_competency_summary_in_plan($params['competencyid'], $params['planid']);
        return $renderable->export_for_template($output);
    }
1273243
public function findAvailableToGuideByUser(User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->leftJoin('p.portfolioGuides', 'guides')
            ->andWhere('p.user = :user')
            ->orWhere('guides.user = :guide')
            ->setParameter('user', $user)
            ->setParameter('guide', $user)
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
294119
public function createUserRole(User $user)
    {
        $username = $user->getUsername();
        $roleName = 'ROLE_USER_'.strtoupper($username);
        $role = $this->getRoleByName($roleName);

        $this->om->startFlushSuite();

        if (is_null($role)) {
            $role = new Role();
            $role->setName($roleName);
            $role->setTranslationKey($username);
            $role->setReadOnly(true);
            $role->setType(Role::USER_ROLE);
            $this->om->persist($role);
        }

        $user->addRole($role);
        $this->om->endFlushSuite();

        return $role;
    }
236152
public function findByUserAndCompetencyIds(User $user, array $competencyIds)
    {
        if (0 === count($competencyIds)) {
            return [];
        }

        return $this->createQueryBuilder('p')
            ->select('p', 'c')
            ->join('p.competency', 'c')
            ->where('p.user = :user')
            ->andWhere((new Expr())->in('p.competency', $competencyIds))
            ->setParameter(':user', $user)
            ->getQuery()
            ->getResult();
    }
229273
public static function list_plan_competencies($id) {
        global $PAGE;

        $params = self::validate_parameters(self::list_plan_competencies_parameters(), array('id' => $id));
        $id = $params['id'];
        $plan = api::read_plan($id);
        $usercontext = $plan->get_context();
        self::validate_context($usercontext);
        $output = $PAGE->get_renderer('core');

        $result = api::list_plan_competencies($plan);

        if ($plan->get('status') == plan::STATUS_COMPLETE) {
            $ucproperty = 'usercompetencyplan';
        } else {
            $ucproperty = 'usercompetency';
        }

        $helper = new performance_helper();
        foreach ($result as $key => $r) {
            $context = $helper->get_context_from_competency($r->competency);
            $scale = $helper->get_scale_from_competency($r->competency);

            $exporter = new competency_exporter($r->competency, array('context' => $context));
            $r->competency = $exporter->export($output);

            if ($r->usercompetency) {
                $exporter = new user_competency_exporter($r->usercompetency, array('scale' => $scale));
                $r->usercompetency = $exporter->export($output);
                unset($r->usercompetencyplan);
            } else {
                $exporter = new user_competency_plan_exporter($r->usercompetencyplan, array('scale' => $scale));
                $r->usercompetencyplan = $exporter->export($output);
                unset($r->usercompetency);
            }
        }
        return $result;
    }
406557
public function findByCompetencyAndLevel(Competency $competency, Level $level)
    {
        return $this->createQueryBuilder('a')
            ->select('a')
            ->join('a.competencyAbilities', 'ca')
            ->join('ca.competency', 'c')
            ->join('ca.level', 'l')
            ->where('c = :competency')
            ->andWhere('l = :level')
            ->orderBy('l.value, a.id')
            ->setParameters([
                ':competency' => $competency,
                ':level' => $level,
            ])
            ->getQuery()
            ->getResult();
    }
255538
public function get_context_from_competency(competency $competency) {
        $frameworkid = $competency->get('competencyframeworkid');
        if (!isset($this->frameworkscontexts[$frameworkid])) {
            $framework = $this->get_framework_from_competency($competency);
            $this->frameworkscontexts[$frameworkid] = $framework->get_context();
        }
        return $this->frameworkscontexts[$frameworkid];
    }
1227735
public function replaceCompetencyProgressUser(User $from, User $to)
    {
        $competencyProgresses = $this->competencyProgressRepo->findByUser($from);

        if (count($competencyProgresses) > 0) {
            foreach ($competencyProgresses as $competencyProgress) {
                $competencyProgress->setUser($to);
            }

            $this->om->flush();
        }

        return count($competencyProgresses);
    }
1316916
public function render_user_competency_course_navigation(user_competency_course_navigation $nav) {
        $data = $nav->export_for_template($this);
        return parent::render_from_template('tool_lp/user_competency_course_navigation', $data);
    }
1222100
protected static function transform_evidence($userid, evidence $evidence, competency $competency, performance_helper $helper) {
        $action = $evidence->get('action');
        $actiontxt = '?';
        if ($action == evidence::ACTION_LOG) {
            $actiontxt = get_string('privacy:evidence:action:log', 'core_competency');
        } else if ($action == evidence::ACTION_COMPLETE) {
            $actiontxt = get_string('privacy:evidence:action:complete', 'core_competency');
        } else if ($action == evidence::ACTION_OVERRIDE) {
            $actiontxt = get_string('privacy:evidence:action:override', 'core_competency');
        }

        $actionuserid = $evidence->get('actionuserid');

        return [
            'action' => $actiontxt,
            'actionuserid' => $actionuserid ? transform::user($actionuserid) : '-',
            'acting_user_is_you' => transform::yesno($userid == $actionuserid),
            'description' => (string) $evidence->get_description(),
            'url' => $evidence->get('url'),
            'grade' => static::transform_competency_grade($competency, $evidence->get('grade'), $helper),
            'note' => $evidence->get('note'),
            'timecreated' => transform::datetime($evidence->get('timecreated')),
            'timemodified' => transform::datetime($evidence->get('timemodified')),
            'created_or_modified_by_you' => transform::yesno($userid == $evidence->get('usermodified'))
        ];
    }
1162958
public function manageRoles(User $user)
    {
        $this->authorize('roles', $user);

        $roles = Role::all();

        return view('laralum_users::roles', ['user' => $user, 'roles' => $roles]);
    }
611003
public static function delete_user_evidence_competency($userevidenceid, $competencyid) {
        $params = self::validate_parameters(self::delete_user_evidence_competency_parameters(), array(
            'userevidenceid' => $userevidenceid,
            'competencyid' => $competencyid,
        ));

        $userevidence = api::read_user_evidence($params['userevidenceid']);
        self::validate_context($userevidence->get_context());

        return api::delete_user_evidence_competency($userevidence, $params['competencyid']);
    }
590724
public function findByUser(User $user, $asArray = true)
    {
        $groupQb = $this->_em->createQueryBuilder()
            ->select('g')
            ->from('Claroline\CoreBundle\Entity\Group', 'g')
            ->join('g.users', 'gu')
            ->where('gu = :user');

        $select = $asArray ? 'o.id, o.name, op.percentage AS progress, COUNT(oc) AS competencyCount' : 'o';

        $query = $this->createQueryBuilder('o')
            ->select($select)
            ->leftJoin('o.objectiveCompetencies', 'oc')
            ->leftJoin('o.users', 'ou')
            ->leftJoin('o.groups', 'og')
            ->leftJoin(
                'HeVinci\CompetencyBundle\Entity\Progress\ObjectiveProgress',
                'op',
                'WITH',
                'op.user = :user AND op.objective = o'
            )
            ->andWhere($groupQb->expr()->orX(
                'ou = :user',
                $groupQb->expr()->in('og', $groupQb->getQuery()->getDQL())
            ))
            ->groupBy('o.id')
            ->setParameter(':user', $user)
            ->getQuery();

        return $query->{$asArray ? 'getArrayResult' : 'getResult'}();
    }
1334600
public static function grade_competency($userid, $competencyid, $grade, $note = null) {
        global $USER, $PAGE;
        $params = self::validate_parameters(self::grade_competency_parameters(), array(
            'userid' => $userid,
            'competencyid' => $competencyid,
            'grade' => $grade,
            'note' => $note
        ));

        $uc = api::get_user_competency($params['userid'], $params['competencyid']);
        self::validate_context($uc->get_context());

        $output = $PAGE->get_renderer('core');
        $evidence = api::grade_competency(
                $uc->get('userid'),
                $uc->get('competencyid'),
                $params['grade'],
                $params['note']
        );

        $scale = $uc->get_competency()->get_scale();
        $exporter = new evidence_exporter($evidence, [
            'actionuser' => $USER,
            'scale' => $scale,
            'usercompetency' => $uc,
            'usercompetencyplan' => null,
            'context' => $evidence->get_context()
        ]);
        return $exporter->export($output);
    }