-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacademic_syllabi.module
executable file
·112 lines (99 loc) · 3.86 KB
/
academic_syllabi.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* @file
* Module file for academic_syllabi_module.
*/
/**
* Implements hook_help().
*/
function academic_syllabi_help($path, $arg) {
switch ($path) {
case 'admin/help#academic_syllabi':
// Help text for the admin section, using the module name in the path.
return t("This module iterates through the syllabi directory, listing
the file names as links for each item found.");
}
}
/**
* Implements hook_permission().
*/
function academic_syllabi_permission() {
return array(
'access syllabi page' => array(
'title' => t('Access syllabi page'),
'description' => t('Allow users to access the syllabi page'),
),
);
}
/**
* Implements hook_menu().
*/
function academic_syllabi_menu() {
$items['academics/course-syllabi'] = array(
'title' => 'Course Syllabi',
'page callback' => 'academic_syllabi_list',
'access arguments' => array('access syllabi page'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Constructs a listing of links
*/
function academic_syllabi_construct_list($program) {
// Find all the *.PDF files in the given program directory, sort the array
// TODO: break this path out into a configuration setting
$syllabi = file_scan_directory("sites/default/files/syllabi/$program/", '/pdf$/');
asort($syllabi);
// Get some variables ready to construct the list
$title = "Spring 2016 " . t(ucfirst($program) . " Course Syllabi");
$type = 'ul';
$attributes = array(
'id' => "$program-syllabi-list",
'class' => 'fa-ul',
);
$items = array();
foreach (element_children($syllabi) as $syllabus) {
// Get the filename in a nicely readable format
$course_name = str_replace("_", " ", $syllabi[$syllabus]->filename);
$course_name = str_replace("-", " - ", $course_name);
$course_name = preg_replace('/\.pdf$/', '', $course_name);
// Store the link for use in the list
$uri = $syllabi[$syllabus]->uri;
$data = '<i class="fa-li fa fa-angle-right"></i>' .
l($course_name, $uri, array('attributes' => array('target' => '_blank')));
$items[] = array(
'data' => $data,
);
}
// Return the themed list, using all the data we've collected
$themed_list = theme_item_list(array('items' => $items, 'title' => $title, 'type' => $type, 'attributes' => $attributes));
return $themed_list;
}
/**
* Constructs page which lists all the PDF files in the specified directory
* as links to those PDF files.
*/
function academic_syllabi_list() {
// Get the lists for the necessary sub-directories
$traditional_list = academic_syllabi_construct_list('traditional');
$evening_list = academic_syllabi_construct_list('evening');
// Start the output with our notification box about the PDF-formatted files
$output = '<p class="typo-box box-information"><strong>Virtual Bookstore</strong>:
Textbook information for current classes is available at <strong>
<a target="_blank"
href="http://slcc.co/bookstore">slcc.co/bookstore</a></strong>.</p>
<p class="typo-icon icon-doc"><span class="icon"> </span>
The forms below are provided as PDF files. You can download and
print them by using <a class="vt-p" href="http://get.adobe.com/reader/"
rel="nofollow" target="_blank">Adobe Reader</a>, <a class="vt-p"
href="http://www.foxitsoftware.com/Secure_PDF_Reader/" rel="nofollow"
target="_blank">Foxit Reader</a>, or another PDF reader.</p>';
// Wrap these two lists in a container dive because that will allow us
// to place the lists side-by-side, which looks a lot nicer than a mile-
// long page with nothing but links.
$output .= '<div class="syllabi-list-container">' . $traditional_list . '</div>';
$output .= '<div class="syllabi-list-container">' . $evening_list . '</div>';
// Finally, return the output.
return $output;
}