/** * Store a newly created resource in storage. * * @return Response */ public function store() { $game = new Game(); $game->fill(Input::all()); $game->save(); return Redirect::action('GameController@index'); }
public function executeCreate(sfWebRequest $request) { $user = UserPeer::retrieveByPk($request->getParameter('username')); if (!$user) { $arr = array(); $arr["result"] = false; $arr["message"] = "Invalid username"; $this->renderText(json_encode($arr)); return sfView::NONE; } $game = new Game(); $game->setIsPublic($request->getParameter('public', 0)); $game->setStartTime(time()); $game->setIsActive(true); $game->setLatitude($request->getParameter('latitude')); $game->setLongitude($request->getParameter('longitude')); $game->save(); $gameMember = new GameMember(); $gameMember->setUserId($user->getId()); $gameMember->setGameId($game->getId()); $gameMember->setIsActive(true); $gameMember->save(); $user->setCurrentGameId($game->getId()); $this->updateUserLocation($user, $request); $arr = array(); $arr["result"] = true; $arr["message"] = "Game created, game number is " . $game->getId() . ". When others join, you will be assigned a target"; $this->renderText(json_encode($arr)); return sfView::NONE; }
protected function endGame($roles) { $playerRepository = new PlayerRepository(); $players = $playerRepository->getByGameAndRole($this->game['id'], $roles); $playersNames = array(); foreach ($players as $player) { $player['winner'] = 1; $player->save(); $user = $player->getUser(); $playersNames[] = $user['username']; } // znovu nacitame actual a attacking playera lebo to robi nejake halusky if ($this->actualPlayer) { $this->actualPlayer = $playerRepository->getOneById($this->actualPlayer['id']); } if ($this->attackingPlayer) { $this->attackingPlayer = $playerRepository->getOneById($this->attackingPlayer['id']); } // vytvorit nejaku tabulku hall of fame kde budu vyhry a prehry // vyhry a prehry za nejaku konkretnu rolu - typ roly - cize je jedno ci si bandita1 alebo bandita2 $message = array('text' => 'vyhrali hraci: ' . implode(', ', $playersNames), 'user' => User::SYSTEM); $this->addMessage($message); $this->game['status'] = Game::GAME_STATUS_ENDED; $this->game->save(); }
public function handleCreate() { $game = new Game(); $game->title = Input::get('title'); $game->publisher = Input::get('publisher'); $game->completed = Input::has('completed'); $game->save(); return Redirect::action('GamesController@index'); }
public function beforeSave() { if (preg_match('/^ん$/u', mb_substr($this->data['Word']['pronunciation'], -1, 1, 'UTF-8')) === 1) { App::import('Model', 'Game'); $game = new Game(); $game->save(array('id' => $this->data['Word']['game_id'], 'is_active' => false), false, array('is_active')); } return parent::beforeSave(); }
public function addGame($args) { $model = new Game(); $model->setAttributes($args); if ($model->save(FALSE)) { return $model->id; } return FALSE; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aGame !== null) { if ($this->aGame->isModified() || $this->aGame->isNew()) { $affectedRows += $this->aGame->save($con); } $this->setGame($this->aGame); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = UserPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); } else { $affectedRows += UserPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collTargetsRelatedByFromUserId !== null) { foreach ($this->collTargetsRelatedByFromUserId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collTargetsRelatedByToUserId !== null) { foreach ($this->collTargetsRelatedByToUserId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collGameMembers !== null) { foreach ($this->collGameMembers as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function createMultiple($round) { foreach (Input::get('games') as $game) { $g = new Game(); $g->round = $round->id; $g->slug = $game['slug']; $g->map = $game['map']; $g->save(); App::make('ReportsController')->createMultiple($g, $game['players']); } }
public function handleCreate() { if (Auth::guest()) { return Redirect::action('UserController@login'); } // Handle create form submission. $game = new Game(); $game->title = Input::get('title'); $game->publisher = Input::get('publisher'); $game->complete = Input::has('complete'); $game->user_id = Auth::user()->id; $game->save(); return Redirect::action('GamesController@index'); }
public function run() { $i = 0; foreach (array_keys(Config::get('devices')) as $device) { foreach (array_keys(Config::get('genres')) as $genre) { $game = new Game(); $game->game_title = "game {$i}"; $game->device = $device; $game->genre = $genre; $game->save(); $i++; } } }
public static function store() { $params = $_POST; $rain = isset($_POST['rain']) && $_POST['rain'] ? "1" : "0"; // checked=1, unchecked=0 $wet_no_rain = isset($_POST['wet_no_rain']) && $_POST['wet_no_rain'] ? "1" : "0"; // checked=1, unchecked=0 $windy = isset($_POST['windy']) && $_POST['windy'] ? "1" : "0"; // checked=1, unchecked=0 $variant = isset($_POST['variant']) && $_POST['variant'] ? "1" : "0"; // checked=1, unchecked=0 $dark = isset($_POST['dark']) && $_POST['dark'] ? "1" : "0"; // checked=1, unchecked=0 $led = isset($_POST['led']) && $_POST['led'] ? "1" : "0"; // checked=1, unchecked=0 $snow = isset($_POST['snow']) && $_POST['snow'] ? "1" : "0"; // checked=1, unchecked=0 $date = $_POST['date']; $time = $_POST['time']; $comment = $_POST['comment']; $courseid = $_POST['courseid']; $gamedate = $date . " " . $time . ":00"; $game = new Game(array('courseid' => $courseid, 'gamedate' => $gamedate, 'comment' => $comment, 'rain' => $rain, 'wet_no_rain' => $wet_no_rain, 'windy' => $windy, 'variant' => $variant, 'dark' => $dark, 'led' => $led, 'snow' => $snow)); $errors = $game->errors(); $course = Course::find($courseid); $scores = array(); // When implementing multiple players per game, cycle through playerid's here $playerid = $_POST['playerid']; foreach ($course->holes as $hole) { $stroke = $_POST['hole' . $hole->hole_num]; // 'holeN' will be something like 'playername-holeN' $ob = $_POST['obhole' . $hole->hole_num]; $score = new Score(array('holeid' => $hole->holeid, 'playerid' => $playerid, 'stroke' => $stroke, 'ob' => $ob)); $errors = array_merge($errors, $score->errors()); $scores[] = $score; } if (count($errors) == 0) { // Game and scores were all valid $gameid = $game->save(); foreach ($scores as $score) { $score->gameid = $gameid; $score->save(); } Redirect::to('/game/' . $game->gameid, array('message' => 'Peli ja sen tulokset lisätty.')); } else { View::make('game/new.html', array('errors' => $errors, 'attributes' => $params, 'course' => $course)); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if ($this->aUser->isModified() || $this->aUser->isNew()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->aGame !== null) { if ($this->aGame->isModified() || $this->aGame->isNew()) { $affectedRows += $this->aGame->save($con); } $this->setGame($this->aGame); } if ($this->isNew()) { $this->modifiedColumns[] = GameMemberPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = GameMemberPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += GameMemberPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // Fetch all request data. $data = Input::only('title', 'game_icon'); // Build the validation constraint set. $rules = array('title' => array('required')); // Create a new validator instance. $validator = Validator::make($data, $rules); if ($validator->passes()) { $game = new Game(); $title = Input::get('title'); //$uniqid = str_shuffle(uniqid()); $game->slug = Str::slug($title, '-'); $game->title = $title; $game->game_icon = Input::get('game_icon'); $game->save(); Cache::forget('games'); return Redirect::to('/')->with('global_success', 'Game submitted successfully!'); } return Redirect::to('/game/add')->withInput()->withErrors($validator)->with('message', 'Validation Errors!'); }
include_once "classes/Game.php"; include_once "classes/GameTable.php"; include_once "classes/ActionType.php"; if (isset($_POST['action'])) { $action = $_POST['action']; $return = true; switch ($action) { case ActionType::ACTION_SAVE: $name = $_POST['name']; $gameType = $_POST['gameType']; $year = $_POST['year']; $rating = $_POST['rating']; $company = $_POST['company']; try { $game = new Game(null, $gameType, $name, $rating, $year, $company); $game->save(); } catch (PDOException $exception) { $return = false; } break; case ActionType::ACTION_DELETE: $id = $_POST['id']; try { $game = new Game($id, null, null, null, null, null); $game->delete(); } catch (PDOException $exception) { $return = false; } break; case ActionType::ACTION_MODIFY: $name = $_POST['name'];
public function saveGames($games) { $documents = array(); $new = array(); print_r("Saving " . count($games) . " Game Listings\n"); foreach ($games as $game) { $homeSlug = $this->slugify->simple($game['homeTeam']); $homeTeam = $this->_team->findOneBySlug($homeSlug); if (!$homeTeam) { $homeTeam = $this->_team->createByName($game['homeTeam']); } $homeTeam = $this->mongo->create_dbref('team', $homeTeam->getId()); $awaySlug = $this->slugify->simple($game['awayTeam']); $awayTeam = $this->_team->findOneBySlug($awaySlug); if (!$awayTeam) { $awayTeam = $this->_team->createByName($game['awayTeam']); } $awayTeam = $this->mongo->create_dbref('team', $awayTeam->getId()); //print_r($homeTeam); //print_r($awayTeam); $datetime = new MongoDate(strtotime($game['date'])); $document = $this->findOneByDateWithTeamsAndScores($datetime, $homeTeam, $awayTeam, $game['homeScore'], $game['awayScore']); if (!$document) { $document = new Game(); $document->setDatetime($datetime); $document->setHomeTeam($homeTeam); $document->setAwayTeam($awayTeam); $document->setHomeScore($game['homeScore']); $document->setAwayScore($game['awayScore']); $document->setUrl($game['url']); $document->save(); array_push($new, $document); } if (!in_array($document, $documents)) { array_push($documents, $document); } print_r('.'); //print_r(count($documents)); } if (count($games)) { print_r("\n"); } print_r("Added " . count($new) . " New Games\n"); return $documents; }
public static function csv_import_process() { $courses = Course::all(); $file_count = count($_FILES['file']['tmp_name']); // Cycle through files for ($i = 0; $i < $file_count; $i++) { $original_filename = $_FILES['file']['name'][$i]; echo "<h3>Adding file: " . $original_filename . "</h3>"; // Find course name $course_name = "NOT FOUND"; $game_course = null; foreach ($courses as $course) { // Check if filename contains coursename if (strpos($original_filename, $course->name) !== false) { $course_name = $course->name; $game_course = $course; } } // Game date $gamedate = substr($original_filename, 0, 11); $gamedate .= " 00:00:00"; echo "Course name: " . $course_name . "<br>"; echo "Game date: " . $gamedate . "<br>"; // Create game $game = new Game(array('courseid' => $game_course->courseid, 'gamedate' => $gamedate, 'rain' => 0, 'wet_no_rain' => 0, 'windy' => 0, 'variant' => 0, 'dark' => 0, 'led' => 0, 'snow' => 0, 'doubles' => 0)); $gameid = $game->save(); // Create scores $csvAsArray = array_map('str_getcsv', file($_FILES['file']['tmp_name'][$i])); $score_errors = CSVScoreProcessor::process($csvAsArray, $gameid, $game_course); if (count($score_errors)) { echo "ERRORS: "; print_r($score_errors); } echo "<br>Done!"; echo "<br>"; } // Clear cached pages Cache::clear(); }
public function gameCreate() { $game = new Game(); $game->lastStepDate = time(); $game->save(); return $this->findMaxGameSession(); }
<?php include 'database_connection.php'; include 'classes/MediaItem.php'; include 'classes/Game.php'; include 'classes/Book.php'; include 'classes/Music.php'; include 'classes/Movie.php'; $game = new Game(); $game->setTitle('Watch Dogs'); $game->setDesc('Crappy shit wannabe hacker game'); $game->setRating(1); $game->setTags(['dnt']); print '<p>' . ($game->save() ? "Saving successful" : "Saving unsuccessful") . '</p>'; $book = new Book(); $book->setTitle('Momo'); $book->setDesc('Dreamy and so on'); $book->setRating(4); $book->setTags(['tc']); print '<p>' . ($book->save() ? "Saving successful" : "Saving unsuccessful") . '</p>'; $movie = new Movie(); $movie->setTitle('The big short'); $movie->setDesc('Capitalism'); $movie->setRating(3); $movie->setTags(['tc', 'wtf']); print '<p>' . ($movie->save() ? "Saving successful" : "Saving unsuccessful") . '</p>'; $music = new Music(); $music->setTitle('Bravo Hits 666'); $music->setDesc('Diabolic Bullshit'); $music->setRating(1); $music->setTags(['dnt']);
public function APICrImport() { $postdata = file_get_contents("php://input"); $request = json_decode($postdata, true); ob_start(); $this->APICrParseInternal($request); $myStr = ob_get_contents(); ob_end_clean(); $cr = json_decode($myStr, true)['data']; //print_r($request); //print_r($cr); //header("HTTP/1.1 406 Not Found"); //print_r($request); // exit(); $GamesID = array(); $CRID = 0; //On check les jeux $games = new Game($this->db); foreach ($request['games'] as $key => $value) { // print_r($value); //si ID == -1 = saisie manuelle if ($value['id'] == -1) { } else { if (isset($value['origin']) && $value['origin'] == 'bdd') { // origin = bdd $games->load(array('id = ?', $value['id'])); } else { $games->load(array('api_uid = ?', $value['id'])); } } if ($games->id) { $GamesID[] = $games->id; } else { if ($value['id'] == -1) { $value['id'] = 99999999; } //on doit l'ajouter $games->reset(); $games->name = $value['name']; $games->api_uid = $value['id']; $games->api_image = $value['image']['super_url']; $games->api_date = $value['date']; $games->save(); $GamesID[] = $games->id; } $games->reset(); } //print_r($GamesID); //On ajoute le CR $newCR = new CR($this->db); //on vérfie si il est pas déjà en base $newCR->load(array('hfr_post_id = ?', $cr['hfr_post_id'])); if ($newCR->id) { header("HTTP/1.1 405 Not Found"); echo 'CR déjà en base :) > <a target="_blank" href="/crotypedia/' . $newCR->id . '">voir sur le site</a>'; exit; } $newCR->reset(); $crProcessed = $newCR->processRawContent($cr); //print_r($crProcessed); $newCR->hfr_cat_id = 5; $newCR->hfr_subcat_id = 249; $newCR->hfr_topic_id = 177180; //$newCR->hfr_page_id = $crProcessed['hfr_page_id']; $newCR->hfr_post_id = $crProcessed['hfr_post_id']; $newCR->hfr_user_id = $crProcessed['hfr_user_id']; $newCR->username = $crProcessed['username']; $newCR->content = $crProcessed['content']; $newCR->content_raw = $crProcessed['content_raw']; $newCR->date_posted = $crProcessed['date_posted']; $newCR->date_modified = date('Y-m-d H:i:s'); $newCR->date_added = date('Y-m-d H:i:s'); $newCR->active = 1; $newCR->type_id = $request['type']; $newCR->format_id = $request['format']; $newCR->comment = $request['comment']; $newCR->save(); $CRID = $newCR->id; $newCR->reset(); //On ajoute en DB $CrGame = new CrGame($this->db); foreach ($GamesID as $gid) { $CrGame->cr_id = $CRID; $CrGame->game_id = $gid; $CrGame->save(); $CrGame->reset(); } echo 'CR ajouté > <a target="_blank" href="/crotypedia/' . $CRID . '">voir sur le site</a>'; }
$app->get('/', function () use($app) { return $app['twig']->render('go_fish.html.twig', array('games' => Game::getAll())); }); $app->get('/add_players', function () use($app) { return $app['twig']->render('add_players.html.twig'); }); $app->post('/created_players', function () use($app) { $new_game = new Game(); $new_players = new Player(); $player1 = $_POST['player1']; $player2 = $_POST['player2']; $new_players->setName1($player1); $new_players->setName2($player2); $new_game->setPlayers($new_players); $current_players = $new_game->getPlayers(); $new_game->save(); $new_players->save(); return $app['twig']->render('created_players.html.twig', array('newplayers' => $current_players)); }); $app->get('/add_player_one_cards', function () use($app) { return $app['twig']->render('add_player_one_cards.html.twig'); }); $app->post('/player_one_hand', function () use($app) { $active_game = Game::getAll(); $active_players = Player::getAll(); $current_players = $active_players[0]->getPlayers(); $current_score = $active_players[0]->getScore1(); $cards = $current_players->getCards(); $current_hand = array(); for ($i = 0; $i <= 4; $i++) { array_push($current_hand, rand(1, 10));
private function importGame($game, $intoDb = null) { $game['database_id'] = $intoDb; $g = new Game(); $g->save($game); return $g->getId(); }
/** * draw cards from draw pile of a $game * * @param Game $game * @param integer $count * @return array - IDs array of drawn cards */ public static function drawCards(Game $game, $count) { if ($game->getIsHNAbandonedMine()) { $drawPile = $game->getThrowPile(); } else { $drawPile = $game->getDrawPile(); } $drawnCards = array(); for ($i = 0; $i < $count; $i++) { $card = array_pop($drawPile); $drawnCards[] = $card['id']; if (empty($drawPile)) { if ($game->getIsHNAbandonedMine()) { $drawPile = $game->getDrawPile(); shuffle($drawPile); $game->setAdditionalField('draw_pile', array()); $game['draw_pile'] = serialize(array()); } else { $drawPile = $game->getThrowPile(); shuffle($drawPile); $game->setAdditionalField('throw_pile', array()); $game['throw_pile'] = serialize(array()); } } } $newDrawPile = array(); foreach ($drawPile as $card) { $newDrawPile[] = $card['id']; } if ($game->getIsHNAbandonedMine()) { $game->setAdditionalField('throw_pile', $drawPile); $game['throw_pile'] = serialize($newDrawPile); } else { $game->setAdditionalField('draw_pile', $drawPile); $game['draw_pile'] = serialize($newDrawPile); } $game->save(); return $drawnCards; }
public static function searchForGames($query, $limit = 10) { self::validateApiKey(); //Change these if we need to include more stuff. $fieldArr = ['id', 'name', 'original_release_date', 'image', 'api_detail_url', 'deck', 'image', 'platforms']; //sanitise query $query = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($query)))))); //generate url $url = self::$gb . 'games?api_key=' . self::$apikey . '&format=json' . self::formatFieldList($fieldArr) . '&limit=' . $limit . '&filter=platforms:17|94|152,name:' . $query; //Limit to Mac, PC, Linux respectively. try { $json = self::makeApiCall($url); } catch (Exception $e) { throw new GBApiException('Error contacting Giantbomb. Please try again later.'); } //QueryDb and try to find the object using the giantbomb unique id if ($json->results == null || count($json->results) < 1) { throw new GBApiException('No results found. Please try another search.'); } $games = []; //initialise as empty array foreach ($json->results as $result) { if (!isset($result->original_release_date) || $result->original_release_date == null) { continue; } //skip if not out yet. $game = GameQuery::create()->findOneByGbId($result->id); if (!isset($game)) { $game = new Game(); $game->setGbId($result->id); $game->setName(Game::generateUniqueName($result->name, $result->original_release_date)); } $game->setGbUrl($result->api_detail_url); $game->setTitle($result->name); $game->setDescription($result->deck); //We don't care if they don't have thumbs. Catch the exceptions and move on try { $game->setGbThumb($result->image->screen_url); } catch (Exception $e) { } try { $game->setGbImage($result->image->medium_url); } catch (Exception $e) { } $game->save(); //Fetch all of the title's platforms from the results we pulled from GB and push them into an array $gbplatforms = []; foreach ($result->platforms as $gbplatform) { array_push($gbplatforms, $gbplatform->id); } //Remove platforms no longer associated with the title $currentPlatforms = $game->getPlatforms(); foreach ($currentPlatforms as $plat) { if (!in_array($plat->getGbId(), $gbplatforms)) { $game->removePlatform($plat); } } //add new platforms associated with the title $allPlatforms = Platform::getAllPlatforms(); foreach ($allPlatforms as $plat) { if (in_array($plat->getGbId(), $gbplatforms)) { $found = false; foreach ($currentPlatforms as $curPlat) { if ($curPlat->getId() == $plat->getId()) { $found = true; break; } } if ($found) { continue; } $game->addPlatform($plat); } } //append result to list. $game->save(); array_push($games, $game); } return $games; }
public function run() { $game = new Game(); $game->game = 'First game'; $game->save(); }
/** * Schedule one set of games, using weighted field assignment * * Takes an array of teams and a datestamp. From this: * - iterate over teams array pairwise and call add_teams_balanced() to create a game with balanced home/away * - iterate over all newly-created games, and assign fields based on region preference. * All of this is performed in a transaction and rolled back if any game fails. */ function schedule_one_set($teams, $datestamp, $should_publish = true) { global $dbh; $dbh->beginTransaction(); $games_list = array(); for ($team_idx = 0; $team_idx < count($teams); $team_idx += 2) { $g = new Game(); $g->set('league_id', $this->league_id); $g->add_teams_balanced($teams[$team_idx], $teams[$team_idx + 1]); $g->set('published', $should_publish); if (!$g->save()) { if (!$dbh->rollback()) { $extra_errors = "<br />Also, failed to roll back transaction. Please contact the system administrator"; } return array(false, "Could not create the games you requested, during addition of opponents.{$extra_errors}"); } $games_list[] = $g; } try { $this->assign_fields_by_preferences($games_list, $datestamp); } catch (Exception $e) { $extra_errors = $e->getMessage(); if (!$dbh->rollback()) { $extra_errors .= "<br />Also, failed to roll back transaction. Please contact the system administrator"; } return array(false, "Failed to assign gameslots for requested games on " . strftime('%c', $datestamp) . ": {$extra_errors}"); } $rc = $dbh->commit(); if (!$rc) { return array(false, 'Transaction commit failed'); } return array(true, ''); }
public function v14() { // Regenerate cache Cache::clear(false); /* * API */ // Copy bridge secret key to API private key $bridge = json_decode($this->Setting->getOption('bridge')); if (!empty($bridge) && $bridge->enabled && !empty($bridge->secret)) { $api = array(); $api['enabled'] = 0; $api['privateKey'] = $bridge->secret; $this->Setting->setOption('api', json_encode($api)); // Disable bridge to make use users update their bridge plugin $bridgeSettings = array(); $bridgeSettings['enabled'] = 0; $bridgeSettings['url'] = $bridge->url; $this->Setting->setOption('bridge', json_encode($bridgeSettings)); $this->Session->setFlash(__('Bridge has been disabled ! Be sure to use an updated version of your bridge plugin for MushRaider 1.4. If you don\'t you\'re gonna have a bad time !'), 'flash_important', array(), 'important'); } /* * Import */ // Add absolute path to games's logo field to prepare import functionallity App::uses('Game', 'Model'); $GameModel = new Game(); $params = array(); $params['recursive'] = -1; $params['fields'] = array('id', 'logo'); if ($games = $GameModel->find('all', $params)) { foreach ($games as $game) { if (!empty($game['Game']['logo']) && strpos($game['Game']['logo'], '/files/') === false) { $toUpdate = array(); $toUpdate['id'] = $game['Game']['id']; $toUpdate['logo'] = '/files/logos/' . $game['Game']['logo']; $GameModel->create(); $GameModel->save($toUpdate); } } } /* * Roles permissions */ // Add roles permissions $rolesPermissions = array(array('title' => __('Full permissions'), 'alias' => 'full_permissions', 'description' => __('Like Chuck Norris, he can do anything. This overwrite every permissions')), array('title' => __('Limited admin access'), 'alias' => 'limited_admin', 'description' => __('Like Robin, he can do some things but not all (like driving the batmobile or change user role)')), array('title' => __('Can manage events'), 'alias' => 'manage_events', 'description' => __('Can create, edit and delete events. Can also manage the roster for each events')), array('title' => __('Can create templates'), 'alias' => 'create_templates', 'description' => __('Can create events templates')), array('title' => __('Can create reports'), 'alias' => 'create_reports', 'description' => __('Can create events reports'))); App::uses('RolePermission', 'Model'); $RolePermissionModel = new RolePermission(); foreach ($rolesPermissions as $rolesPermission) { $RolePermissionModel->create(); $RolePermissionModel->save($rolesPermission); } // Add new roles permissions to existing roles App::uses('Role', 'Model'); $RoleModel = new Role(); App::uses('RolePermissionRole', 'Model'); $RolePermissionRoleModel = new RolePermissionRole(); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('admin'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('full_permissions'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('limited_admin'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('manage_events'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_templates'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_reports'))); }
/** * Persist * * @param Game $game * @internal param User $user * @return mixed */ public function save(Game $game) { return $game->save(); }