Skip to content

Commit

Permalink
nuovo modello database
Browse files Browse the repository at this point in the history
  • Loading branch information
fiste788 committed Mar 22, 2017
1 parent 48fda68 commit e17ce26
Show file tree
Hide file tree
Showing 51 changed files with 1,207 additions and 1,106 deletions.
25 changes: 16 additions & 9 deletions app/controllers/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class ApplicationController extends BaseController {

/**
*
* @var League
* @var Championship
*/
protected $currentChampionship;

Expand All @@ -73,17 +73,18 @@ public function notAuthorized() {
public function initialize() {
parent::initialize();
$this->notification = array();
$leagues = League::getList();
$championships = Championship::getList();
$this->roles = \Fantamanajer\Models\Role::getList();

if (!is_null(Request::getRequest()->getParam('league_view', NULL))) {
$_SESSION['league_view'] = Request::getRequest()->getParam('league_view');
}
if (isset($_SESSION['league_id'])) {
$_SESSION['league_data'] = $leagues[$_SESSION['league_data']];
}
//if (isset($_SESSION['league_id'])) {
$_SESSION['championship_data'] = $championships[1];
//}
$this->currentSeason = Season::getCurrent();
$this->currentMatchday = Matchday::getCurrent();
$this->currentLeague = $leagues[$_SESSION['league_view']];
//$this->currentLeague = $championships[$_SESSION['league_view']];
$this->currentChampionship = Championship::getById(1);
//$this->currentLeague = $leagues[1];
$endDate = Matchday::getTargetCountdown();
Expand All @@ -92,12 +93,18 @@ public function initialize() {
$savant->assign('timestamp', $endDate->getTimestamp());
$savant->assign('currentMatchday', $this->currentMatchday);
$savant->assign('isSeasonEnded', $this->currentMatchday->isSeasonEnded());
$savant->assign('leagues', $leagues);
$savant->assign('championships', $championships);
$savant->assign('route', $this->route);
$savant->assign('page', $this->page);
$savant->assign('router', $this->router);
$savant->assign('request', $this->request);
$savant->assign('roles', $this->roles);
}
//die(var_dump($this->pages));
$this->pages->pages['championship']->title = $this->currentChampionship->getLeague()->getName();
// $this->pages->pages['teams_show']->params = ['id' => $_SESSION['team']->id];
//$this->pages->pages['teams_show']->title = $_SESSION['team']->name;
//$this->pages['championship']->title = $this->currentChampionship->getName();
$this->quickLinks = new QuickLinks($this->request, $this->router, $this->route);
$this->templates['navbar']->assign('entries', $this->pages);
$this->templates['header']->assign('entries', $this->pages);
Expand All @@ -109,9 +116,9 @@ public function initialize() {
private function initializeNotification() {
if ($_SESSION['logged']) {
if (!$this->currentMatchday->isSeasonEnded()) {
$lineup = Lineup::getFormazioneBySquadraAndGiornata($_SESSION['user_id'], $this->currentMatchday->getId());
$lineup = Lineup::getByTeamAndMatchday($_SESSION['user_id'], $this->currentMatchday->getId());
if (empty($lineup)) {
$this->notification[] = new Notify(Notify::LEVEL_MEDIUM, 'Non hai ancora impostato la formazione per questa giornata', $this->router->generate('lineup'));
$this->notification[] = new Notify(Notify::LEVEL_MEDIUM, 'Non hai ancora impostato la formazione per questa giornata', $this->router->generate('lineups'));
}
}
$inactivePlayers = Member::getInactiveByTeam(User::getById($_SESSION['user_id'])->getTeam());
Expand Down
122 changes: 0 additions & 122 deletions app/controllers/FormazioneController.php

This file was deleted.

127 changes: 127 additions & 0 deletions app/controllers/LineupsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace Fantamanajer\Controllers;

use Fantamanajer\Models\Lineup;
use Fantamanajer\Models\Matchday;
use Fantamanajer\Models\Member;
use Fantamanajer\Models\Team;
use Fantamanajer\Models\View\MemberStats;
use FirePHP;
use Lib\FormException;

class LineupsController extends ApplicationController {

public function show() {
$filterTeam = $this->request->getParam('team_id', $_SESSION['team']->id);
$filterMatchday = $this->request->getParam('matchday_id', $this->currentMatchday->getId());

$team = Team::getById($filterTeam);
$matchday = Matchday::getById($filterMatchday);

$lineup = Lineup::getLast($filterTeam, $filterMatchday);
$this->_showLineup($team,$matchday,$lineup);
}

public function build() {
$filterTeam = $this->request->getParam('team_id', $_SESSION['team']->id);
$filterMatchday = $this->request->getParam('matchday_id', $this->currentMatchday->getId());

$a = $this->request->getPostParams();
if(empty($a)) {
$lineup = Lineup::getLast($filterTeam, $filterMatchday);
} else {
$lineup = new Lineup();
$lineup->setTeamId($_SESSION['team']->id);
$lineup->setMatchdayId($this->currentMatchday->id);
$lineup->setModule($lineup->calcModule($this->request->getParam('regular')));
$lineup->players = $lineup->getSchieramenti(array_merge($this->request->getParam('regular'), $this->request->getParam('notRegular')));
}

$this->_showLineup($filterTeam,$filterMatchday,$lineup);
}

protected function _showLineup(Team $team, Matchday $matchday, Lineup $lineup = NULL) {
$module = explode('-','1-4-4-2');
if($matchday->id == $this->currentMatchday->id) {
$players = MemberStats::getByTeam($team);
} else {
$players = Member::getGiocatoriBySquadraAndGiornata($team->id,$matchday->id);
}
if ($lineup != NULL) {
$module = explode('-',$lineup->getModule());
if($lineup->getMatchdayId() != $this->currentMatchday->getId()) {
$lineup = clone $lineup;
$lineup->setMatchdayId($this->currentMatchday->getId());
$lineup->setJolly(FALSE);
$ids = array();
foreach($lineup->players as $player) {
$ids[] = $player->id;
}
}
if($matchday->id != $this->currentMatchday->id) {
$players = MemberStats::getByIds($ids);
}
}
//$module = array_combine(array("P","D","C","A"), array_map('intval', $module));
$module = array_map('intval', $module);
$playersRole = array();
foreach($players as $player) {
$playersRole[$player->role->id][$player->getId()] = $player;
}
$moduleAllowed = array(
"1-4-4-2"=>"4-4-2",
"1-3-5-2"=>"3-5-2",
"1-3-4-3"=>"3-4-3",
"1-4-5-1"=>"4-5-1",
"1-4-3-3"=>"4-3-3",
"1-5-4-1"=>"5-4-1",
"1-5-3-2"=>"5-3-2"
);

$this->templates['content']->assign('usedJolly',Lineup::usedJolly($team,$this->currentMatchday));
$this->templates['content']->assign('module',$module);
$this->templates['content']->assign('moduleAllowed',$moduleAllowed);
$this->templates['content']->assign('players',$playersRole);
$this->templates['content']->assign('lineup', $lineup);
$this->templates['content']->assign('team',$team);
$this->templates['content']->assign('matchday',$matchday);
$this->templates['content']->assign('captains',array("idCaptain","idVCaptani","idVVCaptain"));
/*$this->templates['operation']->assign('squadre', Utente::getByField('idLega',$_SESSION['legaView']));
$this->templates['operation']->assign('squadra',$squadra);
$this->templates['operation']->assign('giornata',$giornata);
$this->templates['operation']->assign('formazioniPresenti',$formazioniPresenti);*/
}

public function update() {
try {
$filterTeam = $this->request->getParam('team_id', $_SESSION['team']->id);
$filterMatchday = $this->request->getParam('matchday_id', $this->currentMatchday->getId());

$team = Team::getById($filterTeam);
$matchday = Matchday::getById($filterMatchday);
if ($filterMatchday == $this->currentMatchday->id && $filterTeam == $_SESSION['team']->id) {
$regular = $this->request->getParam('regulare');
$notRegular = $this->request->getParam('notRegular');

$lineup = new Lineup();
//$formazione->setIdCapitano($this->request->getParam($name))
FirePHP::getInstance()->log($lineup);
$lineupOld = Lineup::getByTeamAndMatchday($filterTeam, $filterMatchday);
if(!is_null($lineupOld)) {
$lineup->setId($lineupOld->getId());
}

$lineup->setIdGiornata($this->currentMatchday->id);
$lineup->save(array('regular' => $regular, 'notRegular' => $notRegular));
$this->setFlash(self::FLASH_SUCCESS,'Formazione caricata correttamente');
}
} catch(FormException $e) {
$this->setFlash(self::FLASH_NOTICE, $e->getMessage());
}
$this->renderAction('lineups');
}

}


14 changes: 7 additions & 7 deletions app/controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
class PagesController extends ApplicationController {

public function home() {
$giornata = Models\Score::getMatchdayWithScores();
$matchday = Models\Score::getMatchdayWithScores();
$bestPlayer = NULL;
$bestPlayers = NULL;

if ($giornata > 0) {
foreach ($this->ruoli as $ruolo => $val) {
if ($matchday > 0) {
foreach ($this->roles as $key => $role) {

$bestPlayers[$ruolo] = Models\Member::getBestPlayerByGiornataAndRuolo($giornata, $ruolo);
$bestPlayer[$ruolo] = array_shift($bestPlayers[$ruolo]);
$bestPlayers[$key] = Models\Member::getBestByMatchdayIdAndRole($matchday, $role);
$bestPlayer[$key] = array_shift($bestPlayers[$key]);
}
}

Expand All @@ -26,8 +26,8 @@ public function home() {

$events = Models\Event::getEvents(NULL, NULL, 0, 5);

$this->templates['content']->assign('squadre', Models\Team::getByField('idLega', $_SESSION['legaView']));
$this->templates['content']->assign('giornata', $giornata);
$this->templates['content']->assign('teams', Models\Team::getByField('championship_id', 1));
$this->templates['content']->assign('matchday', $matchday);
$this->templates['content']->assign('bestPlayer', $bestPlayer);
$this->templates['content']->assign('bestPlayers', $bestPlayers);
$this->templates['content']->assign('articles', $articles);
Expand Down
47 changes: 47 additions & 0 deletions app/controllers/SelectionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Fantamanajer\Controllers;

use Fantamanajer\Models as Models;
use Lib\FormException;

class SelectionController extends ApplicationController {

public function update() {
if ($this->request->isXmlHttpRequest()) {
$this->response->setContentType("application/json");
}
if (($selection = Models\Selection::getByField('team_id', $_SESSION['team']->getId())) == FALSE) {
$selection = new Models\Selection();
$selection->setTeam($_SESSION['team']);
}

if ($_SESSION['logged']) {
try {
if ($this->request->getParam('submit') == 'Cancella acq.') {
$selection->setMemberNew(NULL);
$selection->setMemberOld(NULL);
if($selection->save()) {
echo '{"status":"' . self::FLASH_SUCCESS . '","message":"Cancellazione eseguita con successo"}';
//$this->setFlash(self::FLASH_SUCCESS, 'Cancellazione eseguita con successo');
}
} else {
if($selection->new_member_id == NULL || $selection->old_member_id == NULL)
echo '{"status":"' . self::FLASH_NOTICE . '","message":"Selezionare i giocatori"}';
elseif($selection->save()) {
echo '{"status":"' . self::FLASH_SUCCESS . '","message":"Cancellazione eseguita con successo"}';
//$this->setFlash(self::FLASH_SUCCESS,'Operazione eseguita con successo');
}
}
} catch (FormException $e) {
echo '{"status":"' . self::FLASH_NOTICE . '","message":"' . $e->getMessage() . '"}';
//$this->setFlash(self::FLASH_NOTICE, $e->getMessage());
}
$this->templates['content']->assign('selection', $selection);

//$this->redirectTo('teams_show', array('id' => $_SESSION['team']->getId()));
}

}
}

Loading

0 comments on commit e17ce26

Please sign in to comment.