public function register()
 {
     // user is alredy logged in (so no need for registering)
     if (!empty(Session::get('team'))) {
         return array('status' => 'ok');
     }
     // Get and check parameters
     $name = Input::get('name');
     $key = Input::get('key');
     if (empty($name) || strlen($name) > 100) {
         return array('error' => 'Invalid name!');
     }
     if (empty($key)) {
         return array('error' => 'Invalid key!');
     }
     // check if team already exists
     $team = TeamModel::getTeamIfExists($name, $key);
     if (!empty($team)) {
         if ($team[0]->unique_key == $key) {
             // this user is already registered, so do nothing.
             // call to /register will be made
             // only if the call to /login failed,
             // so this should not happen in normal case
             return array('status' => 'ok');
         }
         return array('error' => 'This team name is taken!');
     }
     // everything is fine, insert user
     if (!TeamModel::registerNewTeam($name, $key)) {
         return array('error' => 'Error while registering team!');
     }
     return array('status' => 'ok');
 }
Example #2
0
 public static function getTeamsArray()
 {
     $teamNames = [];
     foreach (TeamModel::all() as $key => $team) {
         array_push($teamNames, [$team->post_title => $team->post_title]);
     }
     return $teamNames;
 }
 public function getTeam($id)
 {
     $team = TeamModel::getTeamById($id);
     if (empty($team)) {
         return array('error' => 'Team not found!');
     }
     $teamMatches = MatchModel::getTeamMatches($id);
     return array('team' => $team[0], 'matches' => $teamMatches);
 }
Example #4
0
 function getSingle()
 {
     $team = TeamModel::getCurrent();
     $options = array('team' => $team);
     if (isset($team->banner)) {
         $options["home_banner"] = $team->banner;
     }
     return View::make('teams.single')->with($options);
 }
 public function showTeam($id)
 {
     $team = TeamModel::getTeamById($id);
     if (empty($team)) {
         return View::make('error', array('error' => 'Team not found!'));
     }
     $teamMatches = MatchModel::getTeamMatches($id);
     return View::make('team', array('team' => $team, 'matches' => $teamMatches));
 }
Example #6
0
 public function saveteam()
 {
     $DB = new TeamModel('team');
     if (!$DB->create()) {
         $this->error($DB->getError(), __URL__);
     } else {
         $module = "img";
         $path = date("Ymd");
         $pic = $this->_upload($module, $path);
         $img = $pic[0]['savepath'] . $pic[0]['savename'];
         $DB->pic = $img;
         $query = $DB->add();
     }
     if ($query) {
         $this->success(L('ADDSUCCESS'), __URL__);
     } else {
         $this->error(L('ADDFAILURE'), __URL__);
     }
 }
 /**
  * @desc 删除球队
  */
 public function actionDeleteTeam()
 {
     $masterId = CommonFunction::getUserId();
     $leagueId = Yii::app()->request->getPost('leagueId');
     $teamId = Yii::app()->request->getPost('teamId');
     if (empty($leagueId) || empty($teamId)) {
         CommonFunction::ajaxResult(State::$SYS_PARAM_ERROR_CODE, State::$SYS_PARAM_ERROR_MSG);
     }
     $leagueModel = new LeagueModel();
     $groupModel = new GroupModel();
     $Groups = $groupModel->findByLeagueId($leagueId);
     if (empty($Groups)) {
         $res = $leagueModel->removeRelation('teams', 'Team', $leagueId, $teamId);
         if (isset($res->updatedAt)) {
             $resM = $leagueModel->findByMaster($masterId, 1);
             $teamModel = new TeamModel();
             $leagueTeams = $teamModel->findRowsByRelation("teams", "League", $resM[0]->objectId);
             $deleteTeam = $teamModel->findTeamByObjectId($teamId);
             if (isset($deleteTeam[0]->captain->username)) {
                 $uid = $deleteTeam[0]->captain->username;
                 $pushMsg = '你的球队:' . $deleteTeam[0]->name . ',已被联赛【' . $resM[0]->name . '】移除出联赛';
                 CommonFunction::pushAppMsg($uid, $pushMsg);
                 //					$device = new InstallationModel();
                 //					$msg = $device->findByUid($uid);
                 //					if(isset($msg[0]) && !empty($msg[0])){
                 //						$deviceMsg = $msg[0];
                 //						$push = new PushMsgModel();
                 //						$pushMsg = '你的球队:'.$deleteTeam[0]->name.',已被联赛【'.$resM[0]->name.'】移除出联赛';
                 //						if(isset($deviceMsg->deviceToken) && isset($deviceMsg->deviceType) && $deviceMsg->deviceType == 'ios'){
                 //							$push->createIosPush($deviceMsg->deviceToken,$pushMsg);
                 //						}elseif(isset($deviceMsg->installationId) && isset($deviceMsg->deviceType) && $deviceMsg->deviceType == 'android'){
                 //							$push->createAndroidPush($deviceMsg->installationId,$pushMsg);
                 //						}
                 //					}
             }
         }
         CommonFunction::ajaxResult(State::$SUSSION_CODE, State::$SUSSION_MSG, array('leagueTeams' => $leagueTeams));
     } else {
         CommonFunction::ajaxResult(State::$TEAM_DELETE_ERROR_CODE, State::$TEAM_DELETE_ERROR_MSG);
     }
 }
 protected function do_delete()
 {
     parse_str(file_get_contents("php://input"), $_DELETE);
     if (empty($_DELETE["student_id"])) {
         $this->exit_error(400, "studentIDMandatoryAndNotEmpty");
     } else {
         if (empty($_DELETE["team_id"])) {
             $this->exit_error(400, "teamIDMandatoryAndNotEmpty");
         } else {
             $student_id = $_DELETE["student_id"];
             $team_id = $_DELETE["team_id"];
             TeamModel::removeStudentFromTeam($student_id, $team_id);
         }
     }
 }
Example #9
0
<?php

/*-----------------------------------------------------------------------*/
// Match Custom Post
/*-----------------------------------------------------------------------*/
$match = PostType::make('slhb_match', 'Les matchs', 'match')->set(array('public' => true, 'menu_position' => 20, 'supports' => false, 'rewrite' => false, 'query_var' => false, 'labels' => ['add_new' => 'Ajouter un nouveau match', 'add_item' => 'Ajouter un match', 'all_items' => 'Tous les matchs', 'edit_item' => 'Modifier un match']));
/*-----------------------------------------------------------------------*/
// Match informations
/*-----------------------------------------------------------------------*/
$infos = Metabox::make('Informations du match', $match->get('name'))->set(array(Field::date('match_date', ['title' => 'Date du match']), Field::select('match_team_dom', TeamModel::getTeamsArray()), Field::text('match_team_ext', ['title' => 'Equipe à l\'exterieur']), Field::number('score_dom', ['title' => 'Score de l\'équipe à domicile']), Field::number('score_ext', ['title' => 'Score de l\'équipe extérieur'])));
/*-----------------------------------------------------------------------*/
// Match Defaults Values
/*-----------------------------------------------------------------------*/
function slhb_set_title($post_id, $post, $update)
{
    $dateStr = Meta::get($post_id, 'match_date');
    $title = $dateStr . ' - ' . Meta::get($post_id, 'match_team_dom') . ' - ' . Meta::get($post_id, 'match_team_ext');
    $date = date($dateStr);
    //This temporarily removes filter to prevent infinite loops
    remove_action('save_post_slhb_match', __FUNCTION__);
    wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'match_date' => $date));
    //redo filter
    add_action('save_post_slhb_match', __FUNCTION__, 10, 3);
}
add_action('save_post_slhb_match', 'slhb_set_title', 10, 3);
Example #10
0
 public function actionTeams()
 {
     $leagueTeamIds = array();
     $teamModel = new TeamModel();
     //找到联赛中的球队
     $leagueTeams = $teamModel->findRowsByRelation("teams", "League", "52a05804d7");
     foreach ($leagueTeams as $lTeam) {
         array_push($leagueTeamIds, $lTeam->objectId);
     }
     //		$leagueTeamIdsStr = '["'.implode('","',$leagueTeamIds).'"]';
     $arr = array('msg' => 'Hello , 网站端推送', 'status' => 0, 'pushType' => 1, 'teams' => $leagueTeamIds);
     $leaguePushMsgModel = new LeaguePushMsgModel();
     $leaguePushMsgModel->save($arr);
     var_dump($leagueTeamIds);
     exit;
 }
<?php

include_once "../model/TeamModel.php";
include_once "../model/WebFunctions.php";
include_once "../model/ProjectModel.php";
require_once "../model/AuthenticateSession.php";
$teamId = $_GET['team_id'];
$team = TeamModel::getTeamById($teamId);
$projectID = $team['project_id'];
$classID = ProjectModel::getProjectClassById($projectID);
$listOfAvailableStudents = ProjectModel::getFreeStudents($classID);
$listOfTeamMembers = TeamModel::getTeamStudents($teamId);
$table1 = "";
// table 1  - available students
$table2 = "";
// table 2 - students already in team
$summary = $team['summary'];
$creatorId = $team['creator_id'];
if (count($listOfAvailableStudents) > 0) {
    for ($int = 0; $int < count($listOfAvailableStudents); $int++) {
        $table1 .= "<li id='" . $listOfAvailableStudents[$int]['student_id'] . "'class=\"list-group-item ui-state-default hand-cursor\">" . $listOfAvailableStudents[$int]['name'] . "</li>";
        // table 1  - available students
    }
}
if (count($listOfTeamMembers) > 0) {
    for ($int = 0; $int < count($listOfTeamMembers); $int++) {
        // table 2 - current students in team
        if ($listOfTeamMembers[$int]['student_id'] == $creatorId) {
            $table2 .= "<li id='" . $listOfTeamMembers[$int]['student_id'] . "' class=\"list-group-item ui-state-default ui-state-disabled\">" . $listOfTeamMembers[$int]['name'] . "<span class=\"badge\">Owner</span>" . "</li>";
        } else {
            $table2 .= "<li id='" . $listOfTeamMembers[$int]['student_id'] . "' class=\"list-group-item ui-state-default hand-cursor\">" . $listOfTeamMembers[$int]['name'] . "</li>";
Example #12
0
 /**
  * @desc 球队阵容
  */
 public function actionGameLineup()
 {
     $teamId = Yii::app()->request->getQuery('team', '');
     $LineupModel = new LineupModel();
     $lineupData = $LineupModel->findLineupByTeamId($teamId);
     $teamModel = new TeamModel();
     $team = $teamModel->findTeamByObjectId($teamId);
     if ($team) {
         $team = $team[0];
     }
     $backPlayers = array();
     $strikerPlayers = array();
     $forwardPlayers = array();
     $goalkeeperPlayers = array();
     if (isset($lineupData[0])) {
         $lineupId = $lineupData[0]->objectId;
         $userModel = new UserModel();
         $backPlayers = $userModel->findRowsByRelation("back", "Lineup", $lineupId);
         $strikerPlayers = $userModel->findRowsByRelation("striker", "Lineup", $lineupId);
         $forwardPlayers = $userModel->findRowsByRelation("forward", "Lineup", $lineupId);
         $goalkeeperPlayers = $lineupData[0]->goalkeeper;
     }
     //		print_r($team);exit("dafasfda");
     $this->render('gameLineup', array('team' => $team, 'backPlayers' => $backPlayers, 'strikerPlayers' => $strikerPlayers, 'forwardPlayers' => $forwardPlayers, 'goalkeeperPlayers' => $goalkeeperPlayers));
 }
Example #13
0
    ?>
>
                                        <?php 
    echo $i->title();
    ?>
                                    </option>
                                <?php 
}
?>
                            </select>
                        </div>
                        <div class="form-group col-sm-9">
                            <label for="team">Select Team</label>
                            <select name="team">
                                <?php 
foreach (TeamModel::orderBy('id')->get() as $i) {
    ?>
                                    <option value="<?php 
    echo $i->id;
    ?>
" <?php 
    echo $item->team_id == $i->id ? ' selected' : '';
    ?>
>
                                        <?php 
    echo $i->article()->title;
    ?>
                                    </option>
                                <?php 
}
?>
Example #14
0
 /**
  * 查找联赛中所有成员的成员,结果是个对象数组
  * @param unknown_type $leagueId
  */
 public function findMembers($leagueId)
 {
     $teamModel = new TeamModel();
     $leagueTeams = $teamModel->findRowsByRelation("teams", "League", $leagueId);
     if ($leagueTeams && count($leagueTeams) == 2) {
         $team1 = $leagueTeams[0];
         $team2 = $leagueTeams[1];
         $userModel = new UserModel();
         $res = $userModel->getUserByTeam($team1->objectId, $team2->objectId);
         if ($res) {
             return $res;
         }
     }
     return array();
 }
 public function actionGameResult()
 {
     $masterId = CommonFunction::getUserId();
     $leagueModel = new LeagueModel();
     //判断用户是否有管理联赛的权限
     $res = $leagueModel->allowEditLeague($masterId);
     $leagueId = $res->results[0]->objectId;
     $content = CommonFunction::ob2ar($res);
     foreach ($content["results"] as $key) {
         echo $key["name"];
     }
     $teamModel = new TeamModel();
     $tournamentModel = new TournamentModel();
     $leagueTeams = $teamModel->findRowsByRelation("teams", "League", $leagueId);
     $games = array();
     $games = $tournamentModel->findByLeague($leagueId);
     foreach ($games as $k => $game) {
         //比赛开始后2小时,认为比赛结束
         if (time() - strtotime($game->start_time->iso) > 7200) {
             unset($games[$k]);
         }
     }
     $this->render('gameResult', array('leagueTeams' => $leagueTeams, 'games' => $games));
 }
<?php

include_once "../model/StudentModel.php";
include_once "../model/ProjectModel.php";
include_once "../model/TeamModel.php";
include_once "../model/WebFunctions.php";
require_once "../model/AuthenticateSession.php";
// TODO repair pagination
$teamsPerPage = 4;
$content = "";
$student_id = $_GET['student_id'];
$student_name = StudentModel::getStudentById($student_id);
$totalNumberOfTeams = count(TeamModel::getStudentTeams($student_id));
$totalNumberOfPages = ceil($totalNumberOfTeams / $teamsPerPage);
$currentPage = isset($_GET['current_page']) ? (int) $_GET['current_page'] : 1;
$startPage = ($currentPage - 1) * $teamsPerPage;
// set content
$listOfTeams = TeamModel::getStudentTeams($student_id, $startPage, $teamsPerPage);
$content = "";
if (count($listOfTeams) == 0) {
    $content .= "   <div class=\"row text-center\">\r\n                        <div class=\"col-lg-12\">\r\n                            <p>No teams attended</p>\r\n                        </div>\r\n                    </div>";
} else {
    for ($int = 0; $int < count($listOfTeams); $int++) {
        $teamID = $listOfTeams[$int]['team_id'];
        $content .= "<div class=\"col-md-3 portfolio-item\">\r\n                       <a href=\"team-id-{$teamID}\">\r\n                            <img class=\"img-responsive\" src=\"images/team.jpg\" alt=\"\">\r\n                       </a>\r\n                       <p style='text-align: center'>Team {$teamID}</p>\r\n                 </div>";
    }
}
$pagination = WebFunctions::pagination($currentPage, $totalNumberOfPages);
include_once "../view/profile-student.php";
Example #17
0
 /**
  * 给联赛的所有人发送消息
  */
 public function sendMessageForAllLeague($type, $subType, $leagueId, $message)
 {
     //更新赛程发送推送
     $teamModel = new TeamModel();
     $leagueTeams = $teamModel->findMembers($leagueId);
     $leagueModel = new LeagueModel();
     $res = $leagueModel->get($leagueId);
     if (empty($res)) {
         throw new CHttpException(500, '获取联赛信息失败');
     }
     $leagueName = $res->name;
     $this->push($leagueTeams, $leagueName, $message, $type, $subType, array("leagueId" => $leagueId));
 }
    } else {
        $app->response()->body(json_encode($TeamModel->getError()));
        $app->response()->status(400);
    }
});
$app->delete('/teams/:id', function ($id) use($app) {
    // Instantiate Team and set id attribute
    $TeamModel = new TeamModel();
    $TeamModel->setId($id);
    // Delete team, respond with error if method returns false
    if (!$TeamModel->delete()) {
        $app->response()->body(json_encode($TeamModel->getError()));
        $app->response()->status(400);
    }
});
$app->post('/teams/', function () use($app) {
    $requestJson = json_decode($app->request()->getBody(), true);
    // Instantiate Team and fill attributes
    $TeamModel = new TeamModel();
    $TeamModel->setCity($requestJson['city'])->setName($requestJson['name']);
    if ($TeamModel->create()) {
        $app->response()->body(json_encode($TeamModel->toArray()));
    } else {
        $app->response()->body(json_encode($TeamModel->getError()));
        $app->response()->status(400);
    }
});
/**
 * Launch application
 */
$app->run();
Example #19
0
<?php

class TeamModel extends ImplicitWOGAPModel
{
    public $table = 'wog_team_main';
}
TeamModel::setParams(array('t_id' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'p_id' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 't_name' => array('filter' => FILTER_SANITIZE_STRING), 't_peo' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 't_time' => array('filter' => FILTER_SANITIZE_NUMBER_INT)));
<?php

/**
 * Created by PhpStorm.
 * User: nillernoels
 * Date: 03/01/16
 * Time: 22:17
 */
require_once "../model/StudentModel.php";
require_once "../model/TeamModel.php";
require_once "../model/ProjectModel.php";
session_start();
$studentId = $_SESSION['student_id'];
if (isset($_POST['project_id'])) {
    $summary = "";
    if (isset($_POST['summary'])) {
        $summary .= $_POST['summary'];
    }
    if (TeamModel::createTeam($summary, $studentId, $_POST['project_id'])) {
        header("location: home-student");
    }
    $msg = "<div></div>";
} else {
    $classId = StudentModel::getStudentClassById($studentId);
    $listOfAvailableProjects = ProjectModel::getAllProjectsInClassById($classId);
    $projects = "";
    foreach ($listOfAvailableProjects as $project) {
        $projects .= "<option value=\"" . $project['Project_id'] . "\">" . $project['Title'] . "</option>";
    }
    include_once "../view/create-team.php";
}
$content = "";
$isTrainer = $_SESSION['isTrainer'];
if ($isTrainer != 'true') {
    $studentID = $_SESSION['student_id'];
    $studentName = $_SESSION['name'];
    // get name
    $totalNumberOfProjects = count(TeamModel::getStudentTeams($studentID));
    // get total amount
    $totalNumberOfPages = ceil($totalNumberOfProjects / $projectPerPage);
    // calc number of pages
    $currentPage = isset($_GET['current_page']) ? (int) $_GET['current_page'] : 1;
    // if currentPage var isset else default 1
    $startPage = ($currentPage - 1) * $projectPerPage;
    // calc start page ex. 1 = 0 - 4 projects
    // set content:
    $listOfTeams = TeamModel::getStudentTeamsLimit($studentID, $startPage, $projectPerPage);
    // get teams
    $content = "";
    if (count($listOfTeams) == 0) {
        $content .= "   <div class=\"row text-center\">\n                        <div class=\"col-lg-12\">\n                            <p>No teams attended</p>\n                        </div>\n                    </div>";
    } else {
        for ($int = 0; $int < count($listOfTeams); $int++) {
            $teamID = $listOfTeams[$int]['team_id'];
            $content .= "<div class=\"col-md-3 portfolio-item\">\n                       <a href=\"team-id-{$teamID}\">\n                            <img class=\"img-responsive\" src=\"images/team.jpg\" alt=\"\">\n                       </a>\n                       <p style='text-align: center'>Team {$teamID}</p>\n                 </div>";
        }
    }
    $pagination = WebFunctions::pagination($currentPage, $totalNumberOfPages);
    // add pagination
    // add view
    include_once "../view/home-student.php";
} else {
<?php

include_once "../model/TeamModel.php";
include_once "../model/WebFunctions.php";
require_once "../model/AuthenticateSession.php";
$id = $_GET['team_id'];
$team = TeamModel::getTeamById($id);
$listOfStudents = TeamModel::getTeamStudents($id);
$project_id = $team["project_id"];
$content = "";
foreach ($listOfStudents as $student) {
    $content .= "<a href=\"student-id-" . $student['student_id'] . "\">" . $student['name'] . " <br> </a>";
}
// Check right of the user for editing the team
session_start();
if (array_key_exists('student_id', $_SESSION) and $team['creator_id'] == $_SESSION['student_id']) {
    $edit_button = "<a href=\"team-edit-{$id}\">\r\n\t\t<button type=\"button\" class=\"btn btn-default\">\tEdit team </button> </a>";
} else {
    $edit_button = "<button type=\"button\" class=\"btn btn-default\" disabled>\tEdit team </button>";
}
// add view
include_once "../view/team-detail.php";