/**
  * Store a newly created resource in storage.
  * POST /group
  *
  * @return Response
  */
 public function store($id)
 {
     //create sub team
     //return Redirect::action('SubController@create',$id)->with( 'notice', 'This action cannot be perform at this moment, please comeback soon.');
     $user = Auth::user();
     $club = $user->clubs()->FirstOrFail();
     $parent_team = Team::find($id);
     $uuid = Uuid::generate();
     $validator = Validator::make(Input::all(), Team::$rules_group);
     if ($validator->passes()) {
         $team = new Team();
         $team->id = $uuid;
         $team->name = Input::get('name');
         $team->season_id = $parent_team->season_id;
         $team->program_id = $parent_team->program_id;
         $team->description = $parent_team->description;
         $team->early_due = $parent_team->getOriginal('early_due');
         $team->early_due_deadline = $parent_team->early_due_deadline;
         $team->due = $parent_team->getOriginal('due');
         $team->plan_id = $parent_team->plan_id;
         $team->open = $parent_team->open;
         $team->close = $parent_team->close;
         $team->max = Input::get('max');
         $team->status = $parent_team->getOriginal('status');
         $team->parent_id = $parent_team->id;
         $team->club_id = $club->id;
         $team->allow_plan = 1;
         $status = $team->save();
         if ($status) {
             return Redirect::action('TeamController@show', $parent_team->id)->with('messages', 'Group created successfully');
         }
     }
     $error = $validator->errors()->all(':message');
     return Redirect::action('SubController@create', $id)->withErrors($validator)->withInput();
 }
 public static function join($id)
 {
     $player = self::get_user_logged_in();
     $Team = Team::find($id);
     $m = new Teammember(array('player_id' => $player->id, 'team_id' => $Team->id));
     $m->save();
     Redirect::to('/team', array('message' => 'Sinut on lisätty joukkueseen'));
 }
 public static function show($id)
 {
     self::check_logged_in();
     $user = self::get_user_logged_in();
     $event = Event::find($id);
     $team = Team::find($event->team_id);
     $member = Teammember::findByBoth($user->id, $team->id);
     View::make('Event/show.html', array('event' => $event, 'team' => $team, 'member' => $member));
 }
示例#4
0
 public function getTeams($id = NULL)
 {
     if ($id) {
         $team = Team::find($id);
         return View::make('home.team_individual')->with('team', $team);
     } else {
         $teams = Team::all_active()->get();
         return View::make('home.teams')->with('teams', $teams);
     }
 }
示例#5
0
 public static function findByPlayer($player_id)
 {
     $query = DB::connection()->prepare('SELECT team_id FROM Teammember WHERE player_id = :player_id');
     $query->execute(array('player_id' => $player_id));
     $rows = $query->fetchAll();
     $Team = array();
     foreach ($rows as $row) {
         $Team[] = Team::find($row['team_id']);
     }
     return $Team;
 }
示例#6
0
文件: Batch.php 项目: xJakub/LCE
    public function makeMatches() {

        $teams = Team::find('1=1');
        $teamIdByName = Model::pluck($teams, 'teamid', 'name');

        $week = 0;
        $matches = [];

        foreach (explode("\n", file_get_contents("matches.txt")) as $line) {
            $parts = explode("VS", $line);
            if (count($parts) == 1 && substr(trim($line), 0, 2) == '--') {
                $week++;
            }
            if (count($parts) != 2) continue;

            list($name1, $name2) = $parts;
            $name1 = trim($name1);
            $name2 = trim($name2);

            $match = Match::create();
            $match->team1id = $teamIdByName[$name1];
            $match->team2id = $teamIdByName[$name2];
            $match->week = $week;
            $matches[] = $match;

            if (!$match->team1id) {
                die("Equipo desconocido: $name1");
            }
            if (!$match->team2id) {
                die("Equipo desconocido: $name2");
            }

        }

        if (count($matches) >= 1 && count($matches) != count(Match::find('1=1'))) {
            Match::truncate(true);
            Model::saveAll($matches);
            ?>Enfrentamientos actualizados.<br><?
        }
        else {
            ?>No hay cambios en los enfrentamientos.<br><?
        }

    }
 /**
  * ログインしているかどうか
  */
 function isLogin()
 {
     if ($this->session->getIsStarted() && $this->session->itemAt('is_login') == 1) {
         // セッション情報取得
         $s_team = $this->session->itemAt('team');
         // ユーザモデル読み込み
         include_once APP_MODELS_PATH . 'team.php';
         // セッション情報からユーザ情報取得
         $obj = new Team();
         $obj->table_name = 'team';
         $team = $obj->find(array(':id' => $s_team['id']), 'WHERE id = :id');
         // セッション情報破棄
         $this->session->remove('team');
         // セッション再登録
         $this->session->add('team', $team[0]);
         return true;
     }
     return false;
 }
 /**
  * Show the form for creating a new resource.
  * GET /coach/create
  *
  * @return Response
  */
 public function create($id)
 {
     $user = Auth::user();
     $club = $user->clubs()->FirstOrFail();
     $followers = $club->followers;
     $usersData = [];
     //get player from follower
     foreach ($followers as $follower) {
         $fuser = User::find($follower->user_id);
         if ($fuser) {
             $data['fullname'] = $fuser->profile->firstname . " " . $fuser->profile->lastname;
             $data['user'] = $fuser;
             $usersData[] = $data;
         }
     }
     //return $usersData;
     $title = 'League Together - ' . $club->name . ' Teams';
     $team = Team::find($id);
     $plan = $club->plans()->lists('name', 'id');
     return View::make('app.club.coach.create')->with('page_title', $title)->with('team', $team)->with('club', $club)->with('followers', $followers)->with('plan', $plan)->with('usersData', json_encode($usersData))->withUser($user);
 }
 public function team($id)
 {
     //add security to avoid stealing of information
     $user = Auth::user();
     Excel::create('roster', function ($excel) use($id) {
         $excel->sheet('Sheetname', function ($sheet) use($id) {
             $event = Team::find($id);
             $team = array();
             if ($event->children->count() > 0) {
                 foreach ($event->children as $e) {
                     foreach ($e->members as $member) {
                         $team[] = $member;
                     }
                 }
             } else {
                 $team = Member::where('team_id', '=', $id)->with('team')->get();
             }
             $sheet->setOrientation('landscape');
             $sheet->loadView('export.lacrosse.roster', ['members' => $team]);
         });
     })->download('xlsx');
 }
示例#10
0
 public function postView()
 {
     $rules = array('id' => 'required|exists:teams,id', 'name' => 'required|max:255|unique:teams,name,' . Input::get('id'), 'tag' => 'required|max:255', 'upload-logo' => 'max:2500');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::action('Admin_TeamsController@getView', array(Input::get('id')))->withInput()->withErrors($validator);
     } else {
         $team = Team::find(Input::get('id'));
         $team->name = Input::get('name');
         $team->tag = Input::get('tag');
         if (Input::hasFile('upload-logo')) {
             $oldlogopath = $this->dir . $team->logo;
             File::delete($oldlogopath);
             $logofile = Input::file('upload-logo');
             $logofileext = $logofile->getClientOriginalExtension();
             $logo_name = "Team_" . Str::limit(md5(Input::get('name')), 10, false) . '-' . Str::limit(md5(time()), 10, false) . "_" . Str::slug(Input::get('name')) . "." . $logofileext;
             $team->logo = $logo_name;
             $logofile->move($this->dir, $logo_name);
         }
         $team->save();
         return Redirect::action('Admin_TeamsController@getIndex');
     }
 }
 /**
  * Update the specified resource in storage.
  * PUT /members/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($team, $id)
 {
     $team = Team::find($team);
     $member = Member::find($id);
     //optional field - if Null take the default value from the team
     // if(!Input::get('early_due')){
     // 	$member->early_due = $team->early_due;
     // }else{
     // 	$member->early_due = Input::get('early_due');
     // }
     // if(!Input::get('early_due_deadline')){
     // 	$member->early_due_deadline = $team->early_due_deadline;
     // }else{
     // 	$member->early_due_deadline = Input::get('early_due_deadline');
     // }
     // if(!Input::get('due')){
     // 	$member->due = $team->due;
     // }else{
     // 	$member->due = Input::get('due');
     // }
     // $member->save();
     $member->team_id = Input::get('team_id');
     $member->save();
     // Redirect with success message.
     return Redirect::action('MemberController@edit', array($member->team->id, $member->id))->with('notice', 'Member updated successfully');
 }
示例#12
0
文件: Team.php 项目: xJakub/LCE
 public static function getCount()
 {
     static $count = null;
     if ($count === null) {
         $count = count(Team::find('1=1'));
     }
     return $count;
 }
 public function doRefund($id)
 {
     $user = Auth::user();
     $club = $user->clubs()->FirstOrFail();
     $uuid = Uuid::generate();
     $payment = Payment::where('club_id', '=', $club->id)->where('transaction', '=', $id)->FirstOrFail();
     $user_parent = User::find($payment->user_id);
     $uuid = Uuid::generate();
     if ($payment->event_type) {
         $participant = Participant::Find($payment->items->first()->participant_id);
         $event = Evento::find($participant->event->id);
     } else {
         $participant = Member::Find($payment->items->first()->member_id);
         $event = Team::find($participant->team->id);
     }
     $player = Player::Find($participant->player->id);
     //$amount = $payment->getOriginal('subtotal');
     $amount = Input::get('amount');
     if ($amount > $payment->getOriginal('subtotal')) {
         return Redirect::action('AccountingController@refund', $payment->transaction)->with('error', "You cannot refund more than " . $payment->getOriginal('subtotal'));
     }
     if ($amount <= 0 || $amount == '') {
         return Redirect::action('AccountingController@refund', $payment->transaction)->with('error', "Amount must be more than 0");
     }
     if ($amount > 0) {
         $param = array('transactionid' => $payment->transaction, 'club' => $club->id, 'amount' => number_format($amount, 2, ".", ""));
         $transaction = $payment->refund($param);
         if ($transaction->response == 3 || $transaction->response == 2) {
             return Response::json($transaction);
             return Redirect::action('AccountingController@transaction', $payment->transaction)->with('error', $transaction->responsetext);
         } else {
             $payment1 = new Payment();
             $payment1->id = $uuid;
             $payment1->customer = $user_parent->profile->customer_vault;
             $payment1->transaction = $transaction->transactionid;
             $payment1->subtotal = -$transaction->total;
             $payment1->total = -$transaction->total;
             $payment1->club_id = $club->id;
             $payment1->user_id = $user_parent->id;
             $payment1->player_id = $player->id;
             $payment1->type = $transaction->type;
             $sale = new Item();
             $sale->description = $event->name . " ({$transaction->type})";
             $sale->quantity = 1;
             $sale->price = -$transaction->total;
             $sale->payment_id = $uuid;
             if ($payment->event_type) {
                 $payment1->event_type = $event->type_id;
             } else {
                 $payment1->event_type = NULL;
             }
             $payment1->save();
             $sale->save();
             $data = array('club' => $club, 'transaction' => $transaction, 'user' => $user, 'contact' => $user_parent);
             //send notification for refund confirmation
             $mail = Mail::send('emails.receipt.refund', $data, function ($message) use($user, $club, $user_parent) {
                 $message->to($user_parent->email)->subject("Refund Confirmation | " . $club->name);
                 foreach ($club->users()->get() as $value) {
                     $message->bcc($value->email, $club->name);
                 }
             });
         }
         //end of transaction result
     }
     //end of amount test
     return Redirect::action('AccountingController@transaction', $payment->transaction);
 }
 public function doDuplicate($id)
 {
     $team = Team::find($id);
     $uuid = Uuid::generate();
     $copyTeam = $team->replicate();
     $copyTeam->id = $uuid;
     $status = $copyTeam->save();
     if ($status) {
         return Redirect::action('TeamController@index');
     }
     return Redirect::action('TeamController@dupliate', $team->id)->withErrors($status);
 }
示例#15
0
文件: filters.php 项目: robinchow/rms
        return Redirect::to('rms/account/login')->with('warning', 'You must login in to access this area of the site');
    }
});
Route::filter('exec', function () {
    if (!Auth::User()->admin && !Auth::User()->is_currently_part_of_exec()) {
        return Redirect::to('rms/account')->with('warning', 'You are not permitted access. Please login as an admin');
    }
});
Route::filter('admin', function () {
    if (!Auth::User()->admin) {
        return Redirect::to('rms/account')->with('warning', 'You are not permitted access. Please login as an admin');
    }
});
Route::filter('view_team', function () {
    $team_id = Request::segment(4);
    $team = Team::find($team_id);
    if (!Auth::User()->admin && !Auth::User()->is_currently_part_of_exec() && $team->privacy == 1 && !Auth::User()->is_part_of_team(Year::current_year()->id, $team_id)) {
        return Redirect::to('rms/account')->with('warning', 'You are not permitted access. Please login as an admin');
    }
});
Route::filter('manage_team', function () {
    $team_id = Request::segment(4);
    if (!Auth::User()->can_manage_team($team_id)) {
        return Redirect::to('rms/account')->with('warning', 'You are not permitted access. Please login as an admin');
    }
});
Route::filter('signed_up_for_camp', function () {
    if (Auth::user()->has_signed_up_for_camp()) {
        return Redirect::to('rms/camp/registrations/edit');
    }
});
示例#16
0
 public function hof()
 {
     $data['page'] = 'halloffame';
     $teams = array();
     // get yg plg aktif di vote
     $total_votes = Vote::select(DB::raw('count(votes.id) as total'), 'teams.name', 'teams.id')->join('users', 'votes.user_id', '=', 'users.id')->join('teams', 'users.team_id', '=', 'teams.id')->groupBy('teams.id')->orderBy('total', 'desc')->take(5)->get();
     if ($total_votes) {
         foreach ($total_votes as $value) {
             $teams[$value->id] = $value->total;
         }
     }
     // get total komen aktif
     $total_comments = Comment::select(DB::raw('count(comments.id) as total'), 'teams.name', 'teams.id')->join('users', 'comments.user_id', '=', 'users.id')->join('teams', 'users.team_id', '=', 'teams.id')->groupBy('teams.id')->orderBy('total', 'desc')->take(5)->get();
     if ($total_comments) {
         foreach ($total_comments as $value) {
             if (isset($teams[$value->id])) {
                 $teams[$value->id] = $teams[$value->id] + $value->total;
             } else {
                 $teams[$value->id] = $value->total;
             }
         }
     }
     // get total post
     $total_posts = Post::select(DB::raw('count(posts.id) as total'), 'teams.name', 'teams.id')->join('users', 'posts.user_id', '=', 'users.id')->join('teams', 'users.team_id', '=', 'teams.id')->groupBy('teams.id')->orderBy('total', 'desc')->take(5)->get();
     if ($total_posts) {
         foreach ($total_posts as $value) {
             if (isset($teams[$value->id])) {
                 $teams[$value->id] = $teams[$value->id] + $value->total;
             } else {
                 $teams[$value->id] = $value->total;
             }
         }
     }
     if (count($teams) > 0) {
         $winningteam = array_search(max($teams), $teams);
         $data['clubwinner'] = Team::find($winningteam);
     } else {
         $data['clubwinner'] = null;
     }
     $startingeleven = array();
     $data['defenders'] = array();
     $data['assisters'] = array();
     $data['attackers'] = array();
     // player
     $defenders = User::select(array('users.id', 'users.username', 'jersey_image', 'jersey_no', 'profile_pic', DB::raw('count(comments.id) as total')))->join('comments', 'users.id', '=', 'comments.user_id')->join('teams', 'teams.id', '=', 'users.team_id')->orderBy('total', 'desc')->groupBy('users.id')->where('comments.type', 'defense')->take(5)->get();
     $assisters = User::select(array('users.id', 'users.username', 'jersey_image', 'jersey_no', 'profile_pic', DB::raw('count(comments.id) as total')))->join('comments', 'users.id', '=', 'comments.user_id')->join('teams', 'teams.id', '=', 'users.team_id')->orderBy('total', 'desc')->groupBy('users.id')->where('comments.type', 'assist')->take(3)->get();
     $attackers = User::select(array('users.id', 'users.username', 'jersey_image', 'jersey_no', 'profile_pic', DB::raw('count(comments.id) as total')))->join('comments', 'users.id', '=', 'comments.user_id')->join('teams', 'teams.id', '=', 'users.team_id')->orderBy('total', 'desc')->groupBy('users.id')->where('comments.type', 'attack')->take(3)->get();
     if ($defenders) {
         foreach ($defenders as $value) {
             $startingeleven[$value->id] = array('name' => $value->username, 'no' => $value->jersey_no, 'pic' => $value->profile_pic, 'jersey_image' => $value->jersey_image, 'total' => $value->total, 'position' => 'D');
         }
     }
     if ($assisters) {
         foreach ($assisters as $value) {
             if (isset($startingeleven[$value->id]) && $startingeleven[$value->id]['total'] > $value->total) {
                 $startingeleven[$value->id] = array('name' => $value->username, 'no' => $value->jersey_no, 'pic' => $value->profile_pic, 'jersey_image' => $value->jersey_image, 'total' => $value->total, 'position' => 'M');
             } else {
                 $startingeleven[$value->id] = array('name' => $value->username, 'no' => $value->jersey_no, 'pic' => $value->profile_pic, 'jersey_image' => $value->jersey_image, 'total' => $value->total, 'position' => 'M');
             }
         }
     }
     if ($attackers) {
         foreach ($attackers as $value) {
             if (isset($startingeleven[$value->id]) && $startingeleven[$value->id]['total'] > $value->total) {
                 $startingeleven[$value->id] = array('name' => $value->username, 'no' => $value->jersey_no, 'pic' => $value->profile_pic, 'jersey_image' => $value->jersey_image, 'total' => $value->total, 'position' => 'F');
             } else {
                 $startingeleven[$value->id] = array('name' => $value->username, 'no' => $value->jersey_no, 'pic' => $value->profile_pic, 'jersey_image' => $value->jersey_image, 'total' => $value->total, 'position' => 'F');
             }
         }
     }
     $noplayer = array('name' => 'No player', 'no' => '0', 'pic' => '', 'jersey_image' => 'player_dummy.png', 'total' => 0);
     if (count($startingeleven) > 0) {
         foreach ($startingeleven as $se) {
             if ($se['position'] == 'F') {
                 array_push($data['attackers'], $se);
             }
             if ($se['position'] == 'M') {
                 array_push($data['assisters'], $se);
             }
             if ($se['position'] == 'D') {
                 array_push($data['defenders'], $se);
             }
         }
         if (count($data['defenders']) < 5) {
             $selisih = 5 - count($data['defenders']);
             for ($i = 0; $i < $selisih; $i++) {
                 array_push($data['defenders'], $noplayer);
             }
         }
         if (count($data['assisters']) < 3) {
             $selisih = 3 - count($data['assisters']);
             for ($i = 0; $i < $selisih; $i++) {
                 array_push($data['assisters'], $noplayer);
             }
         }
         if (count($data['attackers']) < 3) {
             $selisih = 3 - count($data['attackers']);
             for ($i = 0; $i < $selisih; $i++) {
                 array_push($data['attackers'], $noplayer);
             }
         }
     } else {
         for ($i = 0; $i < 5; $i++) {
             array_push($data['defenders'], $noplayer);
         }
         for ($i = 0; $i < 3; $i++) {
             array_push($data['attackers'], $noplayer);
             array_push($data['assisters'], $noplayer);
         }
     }
     return View::make('halloffame2')->with($data);
 }
示例#17
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $team = Team::find($id);
     $team->delete();
 }
示例#18
0
文件: Ranking.php 项目: xJakub/LCE
    /**
     * @return void
     */
    public function show()
    {
        $matches = Match::find('seasonid = ?', [$this->season->seasonid]);
        $wins = [];
        $games = [];
        $kills = [];
        $deaths = [];
        $mainPositions = [];
        $playoffsDefeat = [];
        $playoffsLast = [];

        foreach($this->season->getTeams() as $team) {
            $wins[$team->teamid] = 0;
            $kills[$team->teamid] = 0;
            $games[$team->teamid] = 0;
            $deaths[$team->teamid] = 0;
        }

        foreach($matches as $match) {
            if ($match->week > $this->season->mainweeks) continue;
            if (!$this->season->weekIsPublished($match->week)) continue;
            if ($match->isDelayed()) continue;

            $winner = $match->getWinner();
            if (!$winner) continue;
            $looser = $match->getLooser();

            $games[$winner]++;
            $games[$looser]++;

            $wins[$winner]++;

            $kills[$winner] += 6;
            $deaths[$looser] += 6;

            $looserKills = $match->getLooserKills();
            $kills[$looser] += $looserKills;
            $deaths[$winner] += $looserKills;
        }

        foreach(array_keys($kills) as $teamid) {
            $tiebreakers[$teamid] = array($wins[$teamid], $kills[$teamid]-$deaths[$teamid], $kills[$teamid], -$deaths[$teamid]);
        }
        arsort($tiebreakers);

        $lastPos = 0;
        $lastTiebreakers = null;
        foreach(array_keys($tiebreakers) as $pos => $teamid) {
            if ($lastTiebreakers != $tiebreakers[$teamid]) {
                $lastPos = $pos;
            }
            $mainPositions[$teamid] = $lastPos;
            $lastTiebreakers = $tiebreakers[$teamid];
        }

        foreach($matches as $match) {
            if ($match->week <= $this->season->mainweeks) continue;
            if (!$this->season->weekIsPublished($match->week)) continue;
            if ($match->isDelayed()) continue;

            $winner = $match->getWinner();
            if (!$winner) continue;
            $looser = $match->getLooser();

            $playoffsDefeat[$looser] = -$match->week;
            $playoffsLast[$winner] = $match->week;
            $playoffsLast[$looser] = $match->week;

            $playoffsPlayed[$winner] = 1;
            $playoffsPlayed[$looser] = 1;

            $games[$winner]++;
            $games[$looser]++;

            $wins[$winner]++;

            $kills[$winner] += 6;
            $deaths[$looser] += 6;

            $looserKills = $match->getLooserKills();
            $kills[$looser] += $looserKills;
            $deaths[$winner] += $looserKills;
        }

        foreach(array_keys($kills) as $teamid) {
            $tiebreakers[$teamid] = array($playoffsLast[$teamid]*1, $playoffsDefeat[$teamid]*1, -$mainPositions[$teamid]);
        }
        arsort($tiebreakers);


        ?>
        <table>
            <thead><tr>
                <td>Puesto</td>
                <td>Equipo</td>
                <td>Combates</td>
                <td>Victorias</td>
                <td>Derrotas</td>
                <td>Debilitados</td>
                <td>Perdidos</td>
            </tr></thead>

            <?
            /**
             * @var $teams Team[]
             */
            $teams = Model::indexBy(Team::find('1=1'), 'teamid');

            $lastTiebreakers = null;
            $lastPos = 0;
            foreach(array_keys($tiebreakers) as $pos => $teamid) {
                $team = $teams[$teamid];
                if ($lastTiebreakers != $tiebreakers[$teamid]) {
                    $lastPos = $pos;
                }

                ?>
                <tr>
                    <td><?= $lastPos+1 ?>º
                        <? if (isset($mainPositions[$teamid]) && $lastPos != $mainPositions[$teamid]) { ?>
                            <div style="height: 4px"></div>
                            <i title="<?= $mainPositions[$teamid]+1 ?>º en las jornadas" style="cursor: pointer; color: #666">
                                <?= $mainPositions[$teamid]+1 ?>º
                            </i>
                        <? } ?>
                    </td>
                    <td style="text-align: left">
                        <div class="teamimg64">
                            <img src="/<?=$team->getImageLink(64, 64)?>">
                        </div>
                        <a href="/<?=$this->season->getLink()?>/equipos/<?=$team->getLink()?>/" class="inblock" style="vertical-align:middle">
                            <?= $team->name ?>
                        </a></td>
                    <td><?= $games[$teamid] ?></td>
                    <td><b><?= $wins[$teamid]*1 ?></b></td>
                    <td><?= $games[$teamid]-$wins[$teamid] ?></td>
                    <td><?= $kills[$teamid] ?></td>
                    <td><?= $deaths[$teamid] ?></td>
                </tr>
                <?
                $lastTiebreakers = $tiebreakers[$teamid];
            }
            ?>
        </table>
        <?
    }
示例#19
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     $team = Team::find($id);
     Team::destroy($id);
     if (file_exists(public_path('teams/' . $team->image))) {
         unlink(public_path('teams/' . $team->image));
     }
     return redirect('team');
 }
示例#20
0
文件: User.php 项目: robinchow/rms
 public function can_manage_team($team_id)
 {
     if ($this->admin || $this->is_currently_part_of_exec()) {
         return true;
     } else {
         $team = Team::find($team_id);
         $result = $team->users()->where('users.id', '=', $this->id)->where('status', '=', 'head')->where('year_id', '=', Year::current_year()->id)->get();
         return count($result) != 0;
     }
 }
示例#21
0
 public function mypage()
 {
     $data['page'] = 'me';
     $data['team'] = Team::find(Auth::user()->team_id);
     return View::make('user.profile')->with($data);
 }
示例#22
0
 public function userpage($username)
 {
     $data['page'] = '';
     $data['pagetype'] = 'profile';
     $data['userdata'] = User::where('username', $username)->first();
     if (empty($data['userdata'])) {
         App::abort(404);
     }
     $userid = $data['userdata']->id;
     $teamid = $data['userdata']->team_id;
     $data['profileid'] = '_' . $userid;
     $data['images'] = Post::where('user_id', $userid)->orderBy('created_at', 'desc');
     $data['totalposts'] = Post::where('user_id', $userid)->count();
     $data['team'] = empty($teamid) ? '' : Team::find($teamid);
     $data['attack'] = Comment::where('user_id', $userid)->where('type', 'attack')->count();
     $data['assist'] = Comment::where('user_id', $userid)->where('type', 'assist')->count();
     $data['defense'] = Comment::where('user_id', $userid)->where('type', 'defense')->count();
     if (Auth::user()) {
         $data['images'] = $data['images']->with(array('votes' => function ($query) use($userid) {
             $query->where('user_id', $userid);
         }))->take(12)->get();
     } else {
         $data['images'] = $data['images']->take(12)->get();
     }
     return View::make('scrollpost')->with($data);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $startDate = Carbon::now();
     $from = Carbon::now()->hour(0)->minute(0)->second(0);
     $to = Carbon::now()->hour(23)->minute(59)->second(59);
     $schedules = SchedulePayment::where('status', 0)->whereBetween('date', array($from, $to))->with('member.user.profile')->get();
     //$schedules = SchedulePayment::where('status', 0)->with('member.user.profile')->get();
     $errors = array();
     $totalAmount = array();
     $errorAmount = array();
     //save daylog
     $dayLog = new ScheduleDailyLog();
     $dayLog->started_on = Carbon::now()->toDateTimeString();
     $dayLog->payments_count = count($schedules);
     $dayLog->save();
     Cart::destroy();
     foreach ($schedules as $schedule) {
         try {
             $vault = $schedule->member->user->profile->customer_vault;
             $user = User::find($schedule->member->user->id);
             $player = Player::find($schedule->member->player->id);
             $club = Club::find($schedule->club_id);
             $team = Team::find($schedule->member->team_id);
             $uuid = Uuid::generate();
             $member = Member::find($schedule->member->id);
             $history = SchedulePayment::find($schedule->id);
             //manually login user out before login new user
             Auth::logout();
             //manually login user
             Auth::login($user);
             //clear cart content
             Cart::destroy();
             //set cart item
             $itemCart = array('id' => $team->id, 'name' => "Scheduled payment for " . $team->name, 'price' => $schedule->subtotal, 'quantity' => 1, 'organization' => $club->name, 'organization_id' => $club->id, 'player_id' => $player->id, 'user_id' => $user->id, 'type' => 'full', 'autopay' => true);
             Cart::insert($itemCart);
             //check if vault exist
             if ($vault) {
                 $param = array('customer_vault_id' => $vault, 'discount' => null, 'club' => $club->id);
                 $payment = new Payment();
                 $transaction = $payment->sale($param);
                 //temp json_decode(json_encode($array), FALSE);
                 //$transaction = json_decode(json_encode(array('response' => 1, 'total'=>$schedule->total, 'fee'=>$schedule->fee)), FALSE);
                 if ($transaction->response == 3 || $transaction->response == 2) {
                     $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => $transaction->transactionid . ' : ' . $transaction->responsetext, 'error_amount' => $schedule->total, 'daily_log_id' => $dayLog->id);
                     array_push($errorAmount, number_format($schedule->total, 2));
                     //Email error
                     $emailerrorstatus = $payment->error($transaction, $club->id, $player->id);
                 } else {
                     array_push($totalAmount, number_format($transaction->total, 2));
                     $payment->id = $uuid;
                     $payment->customer = $vault;
                     $payment->transaction = $transaction->transactionid;
                     $payment->subtotal = $transaction->subtotal;
                     $payment->service_fee = $transaction->fee;
                     $payment->total = $transaction->total;
                     $payment->promo = $transaction->promo;
                     $payment->tax = $transaction->tax;
                     $payment->discount = $transaction->discount;
                     $payment->club_id = $club->id;
                     $payment->user_id = $user->id;
                     $payment->player_id = $player->id;
                     $payment->event_type = null;
                     $payment->type = $transaction->type;
                     $payment->save();
                     //Email receipt
                     $payment->receipt($transaction, $club->id, $player->id);
                     $sale = new Item();
                     $sale->description = $itemCart['name'];
                     $sale->quantity = $itemCart['quantity'];
                     $sale->price = $itemCart['price'];
                     $sale->fee = $transaction->fee;
                     $sale->member_id = $member->id;
                     $sale->team_id = $team->id;
                     $sale->payment_id = $uuid;
                     $sale->save();
                     //update schedule
                     $history->status = 2;
                     $history->save();
                 }
             } else {
                 //save error that vault didnt exist
                 $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => 'Customer Vault not found', 'error_amount' => number_format($schedule->total, 2), 'daily_log_id' => $dayLog->id);
                 array_push($errorAmount, number_format($schedule->total, 2));
             }
         } catch (Exception $e) {
             //save internal error
             $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => $e, 'error_amount' => number_format($schedule->total, 2), 'daily_log_id' => $dayLog->id);
             array_push($errorAmount, number_format($schedule->total, 2));
         }
     }
     //end of foreach schedule
     //save log for everything done
     $dayLogEnd = ScheduleDailyLog::find($dayLog->id);
     $dayLogEnd->ended_on = Carbon::now()->toDateTimeString();
     $dayLogEnd->successful_count = Count($totalAmount);
     $dayLogEnd->error_count = Count($errors);
     $dayLogEnd->total_amount = array_sum($totalAmount);
     $dayLogEnd->total_amount_error = array_sum($errorAmount);
     $dayLogEnd->save();
     //save log for errors
     if (Count($errors) > 0) {
         foreach ($errors as $errorItem) {
             $scheduleError = new ScheduleDailyError();
             $scheduleError->error_description = $errorItem['error_description'];
             $scheduleError->error_amount = $errorItem['error_amount'];
             $scheduleError->payment_schedule_id = $errorItem['payment_schedule_id'];
             $scheduleError->daily_log_id = $dayLogEnd->id;
             $scheduleError->save();
         }
     }
     return Log::info($errors);
 }
 public function milestoneCreatorImage($team_id)
 {
     $team_info = Team::find($team_id);
     $leader = $team_info->leader_id;
     $user = User::find($leader);
     $creator_image = $user->image_path;
     return $creator_image;
 }
示例#25
0
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }
        if (!TwitterAuth::getBotConfig()) {
            ?>Error: el bot no está configurado<br><?
            return;
            }

        if (HTMLResponse::fromPOST('csrf', '') && strlen(trim(HTMLResponse::fromPOST('message','')))) {
            if ($_SESSION['csrf'] != HTMLResponse::fromPOST('csrf', '')) {
                ?>Error: código de seguridad incorrecto.<br><br><?
            }
            else {
                $message = HTMLResponse::fromPOST('message');
                ?>
                <b>Mensaje</b>: <?=htmlentities($message)?><br><br>

<?
                foreach(Team::find('ismember order by username asc') as $team) {
                    $lowname = strtolower($team->username);
                    if (HTMLResponse::fromPOST("check{$lowname}", '')) {
                        $ok = false;

                        $ok = !!TwitterAuth::botSendPrivateMessage($lowname, $message);

                        ?>-<?=$team->username?>:
                        <?= $ok?'Enviado correctamente':'Error en el envío' ?>
                        <br>
                        <?
                    }
                }
                ?><br><br><?
                return;
            }
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }

        ?><div style="max-width: 640px; margin: 0 auto">
        <form action="<?=HTMLResponse::getRoute()?>" method="post">
            <b>Texto del comunicado (será enviado por MD en Twitter):</b><br>
            <textarea style="width: 320px" name="message"></textarea><br>
            <br>
            <b>Destinatarios del comunicado (
                <a href="javascript:void(0)" onclick="$(this).closest('div').find('input[type=checkbox]').attr('checked','checked')">
                    seleccionar todos
                </a>
                ):</b><br>
            <?
            foreach(Team::find('ismember order by username asc') as $team) {
                $lowname = strtolower($team->username);
                ?>
                <div class="inblock" style="margin: 6px; text-align: left; width: 180px">
                    <div class="inblock middle">
                        <input id="check<?=$lowname?>"type="checkbox" name="check<?=$lowname?>">
                    </div>
                    <div class="inblock middle">
                        <label for="check<?=$lowname?>">
                            <?= $team->username ?><br>
                            <span style="font-style:italic; color: #666">
                                <?= $team->name ?>
                            </span>
                        </label>
                    </div>
                </div>
                <?
            }
            ?></div><br>
            <input type="hidden" name="csrf" value="<?= $csrf ?>">
            <button type="submit">Enviar comunicado</button>
        </form><br><br><?
    }
示例#26
0
 public function deleteTeam($id)
 {
     $team = Team::find($id);
     $team->delete();
     Session::flash('success', 'Team deleted');
     return Redirect::to('admin/teams');
 }
示例#27
0
    /**
     * @return void
     */
    public function show()
    {
        $matches = Match::find('seasonid = ? and result != 0', [$this->season->seasonid]);
        $matches = Model::indexBy($matches, 'matchid');

        $teams = Model::indexBy(Team::find('1=1'), 'teamid');

        $matchWinner = [];

        foreach($matches as $match) {
            if ($this->season->weekIsPublished($match->week) && !$match->isDelayed()) {
                $matchWinner[$match->matchid] = $match->getWinner();
            }
        }

        $totalBets = [];
        $correctBets = [];

        $usernames = [];
        $avatars = Model::pluck(Avatar::find('1=1'), 'url', 'userid');

        foreach(Bet::find('1=1') as $bet) {
            if (isset($matchWinner[$bet->matchid])) {
                if ($bet->teamid && $matchWinner[$bet->matchid] == $bet->teamid) {
                    $correctBets[$bet->userid]++;
                }
                $totalBets[$bet->userid]++;
            }
            if ($bet->username) {
                $usernames[$bet->userid] = $bet->username;
            }
        }

        $tiebreakers = [];
        foreach(array_keys($correctBets) as $userid) {
            $tiebreakers[$userid] = [-$correctBets[$userid], $totalBets[$userid], strtolower($usernames[$userid])];
        }
        asort($tiebreakers);


        if (TwitterAuth::isLogged()) {
            $userid = TwitterAuth::getUserId();
            $userBets = Bet::find('userid = ? order by matchid desc', [$userid]);

            $userpos = array_search($userid, array_keys($tiebreakers));
            $userpos = ($userpos === FALSE) ? 0 : $userpos+1;

            ?>
            <div class="inblock" style="text-align: left; margin-right: 20px">
                <h2>Tus estadísticas</h2>
                <table>
                    <thead>
                    <tr>
                        <td>Puesto</td>
                        <td>Nombre</td>
                        <td>Aciertos</td>
                        <td>Fallos</td>
                    </tr>
                    </thead>
                    <tr>
                        <td><?= $userpos ?>º</td>
                        <td style="text-align: left">
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <img src="<?= htmlentities($avatars[$userid]) ?>" style="width:40px; height:40px; border-radius: 20px">
                                </a>
                            </div>
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <?= htmlentities($usernames[$userid]) ?>
                                    <? if (!isset($usernames[$userid])) echo "<i>$userid</i>"; ?>
                                </a>
                            </div>
                        </td>
                        <td><?= $correctBets[$userid] ?></td>
                        <td><?= $totalBets[$userid]-$correctBets[$userid] ?></td>
                    </tr>
                </table>

                <h2>Tus apuestas</h2>
                <table>
                    <thead>
                    <tr>
                        <td>Jornada</td>
                        <td>Enfrentamiento</td>
                        <td>Acierto</td>
                    </tr>
                    </thead>
                    <? foreach($userBets as $bet) {
                        if (!isset($matches[$bet->matchid])) continue;
                        /**
                         * @var $match Match
                         */
                        $match = $matches[$bet->matchid];
                        if (!$match->isPublished() || $match->isDelayed()) continue;

                        $team1 = $teams[$match->team1id];
                        $team2 = $teams[$match->team2id];

                        $success = $match->getWinner() == $bet->teamid;
                        ?>
                        <tr>
                            <td><?= $match->week ?></td>
                            <td>
                                <div class="inblock">
                                    <div class="teamimg64">
                                        <img src="/<?= $team1->getImageLink(64, 64) ?>" class="<?= $match->getWinner() == $team1->teamid ? '' : 'grayscale' ?>">
                                    </div>
                                    <? if ($bet->teamid == $team1->teamid) { ?>
                                        <br><i style="font-size:11px">Votado</i>
                                    <? } ?>
                                </div>

                                <div class="inblock" style="line-height: 64px; margin: 0px 4px">
                                    VS
                                </div>

                                <div class="inblock">
                                    <div class="teamimg64">
                                        <img src="/<?= $team2->getImageLink(64, 64) ?>" class="<?= $match->getWinner() == $team2->teamid ? '' : 'grayscale' ?>">
                                    </div>
                                    <? if ($bet->teamid == $team2->teamid) { ?>
                                        <br><i style="font-size:11px">Votado</i>
                                    <? } ?>
                                </div>
                            </td>
                            <td>
                                <?= $success
                                    ? '<div class="success-icon">&#x2714;</div>'
                                    : '<div class="fail-icon">&#x2718</div>' ?>
                            </td>

                        </tr>
                        <?
                    } ?>
                </table>
            </div>
            <?
        }


        ?>
        <div class="inblock">
            <h2>Clasificación</h2>
            <table>
                <thead>
                <tr>
                    <td>Puesto</td>
                    <td>Nombre</td>
                    <td>Aciertos</td>
                    <td>Fallos</td>
                </tr>
                </thead>

                <?
                $lastTiebreakers = null;
                $lastPos = 0;
                foreach(array_keys($tiebreakers) as $pos => $userid) {
                    unset($tiebreakers[$userid][2]);

                    if ($lastTiebreakers != $tiebreakers[$userid]) {
                        $lastPos = $pos;
                    }

                    if (!isset($avatars[$userid])) {
                        Avatar::setUsersAvatar($userid, $usernames[$userid]);
                    }
                    ?>
                    <tr>
                        <td><?= $lastPos+1 ?>º</td>
                        <td style="text-align: left">
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <img src="<?= htmlentities($avatars[$userid]) ?>" style="width:40px; height:40px; border-radius: 20px">
                                </a>
                            </div>
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <?= htmlentities($usernames[$userid]) ?>
                                    <? if (!isset($usernames[$userid])) echo "<i>$userid</i>"; ?>
                                </a>
                            </div>
                        </td>
                        <td><?= $correctBets[$userid] ?></td>
                        <td><?= $totalBets[$userid]-$correctBets[$userid] ?></td>
                    </tr>
                    <?
                    $lastTiebreakers = $tiebreakers[$userid];
                }
                ?>
            </table>
        </div>
        <?
    }
 public function PaymentRemoveCartItemTeam($club, $id)
 {
     $club = Club::find($club);
     $team = Team::find($id);
     Cart::destroy();
     return Redirect::action('ClubPublicController@paymentSelectTeam', array($club->id, $team->id));
 }
示例#29
0
文件: Team.php 项目: agloa/tournament
 /**
  * Retrieve team object based on id.
  *
  * It also stores all the retrieved values in the default array.
  *
  * @param int $teamID
  * @param array $defaults
  *   (reference ) an assoc array to hold the flattened values.
  *
  * @return team
  */
 public static function getTeam($teamID, &$defaults)
 {
     $params = array('id' => $teamID);
     $team = new Team();
     $team->copyValues($params);
     if ($team->find(TRUE)) {
         CRM_Core_DAO::storeValues($team, $defaults);
     }
     // lookup competitions from custom data table
     // Retrieve team competitions
     $query = "SELECT entity_id AS ID, " . self::$_E . " AS E, " . self::$_O . " AS O, " . self::$_L . " AS L, " . self::$_P . " AS P, " . self::$_M . " AS M, " . self::$_A . " AS A, " . self::$_W . " AS W " . "FROM " . self::$_customDataTableName . " AS team_games WHERE `entity_id` = %1\r\n\t\t";
     $params = array(1 => array($teamID, 'Integer'));
     $records = CRM_Core_DAO::executeQuery($query, $params);
     while ($records->fetch()) {
         $team->competitions['E'] = $records->E;
         $team->competitions['O'] = $records->O;
         $team->competitions['L'] = $records->L;
         $team->competitions['P'] = $records->P;
         $team->competitions['M'] = $records->M;
         $team->competitions['A'] = $records->A;
         $team->competitions['W'] = $records->W;
     }
     $team->players = self::getMember($teamID);
     return $team;
 }
示例#30
0
 public function get_delete($id)
 {
     $team = Team::find($id)->delete();
     return Redirect::to('rms/teams')->with('status', 'Successful Removed Team');
 }