You are here

class LearningPathProgress in Opigno Learning path 3.x

Same name and namespace in other branches
  1. 8 src/Controller/LearningPathProgress.php \Drupal\opigno_learning_path\Controller\LearningPathProgress

Returns responses for ajax progress bar routes.

Hierarchy

Expanded class hierarchy of LearningPathProgress

File

src/Controller/LearningPathProgress.php, line 16

Namespace

Drupal\opigno_learning_path\Controller
View source
class LearningPathProgress implements ContainerInjectionInterface {

  /**
   * The progress bar generator service.
   *
   * @var \Drupal\opigno_learning_path\Progress
   */
  protected $progressService;

  /**
   * Constructs a new LearningPathProgress object.
   *
   * @param Drupal\opigno_learning_path\Progres $progress_service
   *   The progress bar service.
   */
  public function __construct(Progress $progress_service) {
    $this->progressService = $progress_service;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('opigno_learning_path.progress'));
  }

  /**
   * Returns a html of progress bar.
   *
   * @param object $group
   *   Group entity.
   * @param object $account
   *   User entity.
   * @param int $latest_cert_date
   *   Latest certification date.
   * @param string $class
   *   identifier for progress bar.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   The response object.
   */
  public function getHTML(Group $group, User $account, int $latest_cert_date, string $class) {
    $selector = '#progress-ajax-container-' . $group
      ->id() . '-' . $account
      ->id() . '-' . $latest_cert_date . '-' . $class;
    $content = $this->progressService
      ->getProgressBuild($group
      ->id(), $account
      ->id(), $latest_cert_date, $class);
    $response = new AjaxResponse();
    $response
      ->addCommand(new ReplaceCommand($selector, $content));
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LearningPathProgress::$progressService protected property The progress bar generator service.
LearningPathProgress::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
LearningPathProgress::getHTML public function Returns a html of progress bar.
LearningPathProgress::__construct public function Constructs a new LearningPathProgress object.