/** * save session in options table * @return [type] [description] */ public static function save($_userid = true, $_meta = false, $_id = null) { $session_id = session_id(); // define session array $session = ['user' => $_userid, 'cat' => 'session', 'key' => session_name(), 'value' => $session_id]; if ($_meta) { $session['meta'] = $_meta; } if ($_id & is_numeric($_id)) { $session['id'] = $_id; } // save in options table and if successful return session_id if (\lib\utility\option::set($session, true)) { return $session_id; } // else return false return false; }
/** * 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; }
/** * { function_description } * * @param <type> $_user The user * @param <type> $_type The type * @param <type> $_value The value * @param <type> $_args The arguments * * @return <type> ( description_of_the_return_value ) */ public static function updateDetail($_user, $_type, $_value, $_args) { $changeDate = date('Y-m-d H:i:s'); // save mobile number in user history $userDetail = ['user' => $_user, 'cat' => 'history_' . $_user, 'key' => $_type, 'value' => $_value, 'meta' => $_args]; $result = \lib\utility\option::set($userDetail); return $result; }
public function sp_savePoll($_post_new_id, $_onlyAns = false) { $answers = []; $max_ans = 10; for ($i = 1; $i <= $max_ans; $i++) { if (utility::post('ans' . $i)) { $answers[$i]['id'] = $i; $answers[$i]['point'] = utility::post('ans' . $i . '_point'); $answers[$i]['txt'] = utility::post('ans' . $i); } } if ($_onlyAns === true) { return $answers; } $answers = json_encode($answers, JSON_UNESCAPED_UNICODE); $option_data = ['post' => $_post_new_id, 'cat' => 'meta_polls', 'key' => 'answers_' . $_post_new_id, 'value' => "", 'meta' => $answers, 'status' => 'enable']; // save in options table and if successful return session_id return \lib\utility\option::set($option_data, true); }