public static function createNew($data) { $c = new Club(); $c->name = $data['club_name']; $c->save(); return $c; }
public function actionClubsLoad($filename) { if (!is_readable($filename)) { die("Файл '{$filename}' не читается\n"); } else { $strings = preg_split("/\n/", file_get_contents($filename)); echo "Всего строк " . count($strings) . "\n"; $current_city = "Default"; foreach ($strings as $line) { if (strlen($line) > 0) { if ($line[0] === '#') { $current_city = trim(preg_replace('/# /', '', $line)); } else { $club = preg_split('/:/', $line); if (count($club) == 2) { $boss = trim($club[1]); $name = trim($club[0]); $c = new Club(); $c->city = $current_city; $c->name = $name; $c->leader = $boss; if (!$c->save()) { var_export($c->errors); } } } } } } }
/** * Run the clubs table seeds. * * @return void */ public function run() { DB::table('clubs')->delete(); Club::create(array('name' => "Level'UP", 'slug' => 'bde', 'description' => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam", 'photo' => 'https://scontent-ams3-1.xx.fbcdn.net/hphotos-xap1/v/t1.0-9/934736_314254778734727_4954772019685029478_n.png?oh=8e3e56732cfeb8ef0c71df443c43c61b&oe=563A0045', 'website' => 'bde.42.fr', 'facebook' => 'https://www.facebook.com/42.levelup', 'slack' => 'bde')); Club::create(array('name' => "Rugby42", 'slug' => 'rugby-42', 'description' => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam", 'photo' => 'https://scontent-ams3-1.xx.fbcdn.net/hphotos-xta1/t31.0-8/10626436_534070536731308_3775425591585128876_o.png', 'website' => 'http://www.rc42.fr/', 'facebook' => 'https://www.facebook.com/rugby42', 'slack' => 'rugby42')); Club::create(array('name' => "Arcade42", 'slug' => 'arcade-42', 'description' => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam", 'photo' => 'https://pbs.twimg.com/profile_images/639462237892177920/rhsratx7.png')); }
public function store(Request $request) { $club = Club::where('_id', $request->get('club_id'))->first(); $team = $club->teams()->where('_id', $request->get('team_id'))->first(); $user = User::where('email', $request->get('email'))->first(); if (empty($user)) { $user = new User(); $user->first_name = $request->get('first_name'); $user->last_name = $request->get('last_name'); $user->email = $request->get('email'); $user->position = $request->get('position'); $user->active = false; $user->save(); //team $role = new Role(); $role->club_id = $club->_id; $role->club_name = $club->name; $role->team_id = $team->_id; $role->team_name = $team->name; $role->role = 'player'; $user->roles()->save($role); return response()->json($user, 200); } else { return response()->json(array('message' => 'user registered'), 200); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $club = Club::findFail($id); $club->delete(); $this->data->name = $club->name; return $this->json(); }
function getClub($id, $redirect_to = 'home') { $club = Club::where('slug', $id)->first(); if (!isset($club)) { $club = Club::where('id', $id)->first(); if (!isset($club)) { return Redirect::route($redirect_to)->with('error', "The club is not registered in the database"); } } return $club; }
/** * Updates an existing Couple model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $bnames = []; $gnames = []; $bsurname = []; $gsurname = []; $years = [2015]; $clubs = ArrayHelper::map(Club::find()->all(), 'id', function ($club) { /* @var $club Club */ return $club->name . ' (' . $club->leader . ')'; }, 'city'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'bnames' => $bnames, 'bsurnames' => $bsurname, 'gnames' => $gnames, 'gsurnames' => $gsurname, 'years' => $years, 'clubs' => $clubs, 'tours' => $model->tour->concert->tours]); } }
public function clearAll() { $users = User::all(); foreach ($users as $u) { $u->delete(); } $drills = Drill::all(); foreach ($drills as $d) { $d->delete(); } $games = Game::all(); foreach ($games as $g) { $g->delete(); } $clubs = Club::all(); foreach ($clubs as $c) { $c->delete(); } }
/** * Регистрация на концерт * @param $id integer идентификатор концерта * @return string * @throws NotFoundHttpException */ public function actionIndex($id) { $model = $this->findConcert($id); if (false === $model) { throw new NotFoundHttpException("Этого конкурса не существует или он уже прошел."); } else { $couple = new Couple(); $bnames = Couple::getBoysNames(); $bsurnames = Couple::getBoysSurnames(); $gnames = Couple::getGirlsNames(); $gsurnames = Couple::getGirlsSurnames(); $tours = $model->getTours()->all(); $clubs = ArrayHelper::map(Club::find()->all(), 'id', function ($club) { /* @var $club Club */ return $club->name . ' (' . $club->leader . ')'; }, 'city'); if (count($clubs) == 0) { throw new NotFoundHttpException("Отсутствуют клубы для регистрации"); } if (count($tours) == 0) { throw new NotFoundHttpException("Туры на этот концерт еще не добавлены"); } if ($couple->load(\Yii::$app->request->post()) && $couple->validate()) { if ($couple->save()) { $c = new Couple(); $c->bname = $couple->bname; $c->bsurname = $couple->bsurname; $c->gname = $couple->gname; $c->gsurname = $couple->gsurname; $c->byear = $couple->byear; $c->gyear = $couple->gyear; $c->club_id = $couple->club_id; $couple = $c; \Yii::$app->session->addFlash('success', 'Пара успешно зарегистрирована'); } else { \Yii::$app->session->addFlash('warning', 'Пара не зарегистрирована. Проверьте правильность информации'); } } return $this->render('reg', ['model' => $couple, 'bnames' => $bnames, 'bsurnames' => $bsurnames, 'gnames' => $gnames, 'gsurnames' => $gsurnames, 'years' => $this->getYears(1998, 2015), 'tours' => $tours, 'concert' => $model, 'clubs' => $clubs]); } }
public function store(Request $request) { $club = Club::where('name', $request->get('club_name'))->first(); if (empty($club)) { $club = Club::createNew($request->all()); } $team = $club->teams()->where('name', $request->get('team_name'))->first(); if (empty($team)) { $team = $club->createNewTeam($request->all()); } // team exists and has a user add pnding user and notify original creator that user wants access // else add user to team $user = User::where('_id', $request->get('user_id'))->first(); $role = new Role(); $role->club_id = $club->_id; $role->club_name = $club->name; $role->team_id = $team->_id; $role->team_name = $team->name; $role->role = 'coach'; $user->roles()->save($role); return response()->json($team, 200); }
public static function deletePhoto($id) { $photo = (new Query())->select('src, date, id_author, club_id')->from('club_photo')->where('id=:id', [':id' => $id])->one(); $clubId = $photo['club_id']; $role = Club::getUserRole($clubId, Yii::$app->user->getId()); if (!($photo['id_author'] == Yii::$app->user->getId() || ($role == 1 || $role == 2))) { return 0; } Yii::$app->db->createCommand("DELETE FROM club_photo WHERE id=:id")->bindValues([':id' => $id])->execute(); $date = explode(' ', $photo['date']); $date = explode('-', $date[0]); $src = '/img/club/photos/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/'; if (file_exists($src . 'l_' . $photo['src'])) { unlink($src . 'l_' . $photo['src']); } if (file_exists($src . 'original_' . $photo['src'])) { unlink($src . 'original_' . $photo['src']); } // Видаляэмо все що пов'язано з фото Yii::$app->db->createCommand("\n DELETE\n club_photo,\n club_likes,\n comments_club\n FROM\n club_photo\n LEFT OUTER JOIN\n club_likes\n ON club_photo.id=club_likes.photo_id\n LEFT OUTER JOIN\n comments_club\n ON club_photo.id=comments_club.id_photo\n WHERE\n club_photo.id=:id\n ")->bindValues([':id' => $id])->execute(); Yii::$app->db->createCommand("UPDATE clubs SET photo_count=photo_count-1 WHERE id={$clubId}")->execute(); return 1; }
/** * Remove the specified resource from storage. * * @param int $id * * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Club::find($id)->teams->toArray()); if ($canBeDeleted) { Club::destroy($id); \Flash::success('Club deleted!'); } else { \Flash::error('Cannot delete because they are existing teams in this club.'); } return redirect('admin/data-management/clubs'); }
public function actionRemoveUser() { if (Yii::$app->user->isGuest) { echo json_encode(['status' => 0]); return; } $clubId = Yii::$app->request->post('clubId'); $userId = Yii::$app->request->post('userId'); $role = Club::getUserRole($clubId, Yii::$app->user->getId()); $userRole = Club::getUserRole($clubId, $userId); if ($role == 1 && $userRole > 1 || $role == 2 && $userRole > 2) { Club::removeUser($clubId, $userId); echo json_encode(['status' => 1]); } else { echo json_encode(['status' => 0]); } }
/** * Finds the Club model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Club the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Club::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getClub() { return $this->hasOne(Club::className(), ['id' => 'club_id']); }
/** * show the invite request to the user * * @return Response */ public function getIndex() { $this->data->clubs = Club::all(); return $this->view('home.index'); }
public function index() { $clubs = Club::all(); return response()->json($clubs, 200); }
public static function searchClubs($name, $author, $limit, $contentId) { if ($contentId) { $contentRating = (new Query())->select(['rating'])->from('clubs')->where(['id' => $contentId])->scalar(); } $sql = (new Query())->select(['c.id AS club_id', 'c.name AS club_name', 'c.date AS club_date', 'c.user_count AS club_user_count', 'c.photo_count AS club_photo_count', 'u.name AS club_author', 'u.id AS club_id_author', 'c.background as club_background', 'c.img_src as club_img_src'])->from('clubs c')->where(['<', 'c.time_closed', time()])->filterWhere(['like', 'c.name', $name])->innerJoin('user u', 'c.id_author = u.id')->AndFilterWhere(['like', 'u.name', $author])->limit($limit)->orderBy('c.rating DESC'); if ($contentId) { $sql->andWhere(['<', 'c.rating', $contentRating]); } $clubs = $sql->all(); return Club::formatClubDate($clubs); }
public function actionClubs($id, $slug) { User::getUserInfoOrRedirect($this, $id, $user, $isMyProfile); $request = Yii::$app->request; $contentId = $request->post('contentId'); $clubs = Club::getAllUserClubs($id, 20, $slug, $contentId); if ($request->isAjax) { echo json_encode(['content' => $clubs]); return; } $categories = Category::getAllUserClubCategory($id); return $this->render('clubs', ['user' => $user, 'isMyProfile' => $isMyProfile, 'clubs' => $clubs, 'categories' => $categories, 'slug' => $slug]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $club = getClub($id, 'admin::clubs'); ClubPost::where('club_id', $club->id)->delete(); Club::destroy($club->id); return Redirect::route('admin::clubs')->with('success', 'The club has been deleted'); }
/** * Show the form for editing the specified resource. * * @param int $id * * @return mixed */ public function edit($id) { $team = Team::findOrFail($id); $clubs = Club::all(); return view('admin.data-management.teams.edit', compact('team', 'clubs')); }