/**
  * 全部下载(学科)
  *
  * @return void
  */
 public function download_all_subject()
 {
     $rule_id = $this->input->post('rule_id');
     $uids = $this->input->post('uids');
     if (empty($rule_id) || empty($uids) || count($uids) <= 0) {
         message('参数错误,请重试!', 'student/teacher_download/report');
     }
     $zip_path_arr = array();
     foreach ($uids as $uid) {
         /* 查找zip文件 cache文件夹路径 + 考试期次ID + 考生ID*/
         $zip_path = $this->_get_cache_root_path() . "/zip/report/{$rule_id}/{$uid}.zip";
         if (!file_exists($zip_path)) {
             message('文件不存在,请重试!', 'student/teacher_download/report');
         }
         $zip_path_arr[$uid] = $zip_path;
     }
     /* 当前考试期次下所有学科 */
     $subjects_exam = array();
     $sql = "SELECT e.subject_id FROM {pre}exam AS e LEFT JOIN  {pre}evaluate_rule AS er  ON e.exam_pid=er.exam_pid WHERE er.id={$rule_id}";
     $subjects_tmp = $this->db->query($sql)->result_array();
     if (empty($subjects_tmp)) {
         message('当前考试期次下不存在学科!', 'student/teacher_download/report');
     }
     foreach ($subjects_tmp as $key => $value) {
         $subjects_exam[] = $value['subject_id'];
     }
     /* 当前用户可管理学科 */
     $teacher = $this->session->userdata('teacher');
     $subjects_teacher = json_decode($teacher['subjects'], true);
     /* 读取学科 */
     $subjects = C('subject');
     /* 加入总结报告 */
     $subjects[0] = '总结';
     $subjects_exam[] = 0;
     require_once APPPATH . 'libraries/Pclzip.php';
     $rst_diff = array_diff($subjects_teacher, $subjects_exam) || array_diff($subjects_exam, $subjects_teacher);
     /* 判断是否为所有学科 */
     if (empty($rst_diff)) {
         $save_path = $this->_get_cache_root_path() . "/zip/report/" . $rule_id . "/all.zip";
         $zip_all = new pclZip($save_path);
         $file_all_tmp = $zip_all->create(implode($zip_path_arr, ','), PCLZIP_OPT_REMOVE_PATH, $this->_get_cache_root_path() . "/zip/report/{$rule_id}");
         /* 打包所有zip */
         $this->download_file($save_path);
         /* 清除临时zip包 */
         @unlink($save_path);
     } else {
         /* 临时文件夹,存放解压文件 */
         $tmp_dir = $this->_get_cache_root_path() . "/zip/report/" . $rule_id . "/tmp";
         foreach ($zip_path_arr as $uid => $zip_path) {
             /* 解压zip */
             $archive = new PclZip($zip_path);
             $rst = $archive->extract(PCLZIP_OPT_PATH, $tmp_dir . '/' . $uid);
         }
         if ($rst == 0) {
             log_message('error', $archive->errorInfo(true));
             die("文件解压错误!");
         } else {
             $save_path = $this->_get_cache_root_path() . "/zip/report/{$rule_id}/all.zip";
             $file_tmp = array();
             foreach ($zip_path_arr as $uid => $zip_path) {
                 /* 选中所属学科,从新生成zip */
                 foreach ($subjects_teacher as $key => $value) {
                     if (!in_array($value, $subjects_exam) && $value > 0) {
                         continue;
                     }
                     $file_tmp[] = $tmp_dir . '/' . $uid . '/' . $subjects[$value] . '.pdf';
                 }
             }
             $zip = new PclZip($save_path);
             $file_tmp_zip = $zip->create(implode(',', $file_tmp), PCLZIP_OPT_REMOVE_PATH, $tmp_dir);
             /* 下载 */
             $this->download_file($save_path);
             /* 清除解压包 */
             $this->delete_dir($tmp_dir);
             /* 清除临时zip包 */
             @unlink($save_path);
         }
     }
 }
Beispiel #2
0
 public function first()
 {
     include "pclzip.lib.php";
     $backdir = $this->_dir . "/backup";
     $this->clean($backdir);
     $backname = "{$backdir}/Backup" . date("YmdHis") . ".zip";
     $zip = new pclZip($backname);
     $zip->create(__TYPECHO_ROOT_DIR__, PCLZIP_OPT_REMOVE_PATH, __TYPECHO_ROOT_DIR__);
     return $backname;
 }