From 5cd07f7e342efc0133e8317ca3e011429459a110 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Tue, 6 Mar 2007 13:32:22 +0100 Subject: [PATCH] [svn r11419] Added get_file_path() method to get the path of the file whichever tool it comes from. This method is only partial for now and replaces the similar but not identical functions in resourcelinker. --- main/newscorm/learnpathItem.class.php | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index a231b279d2..adb451b7b2 100644 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -265,6 +265,51 @@ class learnpathItem{ if(empty($this->description)){return '';} return $this->description; } + /** + * Gets the file path from the course's root directory, no matter what tool it is from. + * @return string The file path, or an empty string if there is no file attached, or '-1' if the file must be replaced by an error page + */ + function get_file_path(){ + if($this->debug>0){error_log('New LP - In learnpathItem::get_file_path()',0);} + $path = $this->get_path(); + $type = $this->get_type(); + if(empty($path)) + { + if($type == 'dokeos_chapter' OR $type=='chapter' OR $type == 'dir') + { + return ''; + } + else + { + return '-1'; + } + }elseif($path == strval(intval($path))){ + //the path is numeric, so it is a reference to a Dokeos object + switch($type) + { + case 'dokeos_chapter': + case 'dir': + case 'chapter': + return ''; + case TOOL_DOCUMENT: + $table_doc = Database::get_course_table(TABLE_DOCUMENT); + $sql = 'SELECT path FROM '.$table_doc.' WHERE id = '.$path; + $res = api_sql_query($sql,__FILE__,__LINE__); + $row = Database::fetch_array($res); + $real_path = 'document/'.$row['path']; + return $real_path; + case TOOL_STUDENTPUBLICATION: + case TOOL_QUIZ: + case TOOL_FORUM: + case TOOL_THREAD: + case TOOL_LINK: + default: + return '-1'; + } + }else{ + return $path; + } + } /** * Gets the DB ID * @return integer Database ID for the current item