TslAssessment - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of TslAssessment.php

  1. <?php
  2.  
  3. namespace Drupal\tsl_assessment_ui;
  4.  
  5. use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
  6. use Drupal\Core\Entity\EntityTypeManagerInterface;
  7. use Drupal\Core\Link;
  8. use Drupal\Core\Session\AccountProxy;
  9. use Drupal\Core\Url;
  10. use Drupal\tsl_assessment\factory\AssessmentFactory;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12.  
  13. class TslAssessmentLinkGenerator implements ContainerInjectionInterface {
  14.  
  15.   protected $factory;
  16.   protected $entityTypeManager;
  17.   protected $currentUser;
  18.  
  19.   public function __construct(AssessmentFactory $assessment_factory, EntityTypeManagerInterface $entity_type_manager, AccountProxy $account_proxy) {
  20.     $this->factory = $assessment_factory;
  21.     $this->entityTypeManager = $entity_type_manager;
  22.     $this->currentUser = $account_proxy;
  23.   }
  24.  
  25.   public static function create(ContainerInterface $container) {
  26.     return new static(
  27.       $container->get('tsl_assessment.assessment_factory'),
  28.       $container->get('entity_type.manager'),
  29.       $container->get('current_user')
  30.     );
  31.   }
  32.  
  33.   /**
  34.    * Generate link to Assessment submission page by Assessment id.
  35.    *
  36.    * @param $assessment_id
  37.    *
  38.    * @return \Drupal\Core\GeneratedLink|string|null
  39.    * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
  40.    * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
  41.    */
  42.   public function tsl_assessment_ui_get_submit_link($assessment_id) {
  43.     $route_name = 'view.assessment_start_submission_page.page_start_assessment';
  44.     $is_access = Url::fromRoute($route_name, ['tsl_schd_assessment' => $assessment_id])->access();
  45.     $assessment = $this->entityTypeManager->getStorage('tsl_schd_assessment')->load($assessment_id);
  46.     $subject = $this->entityTypeManager->getStorage('user')->load($this->currentUser->id());
  47.     $status = $this->factory->getAssessmentManager($assessment)->getStatus($subject);
  48.     $user_access = $this->factory->getUserAccess();
  49.  
  50.     if (!$is_access || !$user_access->isAdmin() && $user_access->isOrgSubject() && $status == TSL_ASSESSMENT_STATUS_REPORT_CREATED) {
  51.       return $assessment->label();
  52.     }
  53.  
  54.     return Link::createFromRoute(
  55.       $assessment->label(),
  56.       $route_name,
  57.       ['tsl_schd_assessment' => $assessment_id]
  58.     )->toString();
  59.   }
  60. }
  61.  
File Description
  • TslAssessment
  • PHP Code
  • 28 Aug-2019
  • 2.23 Kb
You can Share it: