:::

8-2-3 將報名欄位做成類別方法

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. 由於重複許多次,所以可以獨立成一個方法,在 class\Tad_signup_data.php 加入 get_head() 方法
    //取得報名的標題欄
    public static function get_head($action, $return_type = false, $only_tdc = false)
    {
        $head_row = explode("\n", $action['setup']);
        $head = $type = [];
        foreach ($head_row as $head_data) {
            $cols = explode(',', $head_data);
            if (strpos($cols[0], '#') === false) {
                $head[] = str_replace('*', '', trim($cols[0]));
                $type[] = trim($cols[1]);
            }
        }
    
        if (!$only_tdc) {
            $head[] = '錄取';
            $head[] = '報名日期';
            $head[] = '身份';
        }
    
        if ($return_type) {
            return [$head, $type];
        } else {
            return $head;
        }
    }

     

  2. 修改 csv.php
    /*--略--*/
    $csv = [];
    $head = Tad_signup_data::get_head($action);
    $csv[] = implode(',', $head);
    /*--略--*/

     

  3. 修改 excel.php
    /*--略--*/
    // 抓出標題資料
    $head = Tad_signup_data::get_head($action);
    $row = 1;
    /*--略--*/

     

  4. 修改 pdf.php
    /*--略--*/
    $html[] = "<h1>{$title}報名名單</h1>";
    $html[] = '<table border="1" cellpadding="3">';
    
    $head = Tad_signup_data::get_head($action);
    
    $html[] = "<tr><th>" . implode("</th><th>", $head) . "</th></tr>";
    /*--略--*/

     

  5. 修改 class\Tad_signup_data.php 中的:
    // 預覽 CSV
    public static function preview_csv($action_id)
    {
        /*--略--*/
        $xoopsTpl->assign('action', $action);
    
        // 製作標題
        list($head, $type) = self::get_head($action, true, true);
        $xoopsTpl->assign('head', $head);
        $xoopsTpl->assign('type', $type);
    
        /*--略--*/
    }

    // 預覽 Excel
    public static function preview_excel($action_id)
    {
        /*--略--*/
        $xoopsTpl->assign('action', $action);
    
        // 製作標題
        list($head, $type) = self::get_head($action, true, true);
    
        $xoopsTpl->assign('head', $head);
        $xoopsTpl->assign('type', $type);
        /*--略--*/
    }

     

link to https://github.com/tadlearn/tad_signup/commit/1098ab0fb4f131c0d3c16ff99ba496ad6b8d9752 \


:::

搜尋

QR Code 區塊

https%3A%2F%2Fwww.tad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D48%26tbdsn%3D1776

書籍目錄

展開 | 闔起

線上使用者

65人線上 (15人在瀏覽線上書籍)

會員: 0

訪客: 65

更多…