Exemple #1
0
 /**
  * save once telegram user details
  * @param  [type] $_telegram_id [description]
  * @param  [type] $_fromDetail  [description]
  * @return [type]               [description]
  */
 private static function catchTelegramUser($_telegram_id, $_fromDetail = null)
 {
     // if user_id is not set try to give user_id from database
     // search in db to find user_id
     $qry = "SELECT `user_id`\n\t\t\tFROM options\n\t\t\tWHERE\n\t\t\t\t`option_cat` LIKE 'telegram\\_%' AND\n\t\t\t\t`option_key` LIKE 'user\\_%' AND\n\t\t\t\t`option_value` = {$_telegram_id}\n\t\t";
     $my_user_id = \lib\db::get($qry, 'user_id', true);
     if (is_numeric($my_user_id)) {
         self::$user_id = $my_user_id;
     }
     // if user does not exist in db, signup it
     if (!self::$user_id) {
         // calc full_name of user
         $fullName = trim(self::response('from', 'first_name') . ' ' . self::response('from', 'last_name'));
         $mobile = 'tg_' . $_telegram_id;
         // generate password
         $password = \lib\utility\filter::temp_password();
         \lib\db\users::signup($mobile, $password, true, $fullName);
         self::$user_id = \lib\db\users::$user_id;
         // save telegram user detail like name and username into options
         $userDetail = ['cat' => 'telegram_' . self::$user_id, 'key' => 'user_' . self::response('from', 'username'), 'value' => $_telegram_id, 'meta' => $_fromDetail];
         if (isset(self::$user_id)) {
             $userDetail['user'] = self::$user_id;
             $userDetail['status'] = 'enable';
         } else {
             $userDetail['status'] = 'disable';
         }
         // save in options table
         \lib\utility\option::set($userDetail, true);
     }
     // save session id database only one time
     // if exist use old one else insert new one to database
     \lib\utility\session::save_once(self::$user_id, 'telegram_' . $_telegram_id);
     if (!array_key_exists('tg', $_SESSION) || !is_array($_SESSION['tg'])) {
         $_SESSION['tg'] = array();
     }
     if (self::$user_id) {
         return true;
     }
     return false;
 }
Exemple #2
0
 /**
  * try the sarshomar
  * generate mobile and password and register the Guset Session
  */
 public static function signup_inspection()
 {
     $displayname = "Guest Session";
     $mobile = \lib\utility\filter::temp_mobile();
     $password = \lib\utility\filter::temp_password();
     $user_id = self::signup($mobile, $password, true, $displayname);
     return $user_id;
 }