OpignoLearningPathProgress.php in Opigno Learning path 3.x
File
src/Plugin/views/field/OpignoLearningPathProgress.php
View source
<?php
namespace Drupal\opigno_learning_path\Plugin\views\field;
use Drupal\Core\Session\AccountInterface;
use Drupal\opigno_learning_path\Entity\LatestActivity;
use Drupal\opigno_learning_path\Progress;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OpignoLearningPathProgress extends FieldPluginBase {
protected $uid;
protected $progress;
public function __construct(AccountInterface $user, Progress $progress, ...$default) {
parent::__construct(...$default);
$this->uid = (int) $user
->id();
$this->progress = $progress;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('current_user'), $container
->get('opigno_learning_path.progress'), $configuration, $plugin_id, $plugin_definition);
}
public function query() {
}
public function render(ResultRow $values) {
$entity = $values->_entity;
$group = $entity instanceof LatestActivity ? $entity
->getTraining() : $entity;
return !is_null($group) ? $this->progress
->getProgressBuild($group
->id(), $this->uid, '', 'full') : '';
}
}