[ Index ] |
|
Code source de Claroline 188 |
1 <?php // $Id: resolver.lib.php,v 1.11.2.1 2007/10/31 10:00:00 mathieu Exp $ 2 if ( count( get_included_files() ) == 1 ) die( '---' ); 3 /** 4 * CLAROLINE 5 * 6 * @version 1.8 $Revision: 1.11.2.1 $ 7 * 8 * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL) 9 * 10 * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE 11 * 12 * @author claroline Team <cvs@claroline.net> 13 * @author Renaud Fallier <renaud.claroline@gmail.com> 14 * @author Frédéric Minne <minne@ipm.ucl.ac.be> 15 * 16 * @package CLLINKER 17 * 18 */ 19 require_once dirname(__FILE__) . '/linker.lib.php'; 20 require_once dirname(__FILE__) . '/CRLTool.php'; 21 require_once dirname(__FILE__) . '/../inc/lib/course_utils.lib.php'; 22 require_once dirname(__FILE__) . '/../inc/lib/claro_utils.lib.php'; 23 24 /** 25 * Class Resolver 26 * is a abstact class 27 * 28 * @author Fallier Renaud 29 */ 30 class Resolver 31 { 32 /*------------------------- 33 variable 34 ------------------------*/ 35 var $_basePath; 36 37 /*---------------------------- 38 public method 39 ---------------------------*/ 40 41 /** 42 * constructor 43 * 44 * @param string $basePath string path root directory of courses 45 */ 46 function Resolver($basePath) 47 { 48 $basePath = preg_replace( '~/$~', '', $basePath ); 49 $this->_basePath = $basePath; 50 } 51 52 /** 53 * translated a crl into valid URL 54 * 55 * @param $CRL string a crl 56 * @return string a url valide who corresponds to the crl 57 */ 58 function resolve($crl) 59 { 60 $elementCRLArray = CRLTool::parseCRL($crl); 61 62 // resolve course crl 63 if( isset( $elementCRLArray['course_sys_code'] ) 64 && !isset( $elementCRLArray['tool_name'] ) 65 && !isset( $elementCRLArray['team'] ) 66 && !isset( $elementCRLArray['resource_id'] ) ) 67 { 68 $tool = 'CourseResolver'; 69 require_once dirname(__FILE__) . '/' . $tool . '.php'; 70 $resolver = new $tool($this->_basePath); 71 72 return $resolver->resolve($crl); 73 } 74 // resolve a group crl 75 else if( isset( $elementCRLArray['course_sys_code'] ) 76 && isset( $elementCRLArray['team'] ) 77 && !isset( $elementCRLArray['tool_name'] ) 78 && !isset( $elementCRLArray['resource_id'] ) ) 79 { 80 $tool = 'CLGRP___Resolver'; 81 require_once dirname(__FILE__) . '/' . $tool . '.php'; 82 $resolver = new $tool($this->_basePath); 83 84 return $resolver->resolve($crl); 85 } 86 // resolve a tool (course and group) crl 87 else if( isset( $elementCRLArray['course_sys_code'] ) 88 && isset( $elementCRLArray['tool_name'] ) 89 && !isset( $elementCRLArray['resource_id'] ) ) 90 { 91 return $this->_resolve($crl); 92 } 93 // resolve tool resource crl 94 else 95 { 96 $tool = $elementCRLArray['tool_name'] . 'Resolver'; 97 require_once dirname(__FILE__) . '/' . $tool . '.php'; 98 $resolver = new $tool($this->_basePath); 99 100 return $resolver->resolve($crl); 101 } 102 } 103 104 /** 105 * get the id of a resource for a tool 106 * 107 * @param $tool_name (string) id of a tool. It is the Tlabel 108 * @return integer id of a resource 109 */ 110 function getResourceId($tool_name) 111 { 112 if( isset( $tool_name ) ) 113 { 114 $tool_name = str_pad( $tool_name, 8, '_' ); 115 $tool = $tool_name . 'Resolver'; 116 require_once dirname(__FILE__) . '/' . $tool . '.php'; 117 $resolver = new $tool($this->_basePath); 118 119 return $resolver->getResourceId($tool_name); 120 } 121 else 122 { 123 trigger_error('Error: missing tool name ',E_USER_ERROR); 124 } 125 } 126 127 /** 128 * get the name of a reso 129 * 130 * @param $crl a crl valide 131 * @return 132 */ 133 function getResourceName($crl) 134 { 135 $elementCRLArray = CRLTool::parseCRL($crl); 136 137 if( isset( $elementCRLArray['course_sys_code'] ) 138 && !isset( $elementCRLArray['tool_name'] ) 139 && !isset( $elementCRLArray['team'] ) 140 && !isset( $elementCRLArray['resource_id'] ) ) 141 { 142 $tool = 'CourseResolver'; 143 require_once dirname(__FILE__) . '/' . $tool . '.php'; 144 $resolver = new $tool($this->_basePath); 145 146 return $resolver->getResourceName($crl); 147 } 148 else if( isset( $elementCRLArray['course_sys_code'] ) 149 && isset( $elementCRLArray['team'] ) 150 && !isset( $elementCRLArray['tool_name'] ) 151 && !isset( $elementCRLArray['resource_id'] ) ) 152 { 153 $tool = 'CLGRP___Resolver'; 154 require_once dirname(__FILE__) . '/' . $tool . '.php'; 155 $resolver = new $tool($this->_basePath); 156 157 return $resolver->getResourceName($crl); 158 } 159 else if( isset( $elementCRLArray['course_sys_code'] ) 160 && isset( $elementCRLArray['tool_name'] ) 161 && !isset( $elementCRLArray['resource_id'] ) ) 162 { 163 return $this->_getResourceName($crl); 164 } 165 else 166 { 167 $tool = str_pad( $elementCRLArray['tool_name'] . 'Resolver', 8, '_' ); 168 require_once dirname(__FILE__) . '/' . $tool . '.php'; 169 $resolver = new $tool($this->_basePath); 170 171 return $resolver->getResourceName($crl); 172 } 173 } 174 175 /** 176 * translated a crl into valid URL 177 * 178 * @param $CRL string a crl 179 * @return string a url valide who corresponds to the crl 180 */ 181 function _resolve($crl) 182 { 183 if($crl) 184 { 185 $elementCRLArray = CRLTool::parseCRL($crl); 186 187 if( !isset($elementCRLArray['tool_name']) ) 188 { 189 trigger_error('ERROR: tool_name required',E_USER_ERROR); 190 } 191 192 $url = $this->_getToolPath($elementCRLArray['tool_name']); 193 $url .= '?cidReq=' . $elementCRLArray['course_sys_code']; 194 195 // add the gidReq at the url 196 if( isset($elementCRLArray['team']) ) 197 { 198 $url .= '&gidReq=' . $elementCRLArray['team']; 199 } 200 201 // change the url if it is a group forum 202 if( $elementCRLArray['tool_name'] == 'CLFRM___' && isset($elementCRLArray['team']) ) 203 { 204 $courseInfoArray = get_info_course($elementCRLArray['course_sys_code']); 205 $tbl_cdb_names = claro_sql_get_course_tbl($courseInfoArray['dbNameGlu']); 206 $tbl_group = $tbl_cdb_names['group_team']; 207 208 $sql = 'SELECT `forumId` 209 FROM `' . $tbl_group . '` 210 WHERE `id` =' . (int)$elementCRLArray['team']; 211 $forumId = claro_sql_query_get_single_value($sql); 212 213 $url = $this->_basePath . '/claroline/phpbb/viewforum.php' 214 . '?forum=' . $forumId 215 . '&cidReq=' . $elementCRLArray['course_sys_code'] 216 . '&gidReq=' . $elementCRLArray['team'] 217 ; 218 } 219 else 220 { 221 $url = $this->_basePath . $url; 222 } 223 224 return $url; 225 226 } 227 else 228 { 229 trigger_error('ERROR: crl is required',E_USER_ERROR); 230 } 231 } 232 233 /** 234 * get the path of a tool 235 * 236 * @param $toolName (string) a Tlabel 237 * @return string the path 238 */ 239 function _getToolPath($toolName) 240 { 241 $toolName = rtrim( $toolName, '_' ); 242 return get_module_url( $toolName ) . '/' . get_module_entry( $toolName ); 243 } 244 245 /** 246 * get the title of a resource 247 * 248 * @param $crl a crl 249 * @return the title of a resource 250 */ 251 function _getResourceName($crl) 252 { 253 $elementCRLArray = CRLTool::parseCRL($crl); 254 $title = get_toolname_title($elementCRLArray); 255 256 return $title; 257 } 258 } 259 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 14:38:42 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |