public function index($params) { $data = []; $token = addslashes($params['token']); if (!isset($params['friend_user_id'])) { $userId = self::getUserIdByToken($params['token']); if (!$userId) { return Utils::formatErrorMessage(ERROR_BAD_TOKEN, "Bad token"); } } else { $userId = $params['friend_user_id']; } $buildings = BuildingsController::getBuildings($userId); $lanterns = LanternsController::getLanterns($userId); $resources = ResourcesController::getResource($userId); $gifts = GiftsController::getGifts($userId); $username = UserModel::getUsername($userId); $parade = self::getParade($userId); $dailyreward = self::getDailyreward($userId); $experience = self::getExperience($userId); $ftue = self::getFtue($userId); $resources = json_decode($resources); $data['buildings'] = $buildings; $data['lanterns'] = $lanterns; $data['resources'] = $resources->{'data'}; $data['gifts'] = $gifts; $data['username'] = $username; $data['parade'] = $parade; $data['dailyreward'] = $dailyreward; $data['experience'] = $experience; $data['ftue_complet'] = $ftue; if ($buildings == ERROR_BAD_TOKEN) { return Utils::formatErrorMessage(ERROR_BAD_TOKEN, "Bad token"); } $error = ''; return json_encode(['data' => $data, 'error' => $error != '', 'errorCode' => -1, 'errorMessage' => $error]); }
require_once __DIR__ . '/../app/models/UserModel.class.php'; require_once __DIR__ . '/../Utils.class.php'; require_once __DIR__ . '/../app/models/ResourceModel.class.php'; require_once __DIR__ . '/../app/controllers/ResourcesController.class.php'; require_once __DIR__ . '/../app/models/BuildingModel.class.php'; require_once __DIR__ . '/../app/controllers/BuildingsController.class.php'; require_once __DIR__ . '/../app/models/LanternModel.class.php'; require_once __DIR__ . '/../app/controllers/LanternsController.class.php'; require_once __DIR__ . '/../app/models/GiftModel.class.php'; require_once __DIR__ . '/../app/controllers/GiftsController.class.php'; $basePath = '/v1'; $UsersController = new UsersController(); $ResourcesController = new ResourcesController(); $BuildingsController = new BuildingsController(); $LanternsController = new LanternsController(); $GiftsController = new GiftsController(); $UserModel = new UserModel(); $ResourceModel = new ResourceModel(); $BuildingModel = new BuildingModel(); $LanternModel = new LanternModel(); $GiftModel = new GiftModel(); /* * Main path */ $app->get('/', function (Request $request) use($app, $UsersController) { return $app->redirect('doc/index.html'); }); /* * Users */ $app->get($basePath . '/userInfos', function (Request $request) use($app, $UsersController, $UserModel) {