call() абстрактный публичный Метод

first function used on api call
abstract public call ( )
Пример #1
0
 public function call($name, $params)
 {
     $output = false;
     // Loads user information according to the external user data provided:
     $params = $this->fillParamsFrom($params, $_POST);
     $params = $this->checkExternalUser($params, $_POST);
     if (!empty($params[0]) && !isset($params['idst'])) {
         $params['idst'] = $params[0];
         //params[0] should contain user idst
     }
     switch ($name) {
         case 'listCourses':
         case 'courses':
             $output = $this->getCourses($params);
             break;
         case 'editions':
             $output = $this->getEditions($params);
             break;
         case 'classrooms':
             $output = $this->getClassrooms($params);
             break;
         case 'addUserSubscription':
         case 'addusersubscription':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->addUserSubscription($params);
             }
             break;
         case 'updateUserSubscription':
         case 'updateusersubscription':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->updateUserSubscription($params);
             }
             break;
         case 'deleteUserSubscription':
         case 'deleteusersubscription':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->deleteUserSubscription($params);
             }
             break;
         case 'subscribeUserWithCode':
         case 'subscribeuserwithcode':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->subscribeUserWithCode($params);
             }
             break;
         default:
             $output = parent::call($name, $params);
     }
     return $output;
 }
Пример #2
0
 public function call($name, $params)
 {
     $output = false;
     // Loads user information according to the external user data provided:
     $params = $this->checkExternalUser($params, $_POST);
     if (!empty($params[0]) && !isset($params['idst'])) {
         $params['idst'] = $params[0];
         //params[0] should contain user idst
     }
     if (empty($params['idst']) && !empty($_POST['idst'])) {
         $params['idst'] = (int) $_POST['idst'];
     }
     switch ($name) {
         case 'listUsers':
         case 'userslist':
             $list = $this->getUsersList();
             if ($list['success']) {
                 $output = array('success' => true, 'list' => $list['users_list']);
             } else {
                 $output = array('success' => false);
             }
             break;
         case 'userdetails':
             if (count($params) > 0 && !isset($params['ext_not_found'])) {
                 //params[0] should contain user id
                 if (is_numeric($params['idst'])) {
                     $res = $this->getUserDetails($params['idst']);
                     if (!$res) {
                         $output = array('success' => false, 'message' => "Error: unable to retrieve user details.");
                     } else {
                         $output = array('success' => true, 'details' => $res['details']);
                     }
                 } else {
                     $output = array('success' => false, 'message' => 'Invalid passed parameter.');
                 }
             } else {
                 $output = array('success' => false, 'message' => 'No parameter provided.');
             }
             break;
         case 'customfields':
             $tmp_lang = false;
             //if not specified, use default language
             if (isset($params['language'])) {
                 $tmp_lang = $params['language'];
             }
             //check if a language has been specified
             $res = $this->getCustomFields($tmp_lang);
             if ($res != false) {
                 $output = array('success' => true, 'custom_fields' => $res);
             } else {
                 $output = array('success' => false, 'message' => 'Error: unable to retrieve custom fields.');
             }
             break;
         case 'create':
         case 'createuser':
             $res = $this->createUser($params, $_POST);
             if (is_array($res)) {
                 $output = $res;
             } else {
                 if ($res > 0) {
                     $output = array('success' => true, 'idst' => $res);
                 } else {
                     $output = array('success' => false, 'message' => 'Error: unable to create new user.');
                 }
             }
             break;
         case 'edit':
         case 'updateuser':
             if (count($params) > 0 && !isset($params['ext_not_found'])) {
                 //params[0] should contain user id
                 $res = $this->updateUser($params['idst'], $_POST);
                 if ($res > 0) {
                     $output = array('success' => true);
                 } elseif ($res < 0) {
                     $output = array('success' => false, 'message' => 'Error: incorrect param idst.');
                 }
             } else {
                 $output = array('success' => false, 'message' => 'Error: user id to update has not been specified.');
             }
             break;
         case 'delete':
         case 'deleteuser':
             if (count($params) > 0 && !isset($params['ext_not_found'])) {
                 //params[0] should contain user id
                 $output = $this->deleteUser($params['idst'], $_POST);
             } else {
                 $output = array('success' => false, 'message' => 'Error: user id to update has not been specified.');
             }
             break;
         case 'userdetailsbyuserid':
             $acl_man = new DoceboACLManager();
             $idst = $acl_man->getUserST($params['userid']);
             if (!$idst) {
                 $output = array('success' => false, 'message' => 'Error: invalid userid: ' . $params['userid'] . '.');
             } else {
                 $output = $this->getUserDetails($idst);
             }
             break;
         case 'userdetailsfromcredentials':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->getUserDetailsFromCredentials($_POST);
             }
             break;
         case 'updateuserbyuserid':
             if (count($params) > 0) {
                 //params[0] should contain user id
                 $acl_man = new DoceboACLManager();
                 $idst = $acl_man->getUserST($params['userid']);
                 if (!$idst) {
                     $output = array('success' => false, 'message' => 'Error: invalid userid: ' . $params['userid'] . '.');
                 } else {
                     $res = $this->updateUser($idst, $_POST);
                     $output = array('success' => true);
                 }
             } else {
                 $output = array('success' => false, 'message' => 'Error: user id to update has not been specified.');
             }
             break;
         case 'userCourses':
         case 'mycourses':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->getMyCourses($params['idst'], $_POST);
             }
             break;
         case 'kbsearch':
             if (!isset($params['ext_not_found'])) {
                 $output = $this->KbSearch($params['idst'], $_POST);
             }
             break;
         case 'importextusers':
             $output = $this->importExternalUsers($_POST);
             break;
         case 'importextusersfromemail':
             $output = $this->importExternalUsersFromEmail($_POST);
             break;
         case 'countusers':
             $output = $this->countUsers($_POST);
             break;
         case 'checkregcode':
             $output = $this->checkRegistrationCode($_POST);
             break;
         case 'checkUsername':
         case 'checkusername':
             $output = $this->checkUsername($_POST);
             break;
         default:
             $output = parent::call($name, $_POST);
     }
     return $output;
 }
Пример #3
0
 public function call($name, $params)
 {
     $output = false;
     switch ($name) {
         case 'createrole':
             $res = $this->createRole($_POST);
             if (is_array($res)) {
                 $output = $res;
             } else {
                 if ($res > 0) {
                     $output = array('success' => true, 'id_role' => $res);
                 } else {
                     $output = array('success' => false, 'message' => 'Error: unable to create new role.');
                 }
             }
             break;
         case 'creategroup':
             $res = $this->creategroup($_POST);
             if (is_array($res)) {
                 $output = $res;
             } else {
                 if ($res > 0) {
                     $output = array('success' => true, 'id_group' => $res);
                 } else {
                     $output = array('success' => false, 'message' => 'Error: unable to create new role group.');
                 }
             }
             break;
         case 'deleterole':
             $res = $this->deleteRole($_POST);
             if (is_array($res)) {
                 $output = $res;
             } else {
                 if ($res > 0) {
                     $output = array('success' => true, 'deleted' => $res);
                 } else {
                     $output = array('success' => false, 'message' => 'Error: unable to delete role.');
                 }
             }
             break;
         case 'deletegroup':
             $res = $this->deleteGroup($_POST);
             if (is_array($res)) {
                 $output = $res;
             } else {
                 if ($res > 0) {
                     $output = array('success' => true, 'deleted' => $res);
                 } else {
                     $output = array('success' => false, 'message' => 'Error: unable to delete role group.');
                 }
             }
             break;
         case 'getroles':
             $res = $this->getFunctionalRolesList($_GET);
             if (is_array($res)) {
                 $output = array('success' => true, 'roles' => $res);
             } else {
                 $output = array('success' => false, 'message' => 'Error: unable to get list roles.');
             }
             break;
         case 'getrolegroups':
             $res = $this->getRoleGroups($_GET);
             if (is_array($res)) {
                 $output = array('success' => true, 'groups' => $res);
             } else {
                 $output = array('success' => false, 'message' => 'Error: unable to get list groups.');
             }
             break;
         case 'adduser':
             $res = $this->addUser($_POST);
             if (is_array($res)) {
                 $output = $res;
             } else {
                 if ($res > 0) {
                     $output = array('success' => true, 'result' => $res);
                 } else {
                     $output = array('success' => false, 'message' => 'Error: unable to add user to fncrole.');
                 }
             }
             break;
         default:
             $output = parent::call($name, $_POST);
     }
     return $output;
 }
Пример #4
0
    public static $sso = 'your_toekn_from_api_app';
    public static function getHash($params)
    {
        $res = array('sha1' => '', 'x_auth' => '');
        $res['sha1'] = sha1(implode(',', $params) . ',' . self::$secret_key);
        $res['x_auth'] = base64_encode(self::$key . ':' . $res['sha1']);
        echo $res['x_auth'];
        return $res;
    }
    private static function getDefaultHeader($x_auth)
    {
        return array("Host: " . self::$url, "Content-Type: multipart/form-data", 'X-Authorization: Docebo ' . $x_auth);
    }
    public static function call($action, $data_params)
    {
        $curl = curl_init();
        $hash_info = self::getHash($data_params);
        $http_header = self::getDefaultHeader($hash_info['x_auth']);
        $opt = array(CURLOPT_URL => self::$url . '/api/' . $action, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => $http_header, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data_params, CURLOPT_CONNECTTIMEOUT => 5);
        curl_setopt_array($curl, $opt);
        // $output contains the output string
        $output = curl_exec($curl);
        // it closes the session
        curl_close($curl);
        echo $output;
        return $output;
    }
}
// sample call
$res = API::call('user/profile', array('id_user' => '13258'));