예제 #1
0
 /**
  * Static admin function allowing addition of a learnpath to a course.
  * @param	string	Course code
  * @param	string	Learnpath name
  * @param	string	Learnpath description string, if provided
  * @param	string	Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
  * @param	string	Type of files origin (default = 'zip', others = 'dir','web_dir',...)
  * @param	string	Zip file containing the learnpath or directory containing the learnpath
  * @param	string	Keyword tags to add to the document
  * @return	integer	The new learnpath ID on success, 0 on failure
  */
 function add_lp($course, $name, $description = '', $learnpath = 'guess', $origin = 'zip', $zipname = '', $keyword = '')
 {
     global $charset;
     //if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
     //TODO
     $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
     //check course code exists
     //check lp_name doesn't exist, otherwise append something
     $i = 0;
     $name = learnpath::escape_string($name);
     //session_id
     $session_id = api_get_session_id();
     $check_name = "SELECT * FROM {$tbl_lp} WHERE name = '{$name}'";
     //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
     $res_name = Database::query($check_name, __FILE__, __LINE__);
     while (Database::num_rows($res_name)) {
         //there is already one such name, update the current one a bit
         $i++;
         $name = $name . ' - ' . $i;
         $check_name = "SELECT * FROM {$tbl_lp} WHERE name = '{$name}'";
         //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
         $res_name = Database::query($check_name, __FILE__, __LINE__);
     }
     //new name does not exist yet; keep it
     //escape description
     $description = learnpath::escape_string(api_htmlentities($description, ENT_QUOTES, $charset));
     //Kevin: added htmlentities()
     $type = 1;
     switch ($learnpath) {
         case 'guess':
             break;
         case 'dokeos':
             $type = 1;
             break;
         case 'aicc':
             break;
     }
     switch ($origin) {
         case 'zip':
             //check zipname string. If empty, we are currently creating a new Dokeos learnpath
             break;
         case 'manual':
         default:
             $get_max = "SELECT MAX(display_order) FROM {$tbl_lp}";
             $res_max = Database::query($get_max, __FILE__, __LINE__);
             if (Database::num_rows($res_max) < 1) {
                 $dsp = 1;
             } else {
                 $row = Database::fetch_array($res_max);
                 $dsp = $row[0] + 1;
             }
             $sql_insert = "INSERT INTO {$tbl_lp} " . "(lp_type,name,description,path,default_view_mod," . "default_encoding,display_order,content_maker," . "content_local,js_lib,session_id) " . "VALUES ({$type},'{$name}','{$description}','','embedded'," . "'UTF-8','{$dsp}','Dokeos'," . "'local','','" . Database::escape_string($session_id) . "')";
             //if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
             $res_insert = Database::query($sql_insert, __FILE__, __LINE__);
             $id = Database::insert_id();
             if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) {
                 //save search engine keyword
                 $searchkey = new SearchEngineManager();
                 $searchkey->idobj = $id;
                 $searchkey->course_code = api_get_course_id();
                 $searchkey->tool_id = TOOL_LEARNPATH;
                 $searchkey->value = $keyword;
                 $searchkey->save();
                 $lp = new learnpath(api_get_course_id(), $id, api_get_user_id());
                 $lp->search_engine_save();
             }
             if ($id > 0) {
                 //insert into item_property
                 api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
                 return $id;
             }
             break;
     }
 }