Browse Source

[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.

Yannick Warnier 18 years ago
parent
commit
5cd07f7e34
1 changed files with 45 additions and 0 deletions
  1. 45 0
      main/newscorm/learnpathItem.class.php

+ 45 - 0
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