Пример #1
1
 public function updateSecondaryResources(ActivityParameters $parameters, \stdClass $stepStructure)
 {
     // Store current resources to clean removed
     $existingResources = $parameters->getSecondaryResources();
     $existingResources = $existingResources->toArray();
     // Publish new resources
     $publishedResources = array();
     if (!empty($stepStructure->resources)) {
         $i = 0;
         foreach ($stepStructure->resources as $resource) {
             $resourceNode = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($resource->resourceId);
             if (!empty($resourceNode)) {
                 $parameters->addSecondaryResource($resourceNode);
                 $publishedResources[] = $resourceNode;
             } else {
                 $warning = $this->translator->trans('warning_compl_resource_deleted', array('resourceId' => $resource->resourceId, 'resourceName' => $resource->name), "innova_tools");
                 $this->session->getFlashBag()->add('warning', $warning);
                 unset($stepStructure->resources[$i]);
             }
             $i++;
         }
     }
     // Clean removed resources
     foreach ($existingResources as $existingResource) {
         if (!in_array($existingResource, $publishedResources)) {
             $parameters->removeSecondaryResource($existingResource);
         }
     }
     return $this;
 }
Пример #2
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;
     }
 }
Пример #3
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());
     }
 }
Пример #4
0
 /**
  * @Observe("create_activity")
  *
  * @param CreateResourceEvent $event
  */
 public function onCreate(CreateResourceEvent $event)
 {
     $form = $this->formFactory->create(new ActivityType(), new Activity());
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $published = $form->get('published')->getData();
         $event->setPublished($published);
         $activity = $form->getData();
         $activity->setName($activity->getTitle());
         $activityParameters = new ActivityParameters();
         $activityParameters->setActivity($activity);
         $activity->setParameters($activityParameters);
         $event->setResources(array($activity));
         $event->stopPropagation();
         return;
     }
     $content = $this->templating->render('ClarolineCoreBundle:Resource:createForm.html.twig', array('form' => $form->createView(), 'resourceType' => 'activity'));
     $event->setErrorFormContent($content);
     $event->stopPropagation();
 }
 /**
  * @EXT\Route(
  *     "/{workspaceId}/activity/parameters/{activityParametersId}/user/{userId}/past/evaluations/show/{displayType}",
  *     name="claro_workspace_activities_past_evaluations_show",
  *     options = {"expose": true}
  * )
  * @EXT\ParamConverter("currentUser", options={"authenticatedUser" = true})
  * @EXT\ParamConverter(
  *      "user",
  *      class="ClarolineCoreBundle:User",
  *      options={"id" = "userId", "strictId" = true}
  * )
  * @EXT\ParamConverter(
  *      "workspace",
  *      class="ClarolineCoreBundle:Workspace\Workspace",
  *      options={"id" = "workspaceId", "strictId" = true}
  * )
  * @EXT\ParamConverter(
  *      "activityParameters",
  *      class="ClarolineCoreBundle:Activity\ActivityParameters",
  *      options={"id" = "activityParametersId", "strictId" = true}
  * )
  * @EXT\Template("ClarolineCoreBundle:Tool/workspace/analytics:workspaceActivitiesPastEvaluations.html.twig")
  *
  * Displays past evaluations of one activity for one user
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function workspaceActivitiesPastEvaluationsShowAction(User $currentUser, User $user, Workspace $workspace, ActivityParameters $activityParameters, $displayType)
 {
     if (!$this->authorization->isGranted('analytics', $workspace)) {
         throw new AccessDeniedException();
     }
     $roleNames = $currentUser->getRoles();
     $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);
     if (!$isWorkspaceManager && $currentUser->getId() !== $user->getId()) {
         throw new AccessDeniedException();
     }
     $activity = $activityParameters->getActivity();
     $ruleScore = null;
     $isResultVisible = false;
     if ($activityParameters->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC && count($activityParameters->getRules()) > 0) {
         $rule = $activityParameters->getRules()->first();
         $score = $rule->getResult();
         $scoreMax = $rule->getResultMax();
         if (!is_null($score)) {
             $ruleScore = $score;
             if (!is_null($scoreMax)) {
                 $ruleScore .= ' / ' . $scoreMax;
             }
             $ruleResultVisible = $rule->getIsResultVisible();
             $isResultVisible = !empty($ruleResultVisible);
         }
     }
     $pastEvals = $this->activityManager->getPastEvaluationsByUserAndActivityParams($user, $activityParameters);
     return array('user' => $user, 'activity' => $activity, 'pastEvals' => $pastEvals, 'displayType' => $displayType, 'isWorkspaceManager' => $isWorkspaceManager, 'ruleScore' => $ruleScore, 'isResultVisible' => $isResultVisible);
 }
Пример #6
0
 /**
  * Creates an empty activity evaluation for a user, so that an evaluation
  * is available for display and edition even when the user hasn't actually
  * performed the activity.
  *
  * @param User               $user
  * @param ActivityParameters $activityParams
  *
  * @return Evaluation
  */
 public function createBlankEvaluation(User $user, ActivityParameters $activityParams)
 {
     $evaluationType = $activityParams->getEvaluationType();
     $status = null;
     $nbAttempts = null;
     if ($evaluationType === AbstractEvaluation::TYPE_AUTOMATIC) {
         $status = AbstractEvaluation::STATUS_NOT_ATTEMPTED;
         $nbAttempts = 0;
     }
     $evaluation = new Evaluation();
     $evaluation->setUser($user);
     $evaluation->setActivityParameters($activityParams);
     $evaluation->setType($evaluationType);
     $evaluation->setStatus($status);
     $evaluation->setAttemptsCount($nbAttempts);
     $this->om->persist($evaluation);
     $this->om->flush();
     return $evaluation;
 }