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');
16 * Accessforall Import class.
17 * Based on the specification at:
18 * http://www.imsglobal.org/accessibility/index.html
23 class A4aImport extends A4a {
25 function A4aImport($cid){
26 parent::A4a($cid); //call its parent
31 * @param array XML items generated by the IMS import
33 function importA4a($items){
34 //imported files, keep track of what file path that's been processed. Do not add repeated ones
35 $imported_files = array();
37 //use the items array data and insert it into the database.
38 foreach ($items as $file_path => $a4a_resources){
39 foreach ($a4a_resources as $resource){
40 //If it has adaptation/alternative, this is a primary file.
41 if (isset($resource['hasAdaptation']) && !empty($resource['hasAdaptation'])){
42 //we only have one language in the table, [1], [2], etc will be the same
43 $pri_lang = $resource['language'][0];
45 //insert primary resource
46 $primary_id = $this->setPrimaryResource($this->cid, str_replace($this->relative_path, '', $file_path), $pri_lang);
48 //get primary resource type
49 $resources_attrs = $resource['access_stmt_originalAccessMode'];
51 $attrs = $this->toResourceTypeId($resources_attrs);
53 //insert primary resource type associations
54 foreach ($attrs as $resource_type_id){
55 $this->setPrimaryResourceType($primary_id, $resource_type_id);
58 //insert secondary resource
59 $secondary_resources = $resource['hasAdaptation']; //uri array
60 foreach ($secondary_resources as $secondary_resource){
61 //some paths will reference files above this directory, as a result
62 //we will see ../, but since everything is under 'resources/', the relative_path
63 //we can safely take it out.
64 //@edited Dec 6th, imscc import uses relative paths, ims doesn't.
65 if (substr($secondary_resource, 0, 7) == 'http://' || substr($secondary_resource, 0, 8) == 'https://') {
66 $secondary_resource_with_relative_path = $secondary_resource;
68 $secondary_resource_with_relative_path = $this->relative_path.$secondary_resource;
71 $secondary_files = $items[$secondary_resource_with_relative_path];
72 if (in_array($secondary_resource_with_relative_path, $imported_files)){
75 $imported_files[] = $secondary_resource_with_relative_path;
77 if (empty($secondary_files)){
78 //tweak: if this is empty, then most likely it is an ims import.
79 $secondary_resource = preg_replace('/^\.\.\//', '', $secondary_resource);
80 $secondary_files = $items[$this->relative_path.$secondary_resource];
83 //check if this secondary file is the adaptation of
85 foreach($secondary_files as $secondary_file){
86 //isAdaptation is 1-to-1 mapping, save to use [0]
87 if (substr($secondary_file['isAdaptationOf'][0], 0, 7) == 'http://'
88 || substr($secondary_file['isAdaptationOf'][0], 0, 8) == 'https://') {
89 $adaption_with_relative_path = $secondary_file['isAdaptationOf'][0];
91 $adaption_with_relative_path = $this->relative_path.$secondary_file['isAdaptationOf'][0];
94 if($adaption_with_relative_path == $file_path){
95 $secondary_lang = $secondary_file['language'][0];
97 //access_stmt_originalAccessMode cause we want the language for the secondary file.
98 $secondary_attr = $this->toResourceTypeId($secondary_file['access_stmt_originalAccessMode']);
99 $secondary_id = $this->setSecondaryResource($primary_id, $secondary_resource, $secondary_lang);
101 //insert secondary resource type associations
102 foreach ($secondary_attr as $secondary_resource_type_id){
103 $this->setSecondaryResourceType($secondary_id, $secondary_resource_type_id);
105 //break; //1-to-1 mapping, no need to go further
108 } //foreach of secondary_resources
109 $imported_files = array(); //reset the imported file for the next resource
111 } //foreach of resources
112 } //foreach of item array
116 * By the given attrs array, decide which resource type it is
118 * sign_language = type 2
122 * return type id array
124 function toResourceTypeId($resources_attrs){
128 if (empty($resources_attrs)){
131 if (is_array($resources_attrs)) {
132 if (in_array('auditory', $resources_attrs)){
135 if (in_array('sign_language', $resources_attrs)){
138 if (in_array('textual', $resources_attrs)){
141 if (in_array('visual', $resources_attrs)){
145 if ($resources_attrs=='auditory'){
147 } elseif ($resources_attrs=='sign_language'){
149 } elseif ($resources_attrs=='textual'){
151 } elseif ($resources_attrs=='visual'){