2 /********************************************************************/
4 /********************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /********************************************************************/
15 require_once(AT_INCLUDE_PATH.'../mods/_core/imsafa/classes/A4a.class.php');
18 * Accessforall Import class.
19 * Based on the specification at:
20 * http://www.imsglobal.org/accessibility/index.html
25 class A4aImport extends A4a {
27 function A4aImport($cid){
28 parent::A4a($cid); //call its parent
33 * @param array XML items generated by the IMS import
35 function importA4a($items){
36 //imported files, keep track of what file path that's been processed. Do not add repeated ones
37 $imported_files = array();
39 //use the items array data and insert it into the database.
40 foreach ($items as $file_path => $a4a_resources){
41 foreach ($a4a_resources as $resource){
42 //If it has adaptation/alternative, this is a primary file.
43 if (isset($resource['hasAdaptation']) && !empty($resource['hasAdaptation'])){
44 //we only have one language in the table, [1], [2], etc will be the same
45 $pri_lang = $resource['language'][0];
47 //insert primary resource
48 $primary_id = $this->setPrimaryResource($this->cid, str_replace($this->relative_path, '', $file_path), $pri_lang);
50 //get primary resource type
51 $resources_attrs = $resource['access_stmt_originalAccessMode'];
53 $attrs = $this->toResourceTypeId($resources_attrs);
55 //insert primary resource type associations
56 foreach ($attrs as $resource_type_id){
57 $this->setPrimaryResourceType($primary_id, $resource_type_id);
60 //insert secondary resource
61 $secondary_resources = $resource['hasAdaptation']; //uri array
62 foreach ($secondary_resources as $secondary_resource){
63 //some paths will reference files above this directory, as a result
64 //we will see ../, but since everything is under 'resources/', the relative_path
65 //we can safely take it out.
66 //@edited Dec 6th, imscc import uses relative paths, ims doesn't.
67 if (substr($secondary_resource, 0, 7) == 'http://' || substr($secondary_resource, 0, 8) == 'https://') {
68 $secondary_resource_with_relative_path = $secondary_resource;
70 $secondary_resource_with_relative_path = $this->relative_path.$secondary_resource;
73 $secondary_files = $items[$secondary_resource_with_relative_path];
74 if (in_array($secondary_resource_with_relative_path, $imported_files)){
77 $imported_files[] = $secondary_resource_with_relative_path;
78 if (empty($secondary_files)){
79 //tweak: if this is empty, then most likely it is an ims import.
80 $secondary_resource = preg_replace('/^\.\.\//', '', $secondary_resource);
81 $secondary_files = $items[$secondary_resource_with_relative_path];
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);
100 //insert secondary resource type associations
101 foreach ($secondary_attr as $secondary_resource_type_id){
102 $this->setSecondaryResourceType($secondary_id, $secondary_resource_type_id);
104 //break; //1-to-1 mapping, no need to go further
107 } //foreach of secondary_resources
108 $imported_files = array(); //reset the imported file for the next resource
110 } //foreach of resources
111 } //foreach of item array
115 * By the given attrs array, decide which resource type it is
117 * sign_language = type 2
121 * return type id array
123 function toResourceTypeId($resources_attrs){
127 if (empty($resources_attrs)){
130 if (is_array($resources_attrs)) {
131 if (in_array('auditory', $resources_attrs)){
134 if (in_array('sign_language', $resources_attrs)){
137 if (in_array('textual', $resources_attrs)){
140 if (in_array('visual', $resources_attrs)){
144 if ($resources_attrs=='auditory'){
146 } elseif ($resources_attrs=='sign_language'){
148 } elseif ($resources_attrs=='textual'){
150 } elseif ($resources_attrs=='visual'){