/[drupal]/contributions/modules/flashcard/flashcard.module
ViewVC logotype

Contents of /contributions/modules/flashcard/flashcard.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Wed Jan 10 14:53:15 2007 UTC (2 years, 10 months ago) by suuch
Branch: MAIN
CVS Tags: DRUPAL-4-7--2-2, HEAD
Changes since 1.4: +2 -35 lines
File MIME type: text/x-php
Removed obsolete hook_settings.
1 <?
2 require("includes/functions.inc.php");
3 /**
4 * Implementation of hook_help().
5 *
6 * Throughout Drupal, hook_help() is used to display help text at the top of
7 * pages. Some other parts of Drupal pages get explanatory text from these hooks
8 * as well. We use it here to provide a description of the module on the
9 * module administration page.
10 */
11 function flashcard_help($section="admin/help#flashcard") {
12 switch ($section) {
13 case 'admin/modules#description':
14 // This description is shown in the listing at admin/modules.
15 return t('The flashcard module is a flashcard viewer for vocabulary sets, Question and Answer sets and Fill in the Blanks sets. Requires that the respective modules are installed');
16 break;
17 }
18 }
19
20 /**
21 * Implementation of hook_perm().
22 *
23 * Since we are limiting the ability to create new nodes to certain users,
24 * we need to define what those permissions are here. We also define a permission
25 * to allow users to edit the nodes they created.
26 */
27 function flashcard_perm() {
28 return array('use flashcard viewer', 'administer flashcard viewer');
29 }
30
31 /**
32 * hook_settings() implementation
33 */
34 function flashcard_settings() {
35 return t('Enable typecheck for the relevant content types at %url', array('%url'=>l('admin/settings/content-types', 'admin/settings/content-types')));
36 }
37
38 /**
39 * hook_menu() implementation
40 */
41 function flashcard_menu() {
42 $items = array();
43 $access = (user_access('use flashcard viewer') || user_access('administer flashcard viewer'));
44 $type = MENU_LOCAL_TASK;
45
46 //show on only enabled nodes
47 if (arg(0) == 'node' && is_numeric(arg(1)))
48 {
49 $node = db_fetch_object(db_query("SELECT type, title FROM {node} WHERE nid=".arg(1)));
50 drupal_set_title(check_plain($node->title));
51 switch($node->type)
52 {
53 case "vocab":
54 case "qanda":
55 case "fitb":
56 {
57 if(variable_get('flashcard_'.$node->type, 0)==1) //flashcards allowed
58 {
59 $items[] = array(
60 'path' => 'node/'. arg(1) .'/flashcard/options',
61 'title' => t('flashcard options'),
62 'callback' => 'f_user_options',
63 'callback arguments'=>array(arg(1), $node->type),
64 'access' => $access,
65 'type' => MENU_CALL_BACK
66 );
67
68 $items[] = array(
69 'path' => 'node/'. arg(1) .'/flashcard',
70 'title' => t('view as flashcards'),
71 'callback' => 'f_display_cards',
72 'callback arguments'=>$node->type,
73 'access' => $access,
74 'type' => $type
75 );
76 }
77
78 }
79 break;
80 default:
81 break;
82 }
83 }
84 return $items;
85 }
86
87 /*
88 * hook_load
89 */
90
91
92 /*
93 * Display flashcard
94 */
95 function f_display_cards($nodetype){
96 return theme('f_display_cards', $nodetype);
97 }
98
99 function theme_f_display_cards($nodetype){
100 theme_add_style(drupal_get_path('module', 'flashcard').'/includes/flashcard.css');
101 if(!$side || $side == 'front') $flip_side = 'back';
102 else $flip_side = 'front';
103
104 // If view has not been set, e.g., first view, set to first card in array.
105 if(!$_GET['view']) $view = 0;
106 else $view = $_GET['view'];
107
108 $display_set_id = arg(1);
109 $display_order = f_display_order($display_set_id, $view, $nodetype);
110 $display_order_size = sizeof($display_order);
111 if(!$display_order_size){ //empty set
112 return l(t('No pairs to display. Add a new pair and come back'), $nodetype.'/'.arg(1).'/add');
113 }
114 $card_content = f_display_card($display_set_id, $display_order[($view)], $nodetype);
115
116 $sws = ($_GET['ss']=='1') ? ' '.t('<i>Sides switched</i>'): '';
117 $output.= f_display_quick_actions($view, $display_order_size, $flip_side);
118
119 $card_id_bot.= '<div class="card_bot">[Card ID: '.$display_set_id.'-'.$display_order[$view].']</div>';
120 // RETRIEVE FRONT OF FLASHCARD
121 if(!$_GET['side'] || $_GET['side'] == 'front')
122 {
123 $flip_side = 'back';
124 //is side switched?,
125 if($_GET['ss'] == '1')
126 $card_view = nl2br(stripslashes($card_content[$flip_side]));
127 else //or not?
128 $card_view = nl2br(stripslashes($card_content[(f_swap($flip_side))]));
129 $card_id_top.= '<div class="card_top">'.t('Front - Card %view of %sizes',array('%view'=>($view+1), '%sizes'=>$display_order_size.$sws)).' </div>';
130 }
131 else
132 // RETRIEVE BACK OF FLASHCARD
133 if($_GET['side'] == 'back'){
134 $flip_side = 'front';
135 //is side switched?,
136 if($_GET['ss'] == '1')
137 $card_view = nl2br(stripslashes($card_content[$flip_side]));
138 else //or not?
139 $card_view = nl2br(stripslashes($card_content[(f_swap($flip_side))]));
140
141 $card_exp = $card_content['imageurl'];
142 $card_id_top.= '<div class="card_top">'.t('Back - Card %view of %sizes',array('%view'=>($view+1), '%sizes'=>$display_order_size.$sws)).' </div>';
143 }
144 $card_view = '<div class="card_view">'.$card_view.'</div>';
145
146 // Displays the actions at the top of the page.
147 $output.= f_display_actions($view, $display_order_size, $flip_side);
148
149 // CARD OUTPUT DISPLAY
150 $output.= '<div class="card">';
151 $output.= $card_view.$card_id_bot.$card_id_top;
152 $output.= '</div>';
153 $output.= '<div class="card-exp">'.$card_exp.'</div>';
154
155 // Displays actions at the bottom of the page.
156 $output.= f_display_actions($_GET['view'], $display_order_size, $flip_side);
157 return $output;
158 }
159 function f_display_order($display_set_id, $view, $nodetype, $shuffle="no"){
160
161 $table = strtolower($nodetype)."_data";
162 if((($view == 'all') || ($view)) && ($_SESSION['f_display_set_id'] != $display_set_id))
163 {
164 // Initialize display_order array.
165 $display_order = array();
166 $result = db_query(" SELECT id, front FROM {".$table."}
167 WHERE nid = %d
168 ORDER BY front ASC", $display_set_id);
169 for($i=0; $i<db_num_rows($result); $i++) {
170 $row = db_fetch_object($result);
171 $display_order[$i] = $row->id;
172 }
173
174 //is auto-shuffle on?
175 if(variable_get("flashcard_shuffle_".$nodetype, 0))
176 {
177 $display_order = f_pc_array_shuffle($display_order);
178 }
179
180 //Now set the sessions
181 session_register("f_display_order");
182 $_SESSION['f_display_order'] = $display_order;
183 $_SESSION['f_display_set_id'] = $display_set_id;
184 }
185 else
186 {
187 $display_order = $_SESSION['f_display_order'];
188 }
189 return ($display_order);
190 }
191
192 function f_user_options($display_set_id, $nodetype)
193 {
194 if(sizeof($_POST))
195 {
196 if(sizeof($_POST['toView_id']))
197 {
198
199 $display_order = array();
200 $display_order = $_POST['toView_id'];
201
202 if($_POST['shuffle'] == 'yes')
203 {
204 $display_order = f_pc_array_shuffle($display_order);
205 }
206
207 session_register("f_display_order");
208 session_register("f_display_set_id");
209 $_SESSION['f_display_order'] = $display_order;
210 $_SESSION['f_display_set_id'] = $display_set_id;
211
212 drupal_goto('node/'.$display_set_id.'/flashcard');
213
214 }
215 }
216 else
217 { //display options
218 $table = strtolower($nodetype)."_data";
219 $output = "<h2>".t('Select Cards to View. Default: All')."</h2>";
220 $result = db_query(" SELECT id, front
221 FROM {".$table."}
222 WHERE nid = %d
223 ORDER BY front ASC", $display_set_id);
224
225 $output.= "<table>";
226 for($i=0; $i<db_num_rows($result); $i++)
227 {
228 $row = db_fetch_object($result);
229 $output.= '<tr><td class="cardlisting" width="500">'.
230 ($row->front).
231 '</td><td class="cardlisting"><input type="checkbox" name="toView_id[]" value="'.
232 $row->id.
233 '" checked></td></tr>';
234 $display_order[$i] = $row->id;
235 }
236 $output.= "</table>";
237
238 $output.= '<input type="checkbox" name="shuffle" value="yes" checked> Shuffle?<BR><BR>
239 <input type="Submit" value="Generate '.ucfirst(arg(2)).' Set">';
240 //TODO: Convert to formAPI
241 $output = "<form action=".url($_GET['q'])." method='post'>".$output."</form>";
242 }
243 return $output;
244
245 }
246
247 /**
248 * Setup applicable nodes for viewing
249 */
250 function flashcard_form_alter($form_id, &$form) {
251 if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
252 $type = $form['type']['#value'];
253
254 switch($type){
255 case "vocab":
256 case "qanda":
257 case "fitb":
258 $form['flashcard'] = array(
259 '#type' => 'fieldset',
260 '#title' => t('Flashcard'),
261 '#collapsible' => TRUE,
262 '#weight' => 0
263 );
264 $form['flashcard']['flashcard_'. $type] = array(
265 '#type' => 'checkbox',
266 '#title' => t('Enable flashcards'),
267 '#return_value' => 1,
268 '#default_value' => variable_get('flashcard_'. $type, 0),
269 '#description' => t('Enable viewing as flashcards.')
270 );
271 break;
272 }
273 }
274 return $form;
275 }
276 ?>

  ViewVC Help
Powered by ViewVC 1.1.2