コード例 #1
0
ファイル: Step.php プロジェクト: stmolivier/PathBundle
 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;
 }
コード例 #2
0
 /**
  * @param Activity $activity
  * @return bool
  */
 public function hasPassedActivity(Activity $activity)
 {
     return in_array($activity->getId(), $this->passedActivityIds);
 }
コード例 #3
0
ファイル: Step.php プロジェクト: claroline/distribution
 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;
 }