/**
  *Enlever les elses
  */
 public function createBuilding($params)
 {
     $userId = self::getUserIdByToken(addslashes($params['token']));
     if (!$userId) {
         return Utils::formatErrorMessage(ERROR_BAD_TOKEN, "Bad token");
     }
     if (!self::isValidPosition(addslashes($params['x']), addslashes($params['y']), $userId)) {
         return Utils::formatErrorMessage(ERROR_BAD_POSITION, "Cette position est prise ou pas à portée d'une lanterne");
     }
     if (!BuildingModel::isBuildingExist($params['name'])) {
         return Utils::formatErrorMessage(ERROR_BUILDING_NAME_INCORRECT, "Le nom du building est incorrect");
     }
     if (!self::buyBuilding($params['name'], $userId)) {
         return Utils::formatErrorMessage(ERROR_NO_MONEY, "Not enough gold");
     }
     $buildingID = BuildingModel::getBuildingTypeIdByName($params['name']);
     //echo($result);
     //$result = 0;
     switch ($params['name']) {
         case 'rocket_factory':
             $date = date("Y-m-d H:i:s");
             $lvl = 1;
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_rocket_factory VALUES (NULL, ?, ?, ?)');
             $request->execute(array($userId, $lvl, $date));
             break;
         case 'temple':
             $pinataReady = date("Y-m-d H:i:s");
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_temple VALUES (NULL, ?, ?)');
             $request->execute(array($userId, $pinataReady));
             break;
         case 'bar':
             $date = date("Y-m-d H:i:s");
             $lvl = 1;
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_bar VALUES (NULL, ?, ?, ?)');
             $request->execute(array($userId, $lvl, $date));
             break;
         case 'brothel':
             if (!BuildingModel::getBuildings($buildingID, $userId)) {
                 return Utils::formatErrorMessage(ERROR_BUILDING_NAME_INCORRECT, "Building unique déja construit");
             }
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_brothel VALUES (NULL, ?)');
             $request->execute(array($userId));
             break;
         case 'main_square':
             if (!BuildingModel::getBuildings($buildingID, $userId)) {
                 return Utils::formatErrorMessage(ERROR_BUILDING_NAME_INCORRECT, "Building unique déja construit");
             }
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_main_square VALUES (NULL, ?)');
             $request->execute(array($userId));
             break;
         case 'pyrotechnician':
             $date = date("Y-m-d H:i:s");
             $lvl = 1;
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_pyrotechnician VALUES (NULL, ?, ?, ?)');
             $request->execute(array($userId, $lvl, $date));
             break;
         case 'city_hall':
             if (!BuildingModel::getBuildings($buildingID, $userId)) {
                 return Utils::formatErrorMessage(ERROR_BUILDING_NAME_INCORRECT, "Building unique déja construit");
             }
             $date = date("Y-m-d H:i:s");
             $lvl = 1;
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_city_hall VALUES (NULL, ?, ?, ?)');
             $request->execute(array($userId, $lvl, $date));
             break;
         case 'church':
             if (!BuildingModel::getBuildings($buildingID, $userId)) {
                 return Utils::formatErrorMessage(ERROR_BUILDING_NAME_INCORRECT, "Building unique déja construit");
             }
             $date = date("Y-m-d H:i:s");
             $lvl = 1;
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_church VALUES (NULL, ?, ?, ?)');
             $request->execute(array($userId, $lvl, $date));
             break;
         case 'cantina':
             $date = date("Y-m-d H:i:s");
             $lvl = 1;
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_cantina VALUES (NULL, ?, ?, ?)');
             $request->execute(array($userId, $lvl, $date));
             break;
         case 'gift_shop':
             if (!BuildingModel::getBuildings($buildingID, $userId)) {
                 return Utils::formatErrorMessage(ERROR_BUILDING_NAME_INCORRECT, "Building unique déja construit");
             }
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_gift_shop VALUES (NULL, ?)');
             $request->execute(array($userId));
             break;
         default:
             $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_' . $params['name'] . ' VALUES (NULL, ?)');
             $request->execute(array($userId));
             break;
     }
     $building_id = $GLOBALS['app']['db']->lastInsertId();
     $building_type_id = BuildingModel::getBuildingTypeIdByName($params['name']);
     $date = date("Y-m-d H:i:s");
     $color = "A";
     //Les couleurs sont d'une lettres, en uppercase
     $constructTime = BuildingModel::getConstructTime($params['name']);
     $construct_end = date("Y-m-d H:i:s", strtotime("+" . $constructTime . " hour", strtotime($date)));
     $request = $GLOBALS['app']['db']->prepare('INSERT INTO building_users VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
     $request->execute(array($userId, $date, $date, $building_type_id, $building_id, addslashes($params['x']), addslashes($params['y']), $construct_end, $color));
     return ResourcesController::getResource($userId);
 }