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 /************************************************************************/
14 * Accessforall General class.
15 * Based on the specification at:
16 * http://www.imsglobal.org/accessibility/index.html
23 var $cid = 0; //content id
24 var $resource_types = array(); //resource types hash mapping
25 var $relative_path = ''; //relative path to the file
29 $this->cid = intval($cid);
33 // Return resources type hash mapping.
34 function getResourcesType($type_id=0){
35 $type_id = intval($type_id);
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();
45 foreach ($rows as $row) $this->resource_types[$row['type_id']] = $row['type'];
49 if (!empty($this->resource_types[$type_id])){
50 return $this->resource_types[$type_id];
52 return $this->resource_types;
56 // Get primary resources
57 function getPrimaryResources(){
58 $pri_resources = array(); // cid=>[resource, language code]
60 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesDAO.class.php');
61 $primaryResourcesDAO = new PrimaryResourcesDAO();
62 $rows = $primaryResourcesDAO->getByContent($this->cid);
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'];
72 return $pri_resources;
76 // Get primary resources types
77 function getPrimaryResourcesTypes($pri_resource_id=0){
78 $pri_resource_id = intval($pri_resource_id);
80 //quit if id not specified
81 if ($pri_resource_id == 0) {
85 $pri_resources_types = array(); // cid=>[type id]+
87 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
88 $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
89 $rows = $primaryResourcesTypesDAO->getByResourceID($pri_resource_id);
92 foreach ($rows as $row) {
93 $pri_resources_types[$pri_resource_id][] = $row['type_id'];
96 return $pri_resources_types;
100 // Get secondary resources
101 function getSecondaryResources($pri_resource_id=0){
104 $pri_resource_id = intval($pri_resource_id);
106 //quit if id not specified
107 if ($pri_resource_id == 0) {
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);
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'];
124 return $sec_resources;
128 // Get secondary resources types
129 function getSecondaryResourcesTypes($sec_resource_id=0){
130 $sec_resource_id = intval($sec_resource_id);
132 //quit if id not specified
133 if ($sec_resource_id == 0) {
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);
142 if (is_array($rows)){
143 foreach ($rows as $row) {
144 $sec_resources_types[] = $row['type_id'];
147 return $sec_resources_types;
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();
157 if ($primaryResourcesDAO->Create($content_id, $file_name, $lang)){
158 return mysql_insert_id();
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);
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();
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);
189 // Set the relative path to all files
190 function setRelativePath($path){
191 $this->relative_path = $path . '/';
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);