protected function LearningPathAchievementController::build_page in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Controller/LearningPathAchievementController.php \Drupal\opigno_learning_path\Controller\LearningPathAchievementController::build_page()
 
Returns training page array.
Parameters
int $page: Page id.
Return value
array Training page array.
2 calls to LearningPathAchievementController::build_page()
- LearningPathAchievementController::index in src/
Controller/ LearningPathAchievementController.php  - Returns index array.
 - LearningPathAchievementController::page_ajax in src/
Controller/ LearningPathAchievementController.php  - Loads next achievements page with a AJAX.
 
File
- src/
Controller/ LearningPathAchievementController.php, line 1051  
Class
- LearningPathAchievementController
 - Class LearningPathAchievementController.
 
Namespace
Drupal\opigno_learning_path\ControllerCode
protected function build_page($page = 0) {
  $per_page = 5;
  $user = $account = $this
    ->currentUser();
  $uid = $user
    ->id();
  $query = $this->database
    ->select('group_content_field_data', 'gc');
  $query
    ->innerJoin('groups_field_data', 'g', 'g.id = gc.gid');
  // Opigno Module group content.
  $query
    ->leftJoin('group_content_field_data', 'gc2', 'gc2.gid = gc.gid AND gc2.type = \'group_content_type_162f6c7e7c4fa\'');
  $query
    ->leftJoin('opigno_group_content', 'ogc', 'ogc.entity_id = gc2.entity_id AND ogc.is_mandatory = 1');
  $query
    ->leftJoin('user_module_status', 'ums', 'ums.user_id = gc.uid AND ums.module = gc2.entity_id');
  $query
    ->addExpression('max(ums.started)', 'started');
  $query
    ->addExpression('max(ums.finished)', 'finished');
  $gids = $query
    ->fields('gc', [
    'gid',
  ])
    ->condition('gc.type', 'learning_path-group_membership')
    ->condition('gc.entity_id', $uid)
    ->groupBy('gc.gid')
    ->orderBy('finished', 'DESC')
    ->orderBy('started', 'DESC')
    ->orderBy('gc.gid', 'DESC')
    ->range($page * $per_page, $per_page)
    ->execute()
    ->fetchCol();
  $groups = Group::loadMultiple($gids);
  return array_map(function ($group) use ($account) {
    return $this
      ->build_training($group, $account);
  }, $groups);
}