2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 require_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
14 //require(TR_INCLUDE_PATH.'classes/zipfile.class.php'); // for zipfile
17 * Accessforall Export class.
18 * Based on the specification at:
19 * http://www.imsglobal.org/accessibility/index.html
24 class A4aExport extends A4a {
25 var $original_files = array(); //store all the primary/original resources in [id]=>[incrementer]=>[resource, language, type]
26 // var $alternative_files = array(); //secondary files aka. alternative, equivalent
29 * Get information for this content
30 * @return the xml content
32 function getAlternative(){
33 $resources = parent::getPrimaryResources();
35 foreach($resources as $rid => $prop){
36 $resources_types = parent::getPrimaryResourcesTypes($rid);
38 $secondary_array = array();
39 foreach($resources_types as $rtid){
40 $sec_resources['secondary_resources'] = parent::getSecondaryResources($rid);
41 //determine secondary resource type
42 foreach ($sec_resources['secondary_resources'] as $sec_id => $sec_resource){
43 $current_sec_file = $sec_resource['resource'];
44 $secondary_array['secondary_resources'][] = $current_sec_file ;
46 //add to secondary file array if it's not there
47 if (!isset($this->original_files[$current_sec_file]) || empty($this->original_files[$current_sec_file]) ){
48 //TODO merge these values i think
49 $this->original_files[$current_sec_file ] = $sec_resource;
50 $this->original_files[$current_sec_file ]['resource_type'][$prop['resource']] = parent::getSecondaryResourcesTypes($sec_id);
52 $this->original_files[$current_sec_file ]['resource_type'][$prop['resource']] = parent::getSecondaryResourcesTypes($sec_id);
54 //add this primary file ref, and the resources type to the secondary file
55 $this->original_files[$current_sec_file]['primary_resources'][$prop['resource']] = $rtid;
56 // $this->original_files[$current_sec_file]['primary_resources'][$prop['resource']]['language_code'] = $sec_resource['language_code'];
59 $res_type['resource_type'] = $rtid; //could be 1+
60 $temp = array_merge($prop, $res_type, $secondary_array);
61 if (isset($this->original_files[$temp['resource']])){
62 //use the existing temp array values, but merge in the secondary_array
63 $temp = array_merge($this->original_files[$temp['resource']], $secondary_array);
66 $this->original_files[$temp['resource']] = $temp;
69 return $this->original_files;
73 * Get all secondary files
74 * @return array of secondary files that is being used in this->content.
76 function getAllSecondaryFiles(){
78 $secondary_files = array();
80 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesDAO.class.php');
81 $secondaryResourcesDAO = new SecondaryResourcesDAO();
82 $rows = $secondaryResourcesDAO->getByContent($this->cid);
83 // $sql = "SELECT DISTINCT secondary_resource FROM ".TABLE_PREFIX."primary_resources a LEFT JOIN ".TABLE_PREFIX."secondary_resources s
84 // ON a.primary_resource_id = s.primary_resource_id WHERE content_id=".$this->cid;
85 // $result = mysql_query ($sql);
88 foreach ($rows as $row) {
89 if (!empty($row['secondary_resource'])){
90 $secondary_files[] = $row['secondary_resource'];
94 return $secondary_files;
97 // Save all the xml into an array.
98 // key=filename, value=xml content
102 $xml_array = array(); //array of xml
104 // Get the alt content first.
105 $this->getAlternative();
107 // Get original files' xml
108 foreach($this->original_files as $id=>$resource){
109 $orig_access_mode = array();
111 foreach($resource['resource_type'] as $type_id){
112 if (!is_array($type_id)){
113 //primary resource will always have just on type
114 $orig_access_mode[] = $this->getResourceNameById($type_id);
116 foreach($type_id as $k=>$type_id2){
117 $orig_access_mode[] = $this->getResourceNameById($type_id2[0]);
121 $savant->assign('relative_path', $this->relative_path); //the template will need the relative path
122 $savant->assign('orig_access_mode', $orig_access_mode);
123 $savant->assign('language_code', $resource['language_code']);
124 $savant->assign('secondary_resources', $resource['secondary_resources']);
126 // If this is an alternative, and it is mapping to
127 // 1+ original files. Each of these mapping requires
129 if(isset($resource['primary_resources'])){
130 foreach($resource['primary_resources'] as $uri=>$pri_resource_types){
131 $savant->assign('primary_resource_uri', $uri);
132 $savant->assign('primary_resources', $pri_resource_types);
133 //A file can be both original and alternative, and each could represent diff language
134 //Tried to resolve but the A4a v.2 only accept 1 language
135 // $savant->assign('language_code', $pri_resource_types['language_code']);
136 //overwrite orig_access_mode
137 $orig_access_mode = array(); //reinitialize
138 foreach($resource['resource_type'][$uri] as $type_id){
139 $orig_access_mode[] = $this->getResourceNameById($type_id);
140 $savant->assign('orig_access_mode', $orig_access_mode);
141 $xml_array[$id.' to '.$uri][] = $savant->fetch(TR_INCLUDE_PATH.'classes/A4a/A4a.tmpl.php');
145 $savant->assign('primary_resource_uri', '');
146 $savant->assign('primary_resources', '');
147 $xml_array[$id] = $savant->fetch(TR_INCLUDE_PATH.'classes/A4a/A4a.tmpl.php');
154 * Get resource name by id
157 function getResourceNameById($type_id){
158 $orig_access_mode = '';
159 if (is_array($type_id)) {
160 $type_id = $type_id[0];
164 $orig_access_mode = 'auditory';
167 $orig_access_mode = 'textual';
170 $orig_access_mode = 'sign_language';
173 $orig_access_mode = 'visual';
176 $orig_access_mode = '';
178 return $orig_access_mode;