コード例 #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;
     }
 }
コード例 #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());
     }
 }
コード例 #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;
 }
コード例 #4
0
 /**
  * Copy an activity.
  */
 public function copyActivity(Activity $resource)
 {
     $activity = new Activity();
     $activity->setTitle($resource->getTitle());
     $activity->setDescription($resource->getDescription());
     $activity->setParameters($this->copyParameters($resource));
     if ($primaryResource = $resource->getPrimaryResource()) {
         $activity->setPrimaryResource($primaryResource);
     }
     return $activity;
 }