:::

9-1-3 用 API 取得所有活動

您沒有觀看影片的權限

您沒有觀看影片的權限

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

  1. 在 app_api.php 加入對應流程,如:
    // 取得報名活動
    case 'tad_signup_actions_index':
        echo $api->tad_signup_actions_index($xoopsModuleConfig['only_enable']);
        break;

     

  2. class\Tad_signup_api.php 加入相對應方法,如:
    // 取得所有活動
    public function tad_signup_actions_index($only_enable = true)
    {
        $actions = Tad_signup_actions::get_all($only_enable);
        return $this->encodeJson($actions);
    }

    最上方記得加入

    use XoopsModules\Tad_signup\Tad_signup_actions;

     

  3. 編輯 class\Tad_signup_actions.phpget_all(),在api模式不跑分頁,此外,將報名名單直接算出人數,避免從api直接顯示出詳細個資。
    //取得所有資料陣列
    public static function get_all($only_enable = true, $auto_key = false, $show_number = 0, $order = ", `action_date` desc")
    {
        global $xoopsDB, $xoopsModuleConfig, $xoopsTpl;
        $myts = \MyTextSanitizer::getInstance();
    
        $and_enable = $only_enable ? "and `enable` = '1' and `end_date` >= now() " : '';
    
        $limit = $show_number ? "limit 0, $show_number" : '';
        $sql = "select * from `" . $xoopsDB->prefix("tad_signup_actions") . "` where 1 $and_enable order by `enable` $order $limit";
    
        if (!$show_number && !$_SESSION['api_mode']) {
            //Utility::getPageBar($原sql語法, 每頁顯示幾筆資料, 最多顯示幾個頁數選項);
            $PageBar = Utility::getPageBar($sql, $xoopsModuleConfig['show_number'], 10);
            $bar = $PageBar['bar'];
            $sql = $PageBar['sql'];
            $total = $PageBar['total'];
            $xoopsTpl->assign('bar', $bar);
            $xoopsTpl->assign('total', $total);
        }
    
        $result = $xoopsDB->query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
        $data_arr = [];
        while ($data = $xoopsDB->fetchArray($result)) {
            $data['title'] = $myts->htmlSpecialChars($data['title']);
            $data['detail'] = $myts->displayTarea($data['detail'], 1, 0, 0, 0, 0);
            $data['signup_count'] = count(Tad_signup_data::get_all($data['id']));
    
            if ($_SESSION['api_mode'] or $auto_key) {
                $data_arr[] = $data;
            } else {
                $data_arr[$data['id']] = $data;
            }
        }
        return $data_arr;
    }

     

  4. 將所有 ['signup'] 取代為 ['signup_count'] .signup|@count 取代為 .signup_count 即可,如:
    <i class='fa fa-users' aria-hidden='true'></i> 報名狀況:" . $action['signup_count'] . "/{$action['number']}
    <span data-toggle='tooltip' title='可候補人數'>({$action['candidate']})</span>
    <{if $action.enable && ($action.number + $action.candidate) > $action.signup_count && $action.end_date|strtotime >= $smarty.now}>

     

  5. 詳細異動部份,請點下方按鈕,至GitHub觀看喔~

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


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1762%26tbsn%3D48

書籍目錄

展開 | 闔起

線上使用者

54人線上 (10人在瀏覽線上書籍)

會員: 0

訪客: 54

更多…