You are here

function opigno_learning_path_get_modules_ids_by_group in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 opigno_learning_path.module \opigno_learning_path_get_modules_ids_by_group()

Implements opigno_learning_path_get_modules_ids_by_group().

Get modules ids by group.

Return array with modules ids.

File

./opigno_learning_path.module, line 3800
Contains opigno_learning_path.module.

Code

function opigno_learning_path_get_modules_ids_by_group(Group $group) {

  // Get the courses and modules within those.
  $modules = [];
  $group_content = $group
    ->getContent('subgroup:opigno_course');
  foreach ($group_content as $content) {

    /* @var $content \Drupal\group\Entity\GroupContent */

    /* @var $content_entity \Drupal\group\Entity\Group */
    $course = $content
      ->getEntity();
    $course_contents = $course
      ->getContent('opigno_module_group');
    foreach ($course_contents as $course_content) {

      /* @var $module_entity \Drupal\opigno_module\Entity\OpignoModule */
      $module_entity = $course_content
        ->getEntity();
      $modules[] = $module_entity
        ->id();
    }
  }

  // Get the direct modules.
  $group_content = $group
    ->getContent('opigno_module_group');
  foreach ($group_content as $content) {

    /* @var $content \Drupal\group\Entity\GroupContent */

    /* @var $content_entity \Drupal\opigno_module\Entity\OpignoModule */
    $content_entity = $content
      ->getEntity();
    $modules[] = $content_entity
      ->id();
  }
  return $modules;
}