MDL-13766, use a better value for itemid.

This commit is contained in:
dongsheng
2008-08-06 08:09:01 +00:00
parent 44df8fa94c
commit f3a6f85b94
3 changed files with 11 additions and 14 deletions
+1 -4
View File
@@ -45,10 +45,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_button
return $this->getFrozenHtml();
} else {
$strsaved = get_string('filesaved', 'repository');
// TODO
// Use a better itemid value to identify a repository
// file
$itemid = time();
$itemid = substr(hexdec(uniqid()), 0, 9)+rand(1,100);
$ret = get_repository_client();
$suffix = $ret['suffix'];
$str = $this->_getTabs();
+4 -6
View File
@@ -282,9 +282,8 @@ function repository_get_option($id, $position){
$ret = (array)unserialize($entry->$option);
return $ret;
}
function repository_instances(){
function repository_instances($contextid = SITEID){
global $DB, $CFG, $USER;
$contextid = 0;
$params = array();
$sql = 'SELECT * FROM {repository} r WHERE ';
$sql .= ' (r.userid = 0 or r.userid = ?) ';
@@ -354,17 +353,16 @@ function move_to_filepool($path, $name, $itemid) {
if ($file = $fs->create_file_from_pathname($entry, $path)) {
$id = json_encode($file->get_itemid());
$ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
// TODO
// get_params should include id value, talk to Petr.
return array('url'=>$ret->get_url(),'id'=>$file->get_itemid());
} else {
return null;
}
}
// TODO
// Need to pass contextid and contextlevel here
function get_repository_client(){
global $CFG;
global $CFG, $USER;
$suffix = uniqid();
$strsubmit = get_string('submit', 'repository');
$strlistview = get_string('listview', 'repository');
+6 -4
View File
@@ -17,9 +17,13 @@ $action = optional_param('action', '', PARAM_RAW);
$search = optional_param('s', '', PARAM_RAW);
// id of repository
$repo_id = optional_param('repo_id', 1, PARAM_INT);
$itemid = optional_param('itemid', 0, PARAM_INT);
// context id
$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT);
$itemid = optional_param('itemid', 0, PARAM_INT);
$userid = $USER->id;
if(!$repository = $DB->get_record('repository', array('id'=>$repo_id))) {
if(!$repository = $DB->get_record('repository', array('id'=>$repo_id)))
{
$err = new stdclass;
$err->e = get_string('invalidrepositoryid', 'repository');
die(json_encode($err));
@@ -87,5 +91,3 @@ if($action == 'list') {
die(json_encode($err));
}
}
?>