Пример #1
0
/** 
 *  creates new template items.
 *  all items will be copied and the attribute feedback will be set to 0
 *  and the attribute template will be set to the new templateid
 *  @param object $feedback
 *  @param string $name the name of template shown in the templatelist
 *  @param int $ispublic 0:privat 1:public
 *  @return boolean
 */
function feedback_save_as_template($feedback, $name, $ispublic = 0)
{
    $feedbackitems = get_records('feedback_item', 'feedback', $feedback->id);
    if (!is_array($feedbackitems)) {
        return false;
    }
    if (!($newtempl = feedback_create_template($feedback->course, $name, $ispublic))) {
        return false;
    }
    //create items of this new template
    foreach ($feedbackitems as $item) {
        $item->id = '';
        $item->feedback = 0;
        $item->template = $newtempl;
        $item->name = addslashes($item->name);
        $item->presentation = addslashes($item->presentation);
        insert_record('feedback_item', $item);
    }
    return true;
}
Пример #2
0
/**
 * creates new template items.
 * all items will be copied and the attribute feedback will be set to 0
 * and the attribute template will be set to the new templateid
 *
 * @global object
 * @uses CONTEXT_MODULE
 * @uses CONTEXT_COURSE
 * @param object $feedback
 * @param string $name the name of template shown in the templatelist
 * @param int $ispublic 0:privat 1:public
 * @return boolean
 */
function feedback_save_as_template($feedback, $name, $ispublic = 0) {
    global $DB;
    $fs = get_file_storage();

    if (!$feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$feedback->id))) {
        return false;
    }

    if (!$newtempl = feedback_create_template($feedback->course, $name, $ispublic)) {
        return false;
    }

    //files in the template_item are in the context of the current course or
    //if the template is public the files are in the system context
    //files in the feedback_item are in the feedback_context of the feedback
    if ($ispublic) {
        $s_context = get_system_context();
    } else {
        $s_context = get_context_instance(CONTEXT_COURSE, $newtempl->course);
    }
    $cm = get_coursemodule_from_instance('feedback', $feedback->id);
    $f_context = get_context_instance(CONTEXT_MODULE, $cm->id);

    //create items of this new template
    //depend items we are storing temporary in an mapping list array(new id => dependitem)
    //we also store a mapping of all items array(oldid => newid)
    $dependitemsmap = array();
    $itembackup = array();
    foreach ($feedbackitems as $item) {

        $t_item = clone($item);

        unset($t_item->id);
        $t_item->feedback = 0;
        $t_item->template     = $newtempl->id;
        $t_item->id = $DB->insert_record('feedback_item', $t_item);
        //copy all included files to the feedback_template filearea
        $itemfiles = $fs->get_area_files($f_context->id,
                                    'mod_feedback',
                                    'item',
                                    $item->id,
                                    "id",
                                    false);
        if ($itemfiles) {
            foreach ($itemfiles as $ifile) {
                $file_record = new stdClass();
                $file_record->contextid = $s_context->id;
                $file_record->component = 'mod_feedback';
                $file_record->filearea = 'template';
                $file_record->itemid = $t_item->id;
                $fs->create_file_from_storedfile($file_record, $ifile);
            }
        }

        $itembackup[$item->id] = $t_item->id;
        if ($t_item->dependitem) {
            $dependitemsmap[$t_item->id] = $t_item->dependitem;
        }

    }

    //remapping the dependency
    foreach ($dependitemsmap as $key => $dependitem) {
        $newitem = $DB->get_record('feedback_item', array('id'=>$key));
        $newitem->dependitem = $itembackup[$newitem->dependitem];
        $DB->update_record('feedback_item', $newitem);
    }

    return true;
}
Пример #3
0
/**
 * creates new template items.
 * all items will be copied and the attribute feedback will be set to 0
 * and the attribute template will be set to the new templateid
 *
 * @global object
 * @param object $feedback
 * @param string $name the name of template shown in the templatelist
 * @param int $ispublic 0:privat 1:public
 * @return boolean
 */
function feedback_save_as_template($feedback, $name, $ispublic = 0)
{
    global $DB;
    if (!($feedbackitems = $DB->get_records('feedback_item', array('feedback' => $feedback->id)))) {
        return false;
    }
    if (!($newtempl = feedback_create_template($feedback->course, $name, $ispublic))) {
        return false;
    }
    //create items of this new template
    foreach ($feedbackitems as $item) {
        unset($item->id);
        $item->feedback = 0;
        $item->template = $newtempl;
        $DB->insert_record('feedback_item', $nitem);
    }
    return true;
}