2 /********************************************************************/
4 /********************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Cindy Qi Li, & Harris Wong */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /********************************************************************/
13 // $Id: A4a.class.php 8077 2008-10-23 18:32:31Z hwong $
17 * Accessforall General class.
18 * Based on the specification at:
19 * http://www.imsglobal.org/accessibility/index.html
26 var $cid = 0; //content id
27 var $resource_types = array(); //resource types hash mapping
28 var $relative_path = ''; //relative path to the file
32 $this->cid = intval($cid);
36 // Return resources type hash mapping.
37 function getResourcesType($type_id=0){
40 $type_id = intval($type_id);
42 //if this is the first time calling this function, grab the list from db
43 if (empty($resource_types)){
44 $sql = 'SELECT * FROM '.TABLE_PREFIX.'resource_types';
45 $result = mysql_query($sql, $db);
46 while ($row = mysql_fetch_assoc($result)){
47 $this->resource_types[$row['type_id']] = $row['type'];
51 if (!empty($this->resource_types[$type_id])){
52 return $this->resource_types[$type_id];
54 return $this->resource_types;
58 // Get primary resources
59 function getPrimaryResources(){
62 $pri_resources = array(); // cid=>[resource, language code]
63 $sql = 'SELECT * FROM '.TABLE_PREFIX.'primary_resources WHERE content_id='.$this->cid;
64 $result = mysql_query($sql, $db);
65 if (mysql_numrows($result) > 0){
66 while ($row = mysql_fetch_assoc($result)){
67 $pri_resources[$row['primary_resource_id']]['resource'] = $row['resource'];
68 if ($row['language_code'] != ''){
69 $pri_resources[$row['primary_resource_id']]['language_code'] = $row['language_code'];
73 return $pri_resources;
77 // Get primary resources types
78 function getPrimaryResourcesTypes($pri_resource_id=0){
81 $pri_resource_id = intval($pri_resource_id);
83 //quit if id not specified
84 if ($pri_resource_id == 0) {
88 $pri_resources_types = array(); // cid=>[type id]+
89 $sql = 'SELECT * FROM '.TABLE_PREFIX.'primary_resources_types WHERE primary_resource_id='.$pri_resource_id;
90 $result = mysql_query($sql, $db);
92 while ($row = mysql_fetch_assoc($result)){
93 $pri_resources_types[$pri_resource_id][] = $row['type_id'];
96 return $pri_resources_types;
100 // Get secondary resources
101 function getSecondaryResources($pri_resource_id=0){
104 $pri_resource_id = intval($pri_resource_id);
106 //quit if id not specified
107 if ($pri_resource_id == 0) {
111 $sec_resources = array(); // cid=>[resource, language code]
112 $sql = 'SELECT * FROM '.TABLE_PREFIX.'secondary_resources WHERE primary_resource_id='.$pri_resource_id;
113 $result = mysql_query($sql, $db);
115 while ($row = mysql_fetch_assoc($result)){
116 $sec_resources[$row['secondary_resource_id']]['resource'] = $row['secondary_resource'];
117 if ($row['language_code'] != ''){
118 $sec_resources[$row['secondary_resource_id']]['language_code'] = $row['language_code'];
122 return $sec_resources;
126 // Get secondary resources types
127 function getSecondaryResourcesTypes($sec_resource_id=0){
130 $sec_resource_id = intval($sec_resource_id);
132 //quit if id not specified
133 if ($sec_resource_id == 0) {
137 $sec_resources_types = array(); // cid=>[type id]+
138 $sql = 'SELECT * FROM '.TABLE_PREFIX.'secondary_resources_types WHERE secondary_resource_id='.$sec_resource_id;
139 $result = mysql_query($sql, $db);
141 while ($row = mysql_fetch_assoc($result)){
142 $sec_resources_types[] = $row['type_id'];
145 return $sec_resources_types;
149 // Insert primary resources into the db
150 // @return primary resource id.
151 function setPrimaryResource($content_id, $file_name, $lang){
152 global $addslashes, $db;
154 $content_id = intval($content_id);
155 $file_name = $addslashes($file_name);
156 $lang = $addslashes($lang);
158 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources SET content_id=$content_id, resource='$file_name', language_code='$lang'";
159 $result = mysql_query($sql, $db);
161 return mysql_insert_id();
166 // Insert primary resource type
167 function setPrimaryResourceType($primary_resource_id, $type_id){
170 $primary_resource_id= intval($primary_resource_id);
171 $type_id = intval($type_id);
173 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources_types SET primary_resource_id=$primary_resource_id, type_id=$type_id";
174 $result = mysql_query($sql, $db);
177 // Insert secondary resource
178 // @return secondary resource id
179 function setSecondaryResource($primary_resource_id, $file_name, $lang){
180 global $addslashes, $db;
182 $primary_resource_id = intval($primary_resource_id);
183 $file_name = $addslashes($file_name);
184 $lang = $addslashes($lang);
186 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources SET primary_resource_id=$primary_resource_id, secondary_resource='$file_name', language_code='$lang'";
187 $result = mysql_query($sql, $db);
189 return mysql_insert_id();
194 // Insert secondary resource
195 function setSecondaryResourceType($secondary_resource, $type_id){
198 $secondary_resource = intval($secondary_resource);
199 $type_id = intval($type_id);
201 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources_types SET secondary_resource_id=$secondary_resource, type_id=$type_id";
202 $result = mysql_query($sql, $db);
206 // Set the relative path to all files
207 function setRelativePath($path){
208 $this->relative_path = $path . '/';
212 // Delete all materials associated with this content
213 function deleteA4a(){
216 $pri_resource_ids = array();
218 // Get all primary resources ID out that're associated with this content
219 $sql = 'SELECT a.primary_resource_id FROM '.TABLE_PREFIX.'primary_resources a LEFT JOIN '.TABLE_PREFIX.'primary_resources_types b ON a.primary_resource_id=b.primary_resource_id WHERE content_id='.$this->cid;
220 $result = mysql_query($sql);
222 while($row=mysql_fetch_assoc($result)){
223 $pri_resource_ids[] = $row['primary_resource_id'];
226 //If the are primary resources found
227 if (!empty($pri_resource_ids)){
228 $glued_pri_ids = implode(",", $pri_resource_ids);
230 // Delete all secondary a4a
231 $sql = 'DELETE c, d FROM '.TABLE_PREFIX.'secondary_resources c LEFT JOIN '.TABLE_PREFIX.'secondary_resources_types d ON c.secondary_resource_id=d.secondary_resource_id WHERE primary_resource_id IN ('.$glued_pri_ids.')';
232 $result = mysql_query($sql);
234 // If successful, remove all primary resources
236 $sql = 'DELETE a, b FROM '.TABLE_PREFIX.'primary_resources a LEFT JOIN '.TABLE_PREFIX.'primary_resources_types b ON a.primary_resource_id=b.primary_resource_id WHERE content_id='.$this->cid;