:::

9-4-2-2 class\Tad_signup_api.php 套用語系

您沒有觀看影片的權限

您沒有觀看影片的權限

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

<?php
namespace XoopsModules\Tad_signup;

use XoopsModules\Tadtools\SimpleRest;
use XoopsModules\Tad_signup\Tad_signup_actions;
use XoopsModules\Tad_signup\Tad_signup_data;

require dirname(dirname(dirname(__DIR__))) . '/mainfile.php';

class Tad_signup_api extends SimpleRest
{
    public $uid = '';
    public $user = [];
    public $groups = [];
    private $token = '';

    public function __construct($token = '')
    {
        $this->token = $token;
        if (!isset($_SESSION['api_mode'])) {
            $_SESSION['api_mode'] = true;
        }

        if ($this->token) {
            $User = $this->getXoopsSUser($this->token);
            $this->uid = (int) $User['uid'];
            $this->groups = $User['groups'];
            $this->user = $User['user'];

            //判斷是否對該模組有管理權限 $_SESSION['tad_signup_adm']
            if (!isset($this->user['tad_signup_adm'])) {
                $this->user['tad_signup_adm'] = $_SESSION['tad_signup_adm'] = ($this->uid) ? $this->isAdmin('tad_signup') : false;
            }

            // 判斷有無開設活動的權限
            if (!isset($this->user['can_add'])) {
                $_SESSION['can_add'] = $this->user['can_add'] = $this->powerChk('tad_signup', '1');
            }

        }
    }

    // 傳回目前使用者資訊
    public function user()
    {
        $data = ['uid' => (int) $this->uid, 'groups' => $this->groups, 'user' => $this->user];
        return $this->encodeJson($data);
    }

    // 轉成 json
    private function encodeJson($responseData)
    {
        if (empty($responseData)) {
            $statusCode = 404;
            $responseData = array('error' => _TAD_EMPTY);
        } else {
            $statusCode = 200;
        }
        $this->setHttpHeaders($statusCode);

        $jsonResponse = json_encode($responseData, 256);
        return $jsonResponse;
    }

    // 取得所有活動
    public function tad_signup_actions_index($only_enable = true)
    {
        $actions = Tad_signup_actions::get_all($only_enable);
        return $this->encodeJson($actions);
    }

    // 取得活動所有報名資料
    public function tad_signup_data_index($action_id)
    {
        $action = Tad_signup_actions::get($action_id);
        $data = ($this->user['tad_signup_adm'] || ($this->user['can_add'] && $action['uid'] == $this->uid)) ? Tad_signup_data::get_all($action_id) : [];
        return $this->encodeJson($data);
    }

}

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


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp22.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1806%26tbsn%3D48

書籍目錄

展開 | 闔起

線上使用者

375人線上 (149人在瀏覽線上書籍)

會員: 0

訪客: 375

更多…