:::

4-2-1 在活動列表顯示報名人數

您沒有觀看影片的權限

您沒有觀看影片的權限

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

  1. 活動列表的顯示是跑 index.php 的這個流程
    Tad_signup_actions::index();
    $op = 'tad_signup_actions_index';

     

  2. 換言之,要加入已報名人數,就應該在 class\Tad_signup_actions.phpindex() 中加入已報名人數
    //列出所有資料
    public static function index()
    {
        global $xoopsTpl;
    
        $all_data = self::get_all();
        $xoopsTpl->assign('all_data', $all_data);
    }
    

     

  3. index() 的資料來源又源自 get_all(),所以我們在 get_all()中動手腳即可,我們直接利用 Tad_signup_data::get_all($data['id']) 取得所有該活動的報名資料。
    //取得所有資料陣列
    public static function get_all($only_enable = true, $auto_key = false)
    {
        global $xoopsDB;
        /*--- 略 ---*/
        while ($data = $xoopsDB->fetchArray($result)) {
    
            $data['title'] = $myts->htmlSpecialChars($data['title']);
            $data['detail'] = $myts->displayTarea($data['detail'], 0, 1, 0, 1, 1);
            $data['setup'] = $myts->displayTarea($data['setup'], 0, 1, 0, 1, 1);
            $data['signup'] = Tad_signup_data::get_all($data['id']);
    
        /*--- 略 ---*/
        }
        return $data_arr;
    }

     

  4. 接著,只要在樣板動點手腳就可以了。
    <{foreach from=$all_data key=k item=action name=all_data}>
        <tr>
            <td><a href="index.php?id=<{$action.id}>"><{$action.title}></a></td>
            <td><{$action.action_date}></td>
            <td><{$action.end_date}></td>
            <td><{$action.signup|@count}>/<{$action.number}></td>
            <td>
                <{if $smarty.session.tad_signup_adm}>
                    <a href="index.php?op=tad_signup_actions_edit&id=<{$action.id}>" class="btn btn-warning btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> 編輯活動</a>
                <{/if}>
    
                <{if $action.number > $action.signup|@count && $xoops_isuser && $action.end_date|strtotime >= $smarty.now}>
                    <a href="index.php?op=tad_signup_data_create&action_id=<{$action.id}>" class="btn btn-info btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> 立即報名</a>
                <{/if}>
            </td>
        </tr>
    <{/foreach}>

     

  5. <{$action.signup|@count}> 表示要將 $action.signup 當參數,丟入PHP的 count() 中,@ 符號指的是直接套用於整個陣列,而非裡面的單一元素。
  6. 當然,在PHP也要真的去計算是否人數已滿才行,故,修改 class\Tad_signup_data.php 中的 create()。影片中沒提到,要記得加入 $action['signup'] = Tad_signup_data::get_all($action_id);
    //編輯表單
    public static function create($action_id, $id = '')
    {
        global $xoopsTpl, $xoopsUser;
    
        /*---略---*/
    
        $action = Tad_signup_actions::get($action_id);
        $action['signup'] = Tad_signup_data::get_all($action_id);
        if (time() > strtotime($action['end_date'])) {
            redirect_header($_SERVER['PHP_SELF'] . "?id=$action_id", 3, "已報名截止,無法再進行報名或修改報名");
        } elseif (count($action['signup']) >= $action['number']) {
            redirect_header($_SERVER['PHP_SELF'] . "?id=$action_id", 3, "人數已滿,無法再進行報名");
        }
    
        /*---略---*/
    }

     

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


:::

搜尋

QR Code 區塊

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

書籍目錄

展開 | 闔起

線上使用者

46人線上 (7人在瀏覽線上書籍)

會員: 0

訪客: 46

更多…