class\Tad_signup_data.php
的 get_all()
,使之可以選擇是否只抓取已錄取者,並可自行設定需之要欄位。 影片中資料庫大小寫不正確,一律改為小寫 prefix("tad_signup_data")
//取得所有資料陣列
public static function get_all($action_id = '', $uid = '', $auto_key = false, $only_accept = false)
{
global $xoopsDB, $xoopsUser;
$and_accept = $only_accept ? "and `accept`='1'" : '';
if ($action_id) {
$sql = "select * from `" . $xoopsDB->prefix("tad_signup_data") . "` where `action_id`='$action_id' $and_accept order by `signup_date`";
} else {
if (!$_SESSION['can_add'] or !$uid) {
$uid = $xoopsUser ? $xoopsUser->uid() : 0;
}
$sql = "select * from `" . $xoopsDB->prefix("tad_signup_data") . "` where `uid`='$uid' $and_accept order by `signup_date`";
}
/*--略--*/
return $data_arr;
}
pdf_signup.php
:
<?php
use Xmf\Request;
use XoopsModules\Tad_signup\Tad_signup_actions;
use XoopsModules\Tad_signup\Tad_signup_data;
/*-----------引入檔案區--------------*/
require_once __DIR__ . '/header.php';
if (!$_SESSION['can_add']) {
redirect_header($_SERVER['PHP_SELF'], 3, "您沒有權限使用此功能");
}
$id = Request::getInt('id');
$action = Tad_signup_actions::get($id);
require_once XOOPS_ROOT_PATH . '/modules/tadtools/tcpdf/tcpdf.php';
$pdf = new TCPDF("P", "mm", "A4", true, 'UTF-8', false);
$pdf->setPrintHeader(false); //不要頁首
$pdf->setPrintFooter(false); //不要頁尾
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); //設定自動分頁
$pdf->setFontSubsetting(true); //產生字型子集(有用到的字才放到文件中)
$pdf->SetFont('droidsansfallback', '', 11, '', true); //設定字型
$pdf->SetMargins(15, 15); //設定頁面邊界,
$pdf->AddPage(); //新增頁面,一定要有,否則內容出不來
$title = "{$action['title']}簽到表";
$pdf->SetFont('droidsansfallback', 'B', 24, '', true); //設定字型
$pdf->MultiCell(190, 0, $title, 0, "C");
$pdf->SetFont('droidsansfallback', '', 16, '', true); //設定字型
$pdf->Cell(40, 20, '活動日期:', 0, 0);
$pdf->Cell(150, 20, $action['action_date'], 0, 1);
// $pdf->MultiCell( $w, $h, $txt, $border = 0, $align = 'J', $fill = false, $ln = 1, $x = '', $y = '', $reseth = true, $stretch = 0, $ishtml = false, $autopadding = true, $maxh = 0, $valign = 'T', $fitcell = false );
// $pdf->Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = nil, $stretch = 0, $ignore_min_height = false, $calign = 'T', $valign = 'M')
$h = 15;
$maxh = 15;
$pdf->Cell(15, $h, '編號', 1, 0, 'C');
$pdf->Cell(40, $h, '姓名', 1, 0, 'C');
$pdf->Cell(35, $h, '飲食', 1, 0, 'C');
$pdf->Cell(100, $h, '簽名', 1, 1, 'C');
$signup = Tad_signup_data::get_all($action['id'], null, true, true);
// Utility::dd($signup);
$i = 1;
foreach ($signup as $signup_data) {
$pdf->MultiCell(15, $h, $i, 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
$pdf->MultiCell(40, $h, implode('、', $signup_data['tdc']['姓名']), 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
$pdf->MultiCell(35, $h, implode('、', $signup_data['tdc']['飲食']), 1, 'C', false, 0, '', '', true, 0, false, true, $maxh, 'M');
$pdf->MultiCell(100, $h, '', 1, 'C', false, 1, '', '', true, 0, false, true, $maxh, 'M');
$i++;
}
$pdf->Output("{$title}.pdf", 'I');
link to https://github.com/tadlearn/tad_signup/commit/ed18e4f19acc8ae0012205efb13e4f0fffff3266 \