class CourseReportController in Course 3.x
Same name and namespace in other branches
- 8.3 src/Controller/CourseReportController.php \Drupal\course\Controller\CourseReportController
- 8.2 src/Controller/CourseReportController.php \Drupal\course\Controller\CourseReportController
Hierarchy
- class \Drupal\Core\Entity\Controller\EntityController implements ContainerInjectionInterface uses StringTranslationTrait
- class \Drupal\course\Controller\CourseReportController
Expanded class hierarchy of CourseReportController
File
- src/
Controller/ CourseReportController.php, line 12
Namespace
Drupal\course\ControllerView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseReportController:: |
function | Return a link to a report as HTML. | ||
CourseReportController:: |
function | Page handler for course object reports. | ||
CourseReportController:: |
function | Page handler for course object reports. | ||
EntityController:: |
protected | property | The entity repository. | |
EntityController:: |
protected | property | The entity type bundle info. | |
EntityController:: |
protected | property | The entity type manager. | |
EntityController:: |
protected | property | The renderer. | |
EntityController:: |
public | function | Provides a generic add title callback for entities with bundles. | |
EntityController:: |
public | function | Displays add links for the available bundles. | |
EntityController:: |
public | function | Provides a generic add title callback for an entity type. | |
EntityController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
EntityController:: |
public | function | Provides a generic delete title callback. | |
EntityController:: |
protected | function | Determines the entity. | |
EntityController:: |
public | function | Provides a generic edit title callback. | |
EntityController:: |
protected | function | Expands the bundle information with descriptions, if known. | |
EntityController:: |
protected | function | Returns a redirect response object for the specified route. | |
EntityController:: |
public | function | Provides a generic title callback for a single entity. | |
EntityController:: |
public | function | Constructs a new EntityController. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |