/** * @EXT\Route( * "/workspace/manager/activity/{activityId}/evaluations/page/{page}", * name="claro_workspace_manager_activity_evaluations_show", * defaults={"page"=1} * ) * @EXT\ParamConverter("currentUser", options={"authenticatedUser" = true}) * @EXT\ParamConverter( * "activity", * class="ClarolineCoreBundle:Resource\Activity", * options={"id" = "activityId", "strictId" = true} * ) * @EXT\Template("ClarolineCoreBundle:Tool/workspace/analytics:workspaceManagerActivityEvaluations.html.twig") * * Displays evaluations of an activity for each user of the workspace * * @return Response * * @throws \Exception */ public function workspaceManagerActivityEvaluationsShowAction(User $currentUser, Activity $activity, $page) { $roleNames = $currentUser->getRoles(); $workspace = $activity->getResourceNode()->getWorkspace(); $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames); if (!$isWorkspaceManager) { throw new AccessDeniedException(); } $resourceNode = $activity->getResourceNode(); $activityParams = $activity->getParameters(); $roles = $this->roleManager->getRolesWithRightsByResourceNode($resourceNode); $usersPager = $this->userManager->getUsersByRolesIncludingGroups($roles, $page); $users = array(); foreach ($usersPager as $user) { $users[] = $user; } $allEvaluations = $this->activityManager->getEvaluationsByUsersAndActivityParams($users, $activityParams); $evaluations = array(); foreach ($allEvaluations as $evaluation) { $user = $evaluation->getUser(); $evaluations[$user->getId()] = $evaluation; } $nbSuccess = 0; foreach ($users as $user) { if (!isset($evaluations[$user->getId()])) { $evaluations[$user->getId()] = $this->activityManager->createBlankEvaluation($user, $activityParams); } $status = $evaluations[$user->getId()]->getStatus(); if ($status === AbstractEvaluation::STATUS_COMPLETED || $status === AbstractEvaluation::STATUS_PASSED) { $nbSuccess++; } } $progress = count($users) > 0 ? round($nbSuccess / count($users), 2) * 100 : 0; $ruleScore = null; if ($activityParams->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC && count($activityParams->getRules()) > 0) { $rule = $activityParams->getRules()->first(); $score = $rule->getResult(); $scoreMax = $rule->getResultMax(); if (!is_null($score)) { $ruleScore = $score; if (!is_null($scoreMax)) { $ruleScore .= ' / ' . $scoreMax; } } } return array('analyticsTab' => 'activities', 'activity' => $activity, 'activityParams' => $activityParams, 'workspace' => $workspace, 'users' => $usersPager, 'page' => $page, 'evaluations' => $evaluations, 'ruleScore' => $ruleScore, 'progress' => $progress); }
public function addPermissionsToResource(Activity $activity, array $roles) { $primary = $activity->getPrimaryResource(); $secondaries = []; $nodes = []; if ($primary) { $nodes[] = $primary; } foreach ($activity->getParameters()->getSecondaryResources() as $res) { $secondaries[] = $res; } $nodes = array_merge($nodes, $secondaries); $this->rightsManager->initializePermissions($nodes, $roles); }
/** * Get evaluation data for an activity. * * @param Activity $activity * * @return \Symfony\Component\HttpFoundation\JsonResponse * * @Route( * "/activity/evaluation/{id}", * name = "innova_path_criteria_evaluation", * options = { "expose" = true } * ) * @Method("GET") */ public function getActivityEvaluation(Activity $activity) { $data = ['status' => 'NA', 'attempts' => 0]; // retrieve evaluation data for this activity $evaluationRepo = $this->om->getRepository('ClarolineCoreBundle:Activity\\Evaluation'); $evaluation = $evaluationRepo->findOneBy(['activityParameters' => $activity->getParameters()]); //return relevant data if (!empty($evaluation)) { $data = ['status' => $evaluation->getStatus(), 'attempts' => $evaluation->getAttemptsCount()]; } return new JsonResponse($data); }
public function jsonSerialize() { // Initialize data array $jsonArray = array('id' => $this->id, 'resourceId' => $this->id, 'activityId' => null, 'lvl' => $this->lvl, 'name' => $this->getName(), 'description' => $this->getDescription(), 'primaryResource' => array(), 'resources' => array(), 'excludedResources' => array(), 'children' => array(), 'withTutor' => false, 'who' => null, 'where' => null, 'duration' => null); // Get activity properties if (!empty($this->activity)) { // Get activity ID $jsonArray['activityId'] = $this->activity->getId(); // The ID of the linked Activity // Get primary resource $primaryResource = $this->activity->getPrimaryResource(); if (!empty($primaryResource)) { $jsonArray['primaryResource'] = array(array('id' => $primaryResource->getId(), 'resourceId' => $primaryResource->getId(), 'name' => $primaryResource->getName(), 'type' => $primaryResource->getResourceType()->getName(), 'mimeType' => $primaryResource->getMimeType())); } } // Get parameters if (!empty($this->parameters)) { // Get parameters of the step $parameters = $this->parameters; } else { if (!empty($this->activity)) { // Get parameters of the Activity $parameters = $this->activity->getParameters(); } } if (!empty($parameters)) { // Secondary resources $secondaryResources = $parameters->getSecondaryResources(); if (!empty($secondaryResources)) { // Get propagated resources of the current step $propagatedResources = $this->getPropagatedResources($this->lvl); foreach ($secondaryResources as $secondaryResource) { $jsonArray['resources'][] = array('id' => $secondaryResource->getId(), 'resourceId' => $secondaryResource->getId(), 'name' => $secondaryResource->getName(), 'type' => $secondaryResource->getResourceType()->getName(), 'mimeType' => $secondaryResource->getMimeType(), 'propagateToChildren' => in_array($secondaryResource->getId(), $propagatedResources)); } } // Global Parameters $jsonArray['withTutor'] = $parameters->isWithTutor(); $jsonArray['who'] = $parameters->getWho(); $jsonArray['where'] = $parameters->getWhere(); $jsonArray['duration'] = $parameters->getMaxDuration(); // Duration in seconds } // Excluded resources $parentResources = $this->getParentsSecondaryResources(); foreach ($parentResources as $resource) { $exist = false; foreach ($this->inheritedResources as $inherited) { if ($inherited->getResource()->getId() == $resource->getId()) { $exist = true; break; } } // Parent resource not found in step if (!$exist) { $jsonArray['excludedResources'][] = $resource->getId(); } } // Get step children if (!empty($this->children)) { $jsonArray['children'] = array_values($this->children->toArray()); } return $jsonArray; }
public function jsonSerialize() { $accessibleFrom = $this->getAccessibleFrom(); $accessibleUntil = $this->getAccessibleUntil(); // Initialize data array $jsonArray = ['id' => $this->id, 'resourceId' => $this->id, 'activityId' => null, 'activityHeight' => $this->activityHeight, 'lvl' => $this->lvl, 'name' => $this->getName(), 'description' => $this->getDescription(), 'primaryResource' => [], 'resources' => [], 'excludedResources' => [], 'children' => [], 'withTutor' => false, 'who' => null, 'where' => null, 'duration' => null, 'accessibleFrom' => $accessibleFrom instanceof \DateTime ? $accessibleFrom->format('Y-m-d H:i:s') : null, 'accessibleUntil' => $accessibleUntil instanceof \DateTime ? $accessibleUntil->format('Y-m-d H:i:s') : null, 'evaluationType' => null]; // Get activity properties if (!empty($this->activity)) { // Get activity ID $jsonArray['activityId'] = $this->activity->getId(); // The ID of the linked Activity // Get primary resource $primaryResource = $this->activity->getPrimaryResource(); if (!empty($primaryResource)) { $jsonArray['primaryResource'] = [['id' => $primaryResource->getId(), 'resourceId' => $primaryResource->getId(), 'name' => $primaryResource->getName(), 'type' => $primaryResource->getResourceType()->getName(), 'mimeType' => $primaryResource->getMimeType()]]; } } // Get parameters if (!empty($this->parameters)) { // Get parameters of the step $parameters = $this->parameters; } elseif (!empty($this->activity)) { // Get parameters of the Activity $parameters = $this->activity->getParameters(); } if (!empty($parameters)) { // Secondary resources $secondaryResources = $parameters->getSecondaryResources(); if (!empty($secondaryResources)) { // Get propagated resources of the current step $propagatedResources = $this->getPropagatedResources($this->lvl); foreach ($secondaryResources as $secondaryResource) { $jsonArray['resources'][] = ['id' => $secondaryResource->getId(), 'resourceId' => $secondaryResource->getId(), 'name' => $secondaryResource->getName(), 'type' => $secondaryResource->getResourceType()->getName(), 'mimeType' => $secondaryResource->getMimeType(), 'propagateToChildren' => in_array($secondaryResource->getId(), $propagatedResources)]; } } // Global Parameters $jsonArray['withTutor'] = $parameters->isWithTutor(); $jsonArray['who'] = $parameters->getWho(); $jsonArray['where'] = $parameters->getWhere(); $jsonArray['duration'] = $parameters->getMaxDuration(); // Duration in seconds $jsonArray['evaluationType'] = $parameters->getEvaluationType(); // manual/automatic } // Excluded resources $parentResources = $this->getParentsSecondaryResources(); /** @var \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource */ foreach ($parentResources as $resource) { $exist = false; /** @var \Innova\PathBundle\Entity\InheritedResource $inherited */ foreach ($this->inheritedResources as $inherited) { if ($inherited->getResource()->getId() === $resource->getId()) { $exist = true; break; } } // Parent resource not found in step if (!$exist) { $jsonArray['excludedResources'][] = $resource->getId(); } } // Get condition if (!empty($this->condition)) { // Get condition of the step $jsonArray['condition'] = $this->condition; } // Get step children if (!empty($this->children)) { // Reorder children // The property OrderBy only works when we grab data from the DB, // so if we have modified the Path after it, children may be not ordered $iterator = $this->children->getIterator(); $iterator->uasort(function ($a, $b) { /* * @var \Innova\PathBundle\Entity\Step $a * @var \Innova\PathBundle\Entity\Step $b */ return $a->getOrder() < $b->getOrder() ? -1 : 1; }); $this->children = new ArrayCollection(iterator_to_array($iterator)); $jsonArray['children'] = array_values($this->children->toArray()); } return $jsonArray; }