You are here

public function LearningPathContent::toManagerArray in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/LearningPathContent.php \Drupal\opigno_learning_path\LearningPathContent::toManagerArray()

Returns LP content properties array to manager.

Parameters

\Drupal\opigno_learning_path\Entity\LPManagedContent|null $content: LP content.

Return value

array LP content properties array.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

File

src/LearningPathContent.php, line 52

Class

LearningPathContent
Class LearningPathContent.

Namespace

Drupal\opigno_learning_path

Code

public function toManagerArray(LPManagedContent $content = NULL) {
  if ($content === NULL) {
    $cid = '';
    $is_mandatory = FALSE;
    $success_score_min = 0;
    $parents_links = [];
  }
  else {
    $cid = $content
      ->id();
    $is_mandatory = $content
      ->isMandatory();
    $success_score_min = $content
      ->getSuccessScoreMin();
    $parents_links = $content
      ->getParentsLinks();
  }
  $this_array = [
    'cid' => $cid,
    'entityId' => $this
      ->getEntityId(),
    // TODO: Remove this. Avoid duplicate.
    'entityType' => $this
      ->getLearningPathContentTypeId(),
    // TODO: Remove this. Avoid duplicate.
    'entityBundle' => $this
      ->getLearningPathContentTypeId(),
    'contentType' => $this
      ->getLearningPathContentTypeId(),
    'title' => $this
      ->getTitle(),
    'imageUrl' => $this
      ->getImageUrl(),
    'imageAlt' => $this
      ->getImageAlt(),
    'isMandatory' => $is_mandatory,
    'successScoreMin' => $success_score_min,
  ];
  $parents = [];
  foreach ($parents_links as $link) {
    if (get_class($link) != 'Drupal\\opigno_learning_path\\Entity\\LPManagedLink') {
      continue;
    }
    $parents[] = [
      'cid' => $link
        ->getParentContentId(),
      'minScore' => $link
        ->getRequiredScore(),
    ];
  }
  $this_array['parents'] = $parents;
  return $this_array;
}