当前位置: 首页>>代码示例>>PHP>>正文


PHP assignment_pack_files函数代码示例

本文整理汇总了PHP中assignment_pack_files函数的典型用法代码示例。如果您正苦于以下问题:PHP assignment_pack_files函数的具体用法?PHP assignment_pack_files怎么用?PHP assignment_pack_files使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assignment_pack_files函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: download_submissions

 /**
  * creates a zip of all assignment submissions and sends a zip to the browser
  */
 public function download_submissions()
 {
     global $CFG, $DB;
     raise_memory_limit(MEMORY_EXTRA);
     $submissions = $this->get_submissions('', '');
     if (empty($submissions)) {
         print_error('errornosubmissions', 'assignment');
     }
     $filesforzipping = array();
     //NOTE: do not create any stuff in temp directories, we now support unicode file names and that would not work, sorry
     //online assignment can use html
     $filextn = ".html";
     $groupmode = groups_get_activity_groupmode($this->cm);
     $groupid = 0;
     // All users
     $groupname = '';
     if ($groupmode) {
         $groupid = groups_get_activity_group($this->cm, true);
         $groupname = groups_get_group_name($groupid) . '-';
     }
     $filename = str_replace(' ', '_', clean_filename($this->course->shortname . '-' . $this->assignment->name . '-' . $groupname . $this->assignment->id . ".zip"));
     //name of new zip file.
     foreach ($submissions as $submission) {
         $a_userid = $submission->userid;
         //get userid
         if (groups_is_member($groupid, $a_userid) or !$groupmode or !$groupid) {
             $a_assignid = $submission->assignment;
             //get name of this assignment for use in the file names.
             $a_user = $DB->get_record("user", array("id" => $a_userid), 'id,username,firstname,lastname');
             //get user firstname/lastname
             $submissioncontent = "<html><body>" . format_text($submission->data1, $submission->data2) . "</body></html>";
             //fetched from database
             //get file name.html
             $fileforzipname = clean_filename(fullname($a_user) . "_" . $a_userid . $filextn);
             $filesforzipping[$fileforzipname] = array($submissioncontent);
         }
     }
     //end of foreach
     if ($zipfile = assignment_pack_files($filesforzipping)) {
         send_temp_file($zipfile, $filename);
         //send file and delete after sending.
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:46,代码来源:assignment.class.php

示例2: download_submissions

    /**
     * creates a zip of all assignment submissions and sends a zip to the browser
     */
    public function download_submissions() {
        global $CFG,$DB;
        require_once($CFG->libdir.'/filelib.php');
        $submissions = $this->get_submissions('','');
        if (empty($submissions)) {
            print_error('errornosubmissions', 'assignment', new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id)));
        }
        $filesforzipping = array();
        $fs = get_file_storage();

        $groupmode = groups_get_activity_groupmode($this->cm);
        $groupid = 0;   // All users
        $groupname = '';
        if ($groupmode) {
            $groupid = groups_get_activity_group($this->cm, true);
            $groupname = groups_get_group_name($groupid).'-';
        }
        $filename = str_replace(' ', '_', clean_filename($this->course->shortname.'-'.$this->assignment->name.'-'.$groupname.$this->assignment->id.".zip")); //name of new zip file.
        foreach ($submissions as $submission) {
            // If assignment is open and submission is not finalized then don't add it to zip.
            $submissionstatus = $this->is_finalized($submission);
            if ($this->isopen() && empty($submissionstatus)) {
                continue;
            }
            $a_userid = $submission->userid; //get userid
            if ((groups_is_member($groupid,$a_userid)or !$groupmode or !$groupid)) {
                $a_assignid = $submission->assignment; //get name of this assignment for use in the file names.
                $a_user = $DB->get_record("user", array("id"=>$a_userid),'id,username,firstname,lastname'); //get user firstname/lastname

                $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false);
                foreach ($files as $file) {
                    //get files new name.
                    $fileext = strstr($file->get_filename(), '.');
                    $fileoriginal = str_replace($fileext, '', $file->get_filename());
                    $fileforzipname =  clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext);
                    //save file name to array for zipping.
                    $filesforzipping[$fileforzipname] = $file;
                }
            }
        } // end of foreach loop

        // Throw error if no files are added.
        if (empty($filesforzipping)) {
            print_error('errornosubmissions', 'assignment', new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id)));
        }

        if ($zipfile = assignment_pack_files($filesforzipping)) {
            send_temp_file($zipfile, $filename); //send file and delete after sending.
        }
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:53,代码来源:assignment.class.php


注:本文中的assignment_pack_files函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。