Example #1
0
 public function import(array &$array, $name, $created)
 {
     $ds = DIRECTORY_SEPARATOR;
     foreach ($array['data'] as $item) {
         $description = file_get_contents($this->getRootPath() . $ds . $item['activity']['description']);
         $activity = new Activity();
         $activity->setTitle($item['activity']['title']);
         $primaryResource = !empty($item['activity']['primary_resource']) && isset($created[$item['activity']['primary_resource']]) && $created[$item['activity']['primary_resource']] ? $created[$item['activity']['primary_resource']]->getResourceNode() : null;
         $activity->setPrimaryResource($primaryResource);
         $activity->setDescription($description);
         $parameters = new ActivityParameters();
         $parameters->setMaxDuration($item['activity']['max_duration']);
         $parameters->setWho($item['activity']['who']);
         $parameters->setWhere($item['activity']['where']);
         $parameters->setEvaluationType($item['activity']['evaluation_type']);
         foreach ($item['activity']['secondary_resources'] as $secondaryResource) {
             //in a perfect world, this shouldn't happend
             if ($created[$secondaryResource['uid']]) {
                 $parameters->addSecondaryResource($created[$secondaryResource['uid']]->getResourceNode());
             }
         }
         $activity->setParameters($parameters);
         $this->om->persist($activity);
         $this->om->persist($parameters);
         return $activity;
     }
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $activityManager = $this->container->get('claroline.manager.activity_manager');
     $resourceManager = $this->container->get('claroline.manager.resource_manager');
     $activity = new Activity();
     $activity->setName($this->name);
     $activity->setTitle($this->name);
     $activity->setDescription($this->description);
     if ($this->primaryResource !== null) {
         $activity->setPrimaryResource($this->getReference($this->primaryResource)->getResourceNode());
     }
     $activityParameters = new ActivityParameters();
     $activityParameters->setActivity($activity);
     $activity->setParameters($activityParameters);
     $parent = $this->getReference('directory/' . $this->parent);
     $workspace = $parent->getWorkspace();
     $resourceType = $manager->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('activity');
     $resourceManager->create($activity, $resourceType, $this->getReference('user/' . $this->creator), $workspace, $parent);
     foreach ($this->secondaryResources as $secondaryResource) {
         $activityManager->addResource($activity, $this->getReference($secondaryResource)->getResourceNode());
     }
 }
Example #3
0
 /**
  * @param  \Innova\PathBundle\Entity\Step               $step
  * @param  \stdClass                                    $stepStructure
  * @return \Innova\PathBundle\Manager\PublishingManager
  * @throws \LogicException
  */
 public function updateActivity(Step $step, \stdClass $stepStructure)
 {
     $newActivity = false;
     $activity = $step->getActivity();
     if (empty($activity)) {
         if (!empty($stepStructure->activityId)) {
             // Load activity from DB
             $activity = $this->om->getRepository('ClarolineCoreBundle:Resource\\Activity')->findOneById($stepStructure->activityId);
             if (empty($activity)) {
                 // Can't find Activity => create a new one
                 $newActivity = true;
                 $activity = new Activity();
             }
         } else {
             // Create new activity
             $newActivity = true;
             $activity = new Activity();
         }
     }
     // Update activity properties
     if (!empty($stepStructure->name)) {
         $name = $stepStructure->name;
     } else {
         // Create a default name
         $name = $step->getPath()->getName() . ' - ' . Step::DEFAULT_NAME . ' ' . $step->getOrder();
     }
     $activity->setName($name);
     $activity->setTitle($name);
     $description = !empty($stepStructure->description) ? $stepStructure->description : ' ';
     $activity->setDescription($description);
     // Link resource if needed
     if (!empty($stepStructure->primaryResource) && !empty($stepStructure->primaryResource[0]) && !empty($stepStructure->primaryResource[0]->resourceId)) {
         $resource = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($stepStructure->primaryResource[0]->resourceId);
         if (!empty($resource)) {
             $activity->setPrimaryResource($resource);
         } else {
             $warning = $this->translator->trans('warning_primary_resource_deleted', array('resourceId' => $stepStructure->primaryResource[0]->resourceId, 'resourceName' => $stepStructure->primaryResource[0]->name), "innova_tools");
             $this->session->getFlashBag()->add('warning', $warning);
             $stepStructure->primaryResource = array();
         }
     } elseif ($activity->getPrimaryResource()) {
         // Step had a resource which has been deleted
         $activity->setPrimaryResource(null);
     }
     // Generate Claroline resource node and rights
     if ($newActivity) {
         // It's a new Activity, so use Step parameters
         $activity->setParameters($step->getParameters());
         $activityType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('activity');
         $creator = $step->getPath()->getCreator();
         $workspace = $step->getWorkspace();
         // Store Activity in same directory than parent Path
         $parent = $step->getPath()->getResourceNode()->getParent();
         if (empty($parent)) {
             $parent = $this->resourceManager->getWorkspaceRoot($workspace);
         }
         $activity = $this->resourceManager->create($activity, $activityType, $creator, $workspace, $parent);
     } else {
         // Activity already exists => update ResourceNode
         $activity->getResourceNode()->setName($activity->getTitle());
     }
     // Update JSON structure
     $stepStructure->activityId = $activity->getId();
     // Store Activity in Step
     $step->setActivity($activity);
     return $this;
 }
 /**
  * @param Activity $activity
  * @return bool
  */
 public function hasPassedActivity(Activity $activity)
 {
     return in_array($activity->getId(), $this->passedActivityIds);
 }
 /**
  * @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);
 }
Example #7
0
 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;
 }
 protected function persistActivity($name)
 {
     if (!isset($this->defaults['user'])) {
         $this->defaults['user'] = $this->persistUser('default_user');
     }
     if (!isset($this->defaults['workspace'])) {
         $workspace = new Workspace();
         $workspace->setName('ws-jdoe');
         $workspace->setCreator($this->defaults['user']);
         $workspace->setCode('jdoe-123');
         $workspace->setGuid('123');
         $this->om->persist($workspace);
         $this->defaults['workspace'] = $workspace;
     }
     if (!isset($this->defaults['activity_type'])) {
         $type = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('activity');
         $this->defaults['activity_type'] = $type;
     }
     $node = new ResourceNode();
     $node->setName($name);
     $node->setCreator($this->defaults['user']);
     $node->setResourceType($this->defaults['activity_type']);
     $node->setWorkspace($this->defaults['workspace']);
     $node->setGuid($name);
     $node->setClass('foo');
     $activity = new Activity();
     $activity->setName($name);
     $activity->setDescription('desc');
     $activity->setResourceNode($node);
     $this->om->persist($node);
     $this->om->persist($activity);
     return $activity;
 }
 private function createActivity($name)
 {
     $user = new User();
     $user->setFirstName('John');
     $user->setLastName('Doe');
     $user->setUsername('jdoe');
     $user->setMail('*****@*****.**');
     $user->setPassword('123');
     $workspace = new Workspace();
     $workspace->setName('w1');
     $workspace->setCode('abc');
     $workspace->setGuid('abc123');
     $workspace->setCreator($user);
     $type = new ResourceType();
     $type->setName('activity');
     $node = new ResourceNode();
     $node->setName($name);
     $node->setClass('FooClass');
     $node->setCreator($user);
     $node->setResourceType($type);
     $node->setWorkspace($workspace);
     $activity = new Activity();
     $activity->setResourceNode($node);
     $activity->setDescription('activity...');
     $this->om->persist($user);
     $this->om->persist($workspace);
     $this->om->persist($type);
     $this->om->persist($node);
     $this->om->persist($activity);
     return $activity;
 }
 /**
  * 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);
 }
Example #11
0
 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;
 }