:::

4-6-2 讓活動的 get() 可以根據情況過濾

您沒有觀看影片的權限

您沒有觀看影片的權限

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

  1. 在我們用 Tad_signup_actions::get() 活動時,都要自己做一次過濾,難道不能先過濾嗎?可以,但是用來修改時不行,顯示時可以,要做到彈性控制,我們多個參數即可
  2. 修改 class\Tad_signup_actions.php 中的 get(),並加入第二個參數,一般預設值都是以不改變現狀為準(或者最常用設定)影片中有做 $data['setup'] 的過濾,但實際上別做,會出問題
    //以流水號取得某筆資料
    public static function get($id = '', $filter = false)
    {
        global $xoopsDB;
    
        if (empty($id)) {
            return;
        }
    
        $sql = "select * from `" . $xoopsDB->prefix("tad_signup_actions") . "`
        where `id` = '{$id}'";
        $result = $xoopsDB->query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
        $data = $xoopsDB->fetchArray($result);
        if ($filter) {
            $myts = \MyTextSanitizer::getInstance();
            $data['detail'] = $myts->displayTarea($data['detail'], 0, 1, 0, 1, 1);
            $data['title'] = $myts->htmlSpecialChars($data['title']);
        }
        return $data;
    }
  3. 搜尋其他地方有用到 Tad_signup_actions::get() 的,一一檢視是否需要修改,例如 class\Tad_signup_actions.php 中的 show(),就不再需要用迴圈過濾
    //以流水號秀出某筆資料內容
    public static function show($id = '')
    {
        global $xoopsDB, $xoopsTpl, $xoopsUser;
    
        if (empty($id)) {
            return;
        }
    
        $id = (int) $id;
        $data = self::get($id, true);
    
        foreach ($data as $col_name => $col_val) {
            $xoopsTpl->assign($col_name, $col_val);
        }
    
        /*---略---*/
    }

     

  4. 還有 class\Tad_signup_data.phpcreate()
    //編輯表單
    public static function create($action_id, $id = '')
    {
        global $xoopsTpl, $xoopsUser;
    
        /*---略---*/
        $action = Tad_signup_actions::get($action_id, true);
        $action['signup'] = Tad_signup_data::get_all($action_id);
        if (time() > strtotime($action['end_date'])) {
            redirect_header($_SERVER['PHP_SELF'], 3, "已報名截止,無法再進行報名或修改報名");
        } elseif (count($action['signup']) >= $action['number']) {
            redirect_header($_SERVER['PHP_SELF'], 3, "人數已滿,無法再進行報名");
        }
        $xoopsTpl->assign('action', $action);
        /*---略---*/
    }

     

  5. 還有 class\Tad_signup_data.phpshow()
    //以流水號秀出某筆資料內容
    public static function show($id = '')
    {
        global $xoopsDB, $xoopsTpl, $xoopsUser;
    
        /*---略---*/
    
        $action = Tad_signup_actions::get($action_id, true);
        $xoopsTpl->assign('action', $action);
    
        /*---略---*/
    }

     

  6. 以及 class\Tad_signup_data.phpget_all() 這部份錄影時忘了做,請務必加上
    //取得所有資料陣列
    public static function get_all($action_id, $uid = '', $auto_key = false)
    {
        global $xoopsDB, $xoopsUser;
        /*---略---*/
        while ($data = $xoopsDB->fetchArray($result)) {
            $TadDataCenter->set_col('id', $data['id']);
            $data['tdc'] = $TadDataCenter->getData();
            $data['action'] = Tad_signup_actions::get($data['action_id'], true);
    
            /*---略---*/
        }
        return $data_arr;
    }

     

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


:::

搜尋

QR Code 區塊

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

書籍目錄

展開 | 闔起

線上使用者

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

會員: 0

訪客: 82

更多…