Skip to content

Commit

Permalink
MDL-15402: delete a type now delete all its instances, fix confirmati…
Browse files Browse the repository at this point in the history
…on xhtml and message, change save label buttons, repository_get_instances() return now all instances if no context is defined
  • Loading branch information
jerome committed Sep 3, 2008
1 parent 4f2b9a4 commit 46dd6bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion admin/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
}
exit;
}
notice_yesno(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
notice_yesno(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
$return = false;
}
else if (!empty($move) && !empty($type)) {
Expand Down
2 changes: 1 addition & 1 deletion lang/en_utf8/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$string['configcacheexpire'] = 'Configurate the cache expired time (in minutes).';
$string['configsaved'] = 'Configuration saved!';
$string['confirmdelete'] = 'Are you sure you want to delete this repository - $a?';
$string['confirmremove'] = 'Are you sure you want to remove this repository plugin - $a?';
$string['confirmremove'] = 'Are you sure you want to remove this repository plugin and <strong style=color:red>all of its instances</strong> - $a?';
$string['create'] = 'Create';
$string['createrepository'] = 'Create a repository instance';
$string['date'] = 'Date';
Expand Down
46 changes: 26 additions & 20 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function __construct($typename = '', $typeoptions = array(), $visible = t
$this->_typename = $typename;
$this->_visible = $visible;
$this->_sortorder = $sortorder;

//set options attribut
$this->_options = array();
//check that the type can be setup
Expand Down Expand Up @@ -337,6 +337,13 @@ public function switch_and_update_visibility(){
*/
public function delete(){
global $DB;

//delete all instances of this type
$instances = repository_get_instances(null,null,false,$this->_typename);
foreach($instances as $instance){
$instance->delete();
}

return $DB->delete_records('repository', array('type' => $this->_typename));
}
}
Expand Down Expand Up @@ -386,10 +393,7 @@ function repository_get_types(){

if($records = $DB->get_records('repository',null,'sortorder')) {
foreach($records as $type) {
$typename = $type->type;
$visible = $type->visible;
$sortorder = $type->sortorder;
$types[] = new repository_type($typename, (array)get_config($typename), $visible, $sortorder);
$types[] = new repository_type($type->type, (array)get_config($type->type), $type->visible, $type->sortorder);
}
}

Expand Down Expand Up @@ -864,29 +868,31 @@ class repository_exception extends moodle_exception {
* @global object $USER
* @param object $context
* @param integer $userid
* @param boolean $visible if visible == true, return visible instances only,
* @param boolean $onlyvisible if visible == true, return visible instances only,
* otherwise, return all instances
* @param string $type a type name to retrieve
* @return array repository instances
*/
function repository_get_instances($context, $userid = null, $visible = true, $type=null){
function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null){
global $DB, $CFG, $USER;
$params = array();
$sql = 'SELECT i.*, r.type AS repositorytype, r.visible FROM {repository} r, {repository_instances} i WHERE ';
$sql .= 'i.typeid = r.id AND ';
$sql .= 'i.typeid = r.id ';
if (!empty($userid) && is_numeric($userid)) {
$sql .= ' (i.userid = 0 or i.userid = ?) AND ';
$sql .= ' AND (i.userid = 0 or i.userid = ?)';
$params[] = $userid;
}
if($context->id == SYSCONTEXTID) {
$sql .= ' (i.contextid = ?)';
$params[] = SYSCONTEXTID;
} else {
$sql .= ' (i.contextid = ? or i.contextid = ?)';
$params[] = SYSCONTEXTID;
$params[] = $context->id;
if (!empty($context)){
if($context->id == SYSCONTEXTID) {
$sql .= ' AND (i.contextid = ?)';
$params[] = SYSCONTEXTID;
} else {
$sql .= ' AND (i.contextid = ? or i.contextid = ?)';
$params[] = SYSCONTEXTID;
$params[] = $context->id;
}
}
if($visible == true) {
if($onlyvisible == true) {
$sql .= ' AND (r.visible = 1)';
}
if(isset($type)) {
Expand Down Expand Up @@ -1878,7 +1884,7 @@ public function definition() {
}
$this->set_data($data);
}
$this->add_action_buttons(true, get_string('submit'));
$this->add_action_buttons(true, get_string('save','repository'));
}

/**
Expand Down Expand Up @@ -1960,7 +1966,7 @@ public function definition() {
$this->set_data($data);
}

$this->add_action_buttons(true, get_string('submit'));
$this->add_action_buttons(true, get_string('save','repository'));
}

}
Expand Down Expand Up @@ -2032,7 +2038,7 @@ function repository_display_instances_list($context, $admin = false, $typename =
//create a unique type of instance
else {
if (repository_static_function($typename, 'has_multiple_instances')){
$addable = 1;
$addable = 1;
$instancehtml .= '<li><a href="'.$baseurl.'&amp;new='.$typename.'">'.get_string('create', 'repository')
.' "'.get_string('repositoryname', 'repository_'.$typename).'" '
.get_string('instance', 'repository').'</a></li>';
Expand Down

0 comments on commit 46dd6bb

Please sign in to comment.