9b7c069294caf2cf90caf1aeeeb35fabaa38ad6b
[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
76         // Get primary resources types
77         function getPrimaryResourcesTypes($pri_resource_id=0){
78                 $pri_resource_id = intval($pri_resource_id);
79
80                 //quit if id not specified
81                 if ($pri_resource_id == 0) {
82                         return array();
83                 }
84
85                 $pri_resources_types = array(); // cid=>[type id]+
86                 
87                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
88                 $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
89                 $rows = $primaryResourcesTypesDAO->getByResourceID($pri_resource_id);
90                 
91                 if (is_array($rows)){
92                         foreach ($rows as $row) {
93                                 $pri_resources_types[$pri_resource_id][] = $row['type_id'];
94                         }
95                 }
96                 return $pri_resources_types;
97         }
98
99
100         // Get secondary resources 
101         function getSecondaryResources($pri_resource_id=0){
102                 global $db;
103
104                 $pri_resource_id = intval($pri_resource_id);
105
106                 //quit if id not specified
107                 if ($pri_resource_id == 0) {
108                         return array();
109                 }
110
111                 $sec_resources = array(); // cid=>[resource, language code]
112                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesDAO.class.php');
113                 $secondaryResourcesDAO = new SecondaryResourcesDAO();
114                 $rows = $secondaryResourcesDAO->getByPrimaryResourceID($pri_resource_id);
115                 
116                 if (is_array($rows)){
117                         foreach ($rows as $row) {
118                                 $sec_resources[$row['secondary_resource_id']]['resource'] = $row['secondary_resource'];
119                                 if ($row['language_code'] != ''){
120                                         $sec_resources[$row['secondary_resource_id']]['language_code'] = $row['language_code'];
121                                 }
122                         }
123                 }
124                 return $sec_resources;
125         }
126
127
128         // Get secondary resources types
129         function getSecondaryResourcesTypes($sec_resource_id=0){
130                 $sec_resource_id = intval($sec_resource_id);
131
132                 //quit if id not specified
133                 if ($sec_resource_id == 0) {
134                         return array();
135                 }
136
137                 $sec_resources_types = array(); // cid=>[type id]+
138                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesTypesDAO.class.php');
139                 $secondaryResourcesTypesDAO = new SecondaryResourcesTypesDAO();
140                 $rows = $secondaryResourcesTypesDAO->getByResourceID($sec_resource_id);
141                 
142                 if (is_array($rows)){
143                         foreach ($rows as $row) {
144                                 $sec_resources_types[] = $row['type_id'];
145                         }
146                 }
147                 return $sec_resources_types;
148         }
149
150
151         // Insert primary resources into the db
152         // @return primary resource id.
153         function setPrimaryResource($content_id, $file_name, $lang){
154                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
155                 $primaryResourcesDAO = new PrimaryResourcesDAO();
156                 
157                 if ($primaryResourcesDAO->Create($content_id, $file_name, $lang)){
158                         return mysql_insert_id();
159                 }
160                 return false;
161         }
162
163         // Insert primary resource type
164         function setPrimaryResourceType($primary_resource_id, $type_id){
165                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
166                 $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
167                 $primaryResourcesTypesDAO->Create($primary_resource_id, $type_id);
168         }
169
170         // Insert secondary resource
171         // @return secondary resource id
172         function setSecondaryResource($primary_resource_id, $file_name, $lang){
173                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesDAO.class.php');
174                 $secondaryResourcesDAO = new SecondaryResourcesDAO();
175                 if ($secondaryResourcesDAO->Create($primary_resource_id, $file_name, $lang)){
176                         return mysql_insert_id();
177                 }
178                 return false;
179         }
180
181         // Insert secondary resource
182         function setSecondaryResourceType($secondary_resource, $type_id){
183                 include_once(TR_INCLUDE_PATH.'classes/DAO/SecondaryResourcesTypesDAO.class.php');
184                 $secondaryResourcesTypesDAO = new SecondaryResourcesTypesDAO();
185                 $secondaryResourcesTypesDAO->Create($secondary_resource, $type_id);
186         }
187
188         
189         // Set the relative path to all files
190         function setRelativePath($path){
191                 $this->relative_path = $path . '/';
192         }
193
194
195         // Delete all materials associated with this content
196         function deleteA4a(){
197                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
198                 $primaryResourcesDAO = new PrimaryResourcesDAO();
199                 $rows = $primaryResourcesDAO->Delete($this->cid);
200         }
201 }
202
203 ?>