You are here

public function UserController::ajaxLoadTrainingDetails in Opigno statistics 8

Same name and namespace in other branches
  1. 3.x src/Controller/UserController.php \Drupal\opigno_statistics\Controller\UserController::ajaxLoadTrainingDetails()

Loads a user training details with the AJAX.

Parameters

\Drupal\user\UserInterface $user: User.

\Drupal\group\Entity\GroupInterface $group: Training.

Return value

\Drupal\Core\Ajax\AjaxResponse AJAX response.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 string reference to 'UserController::ajaxLoadTrainingDetails'
opigno_statistics.routing.yml in ./opigno_statistics.routing.yml
opigno_statistics.routing.yml

File

src/Controller/UserController.php, line 1215

Class

UserController
Class UserController.

Namespace

Drupal\opigno_statistics\Controller

Code

public function ajaxLoadTrainingDetails(UserInterface $user, GroupInterface $group) {
  $gid = $group
    ->id();
  $uid = $user
    ->id();
  $selector = ".trainings-list tr.training[data-training=\"{$gid}\"][data-user=\"{$uid}\"]";
  $content = [
    [
      '#type' => 'html_tag',
      '#tag' => 'tr',
      '#attributes' => [
        'data-training' => $gid,
        'data-user' => $uid,
        'class' => [
          'training-active',
        ],
      ],
      [
        '#type' => 'html_tag',
        '#tag' => 'td',
        '#attributes' => [
          'colspan' => 4,
        ],
        '#value' => $group
          ->label(),
      ],
      [
        '#type' => 'html_tag',
        '#tag' => 'td',
        'close' => [
          '#type' => 'html_tag',
          '#tag' => 'span',
          '#attributes' => [
            'data-training' => $gid,
            'data-user' => $uid,
            'class' => [
              'training-close',
            ],
          ],
        ],
      ],
    ],
    [
      '#type' => 'html_tag',
      '#tag' => 'tr',
      '#attributes' => [
        'data-training' => $gid,
        'data-user' => $uid,
        'class' => [
          'training-details',
        ],
      ],
      [
        '#type' => 'html_tag',
        '#tag' => 'td',
        '#attributes' => [
          'colspan' => 5,
        ],
        'details' => $this
          ->buildTrainingDetails($user, $group),
      ],
    ],
  ];
  $content['#attached']['library'][] = 'opigno_statistics/user';
  $response = new AjaxResponse();
  $response
    ->addCommand(new AfterCommand($selector, $content));
  return $response;
}