You are here

class CourseReportController in Course 3.x

Same name and namespace in other branches
  1. 8.3 src/Controller/CourseReportController.php \Drupal\course\Controller\CourseReportController
  2. 8.2 src/Controller/CourseReportController.php \Drupal\course\Controller\CourseReportController

Hierarchy

Expanded class hierarchy of CourseReportController

File

src/Controller/CourseReportController.php, line 12

Namespace

Drupal\course\Controller
View source
class CourseReportController extends EntityController {

  /**
   * Return a link to a report as HTML.
   *
   * @return Link
   */
  function course_object_single_report_link($courseObject, $report) {
    if (!empty($report['link'])) {
      if (!empty($report['modal'])) {
        $report['link']
          ->getURL()
          ->setOption('attributes', [
          'class' => 'use-ajax',
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 800,
          ]),
        ]);
      }
      return $report['link'];
    }
    else {
      return Link::createFromRoute($report['title'], 'course.reports.objects.report', [
        'course' => $courseObject
          ->getCourse()
          ->id(),
        'course_object' => $courseObject
          ->id(),
        'report' => $report['key'],
      ]);
    }
  }

  /**
   * Page handler for course object reports.
   */
  function objectReport(Course $course, CourseObject $course_object, $report) {
    $render = $this
      ->objectReports($course);
    $info = $course_object
      ->getReport($report);
    $header = '<h2>' . $course_object
      ->getTitle() . ': ' . $info['title'] . '</h2>';
    $content = $course_object
      ->getReport($report);
    if (!$content) {
      $content = [
        '#plain_text' => t('Sorry, no report is available for this type.'),
      ];
    }
    $render[0]['report']['header'] = [
      '#markup' => $header,
    ];
    $render[0]['report']['content'] = $content['content'];
    return $render;
  }

  /**
   * Page handler for course object reports.
   */
  function objectReports(Course $course) {

    // Report navigation.
    $nav = [
      '#id' => 'course-object-reports-content',
      '#attributes' => [
        'valign' => 'top',
      ],
    ];

    // Report content.
    $content = [];

    // Render Array
    $render = array();
    foreach ($course
      ->getObjects() as $courseObject) {
      $items = array();
      if (method_exists($courseObject, 'getReports')) {
        foreach ($courseObject
          ->getReports() as $key => $report) {
          $report['key'] = $key;
          $items[$key] = $this
            ->course_object_single_report_link($courseObject, $report)
            ->toString();
        }
        $nav[$courseObject
          ->id()] = array(
          '#theme' => 'item_list',
          '#title' => $courseObject
            ->getTitle(),
          '#items' => $items,
        );
      }
    }
    if (is_array($content)) {
      $content = Drupal::service('renderer')
        ->render($content);
    }
    $render[0]['nav'] = $nav;
    $render['#type'] = 'table';
    $render['#attributes'] = array(
      'id' => 'course-object-reports',
    );
    return $render;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CourseReportController::course_object_single_report_link function Return a link to a report as HTML.
CourseReportController::objectReport function Page handler for course object reports.
CourseReportController::objectReports function Page handler for course object reports.
EntityController::$entityRepository protected property The entity repository.
EntityController::$entityTypeBundleInfo protected property The entity type bundle info.
EntityController::$entityTypeManager protected property The entity type manager.
EntityController::$renderer protected property The renderer.
EntityController::addBundleTitle public function Provides a generic add title callback for entities with bundles.
EntityController::addPage public function Displays add links for the available bundles.
EntityController::addTitle public function Provides a generic add title callback for an entity type.
EntityController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
EntityController::deleteTitle public function Provides a generic delete title callback.
EntityController::doGetEntity protected function Determines the entity.
EntityController::editTitle public function Provides a generic edit title callback.
EntityController::loadBundleDescriptions protected function Expands the bundle information with descriptions, if known.
EntityController::redirect protected function Returns a redirect response object for the specified route.
EntityController::title public function Provides a generic title callback for a single entity.
EntityController::__construct public function Constructs a new EntityController.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.