AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / include / classes / A4a / A4a.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 /**
14  * Accessforall General class.
15  * Based on the specification at: 
16  *              http://www.imsglobal.org/accessibility/index.html
17  *
18  * @date        Oct 3rd, 2008
19  * @author      Harris Wong
20  */
21 class A4a {
22         //variables
23         var $cid = 0;                                           //content id
24         var $resource_types = array();          //resource types hash mapping
25         var $relative_path = '';                        //relative path to the file 
26
27         //Constructor
28         function A4a($cid){
29                 $this->cid = intval($cid);
30         }
31
32
33         // Return resources type hash mapping.
34         function getResourcesType($type_id=0){
35                 $type_id = intval($type_id);
36
37                 //if this is the first time calling this function, grab the list from db
38                 if (empty($resource_types)){
39                         include_once(TR_INCLUDE_PATH.'classes/DAO/ResourceTypesDAO.class.php');
40                         $resourceTypesDAO = new ResourceTypesDAO();
41                         $rows = $resourceTypesDAO->getAll();
42                         
43                         if (is_array($rows))
44                         {
45                                 foreach ($rows as $row) $this->resource_types[$row['type_id']] = $row['type'];
46                         }
47                 }
48
49                 if (!empty($this->resource_types[$type_id])){
50                         return $this->resource_types[$type_id];         
51                 }
52                 return $this->resource_types;
53         }
54
55         
56         // Get primary resources
57         function getPrimaryResources(){
58                 $pri_resources = array(); // cid=>[resource, language code]
59
60                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
61                 $primaryResourcesDAO = new PrimaryResourcesDAO();
62                 $rows = $primaryResourcesDAO->getByContent($this->cid);
63                 
64                 if (is_array($rows)){
65                         foreach ($rows as $row) {
66                                 $pri_resources[$row['primary_resource_id']]['resource'] = $row['resource'];
67                                 if ($row['language_code'] != ''){
68                                         $pri_resources[$row['primary_resource_id']]['language_code'] = $row['language_code'];
69                                 }
70                         }
71                 }
72                 return $pri_resources;
73         }
74
75     //get primary resource by resource name
76     function getPrimaryResourceByName($resource_name){
77         if ($resource_name==''){
78             return array();
79         }
80
81         include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
82         $primaryResourcesDAO = new PrimaryResourcesDAO();
83         $pri_resources = $primaryResourcesDAO->getByResourceName($this->cid, $_SESSION['lang'], $resource_name);
84         return $pri_resources;
85     }
86
87
88         // Get primary resources types
89         function getPrimaryResourcesTypes($pri_resource_id=0){
90                 $pri_resource_id = intval($pri_resource_id);
91
92                 //quit if id not specified
93                 if ($pri_resource_id == 0) {
94                         return array();
95                 }
96
97                 $pri_resources_types = array(); // cid=>[type id]+
98                 
99                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
100                 $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
101                 $rows = $primaryResourcesTypesDAO->getByResourceID($pri_resource_id);
102                 
103                 if (is_array($rows)){
104                         foreach ($rows as $row) {
105                                 $pri_resources_types[$pri_resource_id][] = $row['type_id'];
106                         }
107                 }
108                 return $pri_resources_types;
109         }
110
111
112         // Get secondary resources 
113         function getSecondaryResources($pri_resource_id=0){
114                 global $db;
115
116                 $pri_resource_id = intval($pri_resource_id);
117
118                 //quit if id not specified
119                 if ($pri_resource_id == 0) {
120                         return array();
121                 }
122
123                 $sec_resources = array(); // cid=>[resource, language code]
124                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesDAO.class.php');
125                 $secondaryResourcesDAO = new SecondaryResourcesDAO();
126                 $rows = $secondaryResourcesDAO->getByPrimaryResourceID($pri_resource_id);
127                 
128                 if (is_array($rows)){
129                         foreach ($rows as $row) {
130                                 $sec_resources[$row['secondary_resource_id']]['resource'] = $row['secondary_resource'];
131                                 if ($row['language_code'] != ''){
132                                         $sec_resources[$row['secondary_resource_id']]['language_code'] = $row['language_code'];
133                                 }
134                         }
135                 }
136                 return $sec_resources;
137         }
138
139
140         // Get secondary resources types
141         function getSecondaryResourcesTypes($sec_resource_id=0){
142                 $sec_resource_id = intval($sec_resource_id);
143
144                 //quit if id not specified
145                 if ($sec_resource_id == 0) {
146                         return array();
147                 }
148
149                 $sec_resources_types = array(); // cid=>[type id]+
150                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesTypesDAO.class.php');
151                 $secondaryResourcesTypesDAO = new SecondaryResourcesTypesDAO();
152                 $rows = $secondaryResourcesTypesDAO->getByResourceID($sec_resource_id);
153                 
154                 if (is_array($rows)){
155                         foreach ($rows as $row) {
156                                 $sec_resources_types[] = $row['type_id'];
157                         }
158                 }
159                 return $sec_resources_types;
160         }
161
162
163         // Insert primary resources into the db
164         // @return primary resource id.
165         function setPrimaryResource($content_id, $file_name, $lang){
166                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
167                 $primaryResourcesDAO = new PrimaryResourcesDAO();
168                 
169                 if ($primaryResourcesDAO->Create($content_id, $file_name, $lang)){
170                         return mysql_insert_id();
171                 }
172                 return false;
173         }
174
175         // Insert primary resource type
176         function setPrimaryResourceType($primary_resource_id, $type_id){
177                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
178                 $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
179                 $primaryResourcesTypesDAO->Create($primary_resource_id, $type_id);
180         }
181
182         // Insert secondary resource
183         // @return secondary resource id
184         function setSecondaryResource($primary_resource_id, $file_name, $lang){
185                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesDAO.class.php');
186                 $secondaryResourcesDAO = new SecondaryResourcesDAO();
187                 if ($secondaryResourcesDAO->Create($primary_resource_id, $file_name, $lang)){
188                         return mysql_insert_id();
189                 }
190                 return false;
191         }
192
193         // Insert secondary resource
194         function setSecondaryResourceType($secondary_resource, $type_id){
195                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesTypesDAO.class.php');
196                 $secondaryResourcesTypesDAO = new SecondaryResourcesTypesDAO();
197                 $secondaryResourcesTypesDAO->Create($secondary_resource, $type_id);
198         }
199
200         
201         // Set the relative path to all files
202         function setRelativePath($path){
203                 $this->relative_path = $path . '/';
204         }
205
206
207     /**
208      * Delete this primary resource and all its associated secondary resources
209      * @param   int     primary resournce id
210      */
211     function deletePrimaryResource($primary_rid){
212         include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
213         $primaryResourcesDAO = new PrimaryResourcesDAO();
214         $primaryResourcesDAO->DeleteByResourceID($primary_rid);
215     }
216
217         // Delete all materials associated with this content
218         function deleteA4a(){
219                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
220                 $primaryResourcesDAO = new PrimaryResourcesDAO();
221                 $rows = $primaryResourcesDAO->Delete($this->cid);
222         }    
223 }
224
225 ?>