-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1282 from proditis/master
team improvements
- Loading branch information
Showing
31 changed files
with
2,006 additions
and
949 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
backend/migrations/m241101_080235_create_team_invite_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles the creation of table `{{%team_invite}}`. | ||
*/ | ||
class m241101_080235_create_team_invite_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->createTable('{{%team_invite}}', [ | ||
'id' => $this->primaryKey(), | ||
'team_id' => $this->integer(), | ||
'token' => $this->string(32)->notNull()->unique()->defaultValue(''), | ||
'created_at' => $this->dateTime(), | ||
'updated_at' => $this->timestamp(), | ||
]); | ||
$this->addForeignKey('fk_team_id', 'team_invite', 'team_id', 'team', 'id', 'CASCADE', 'CASCADE'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->dropForeignKey('fk_team_id', 'team_invite'); | ||
$this->dropTable('{{%team_invite}}'); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
backend/migrations/m241101_102909_populate_invite_urls.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241101_102909_populate_invite_urls | ||
*/ | ||
class m241101_102909_populate_invite_urls extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$res = $this->db->createCommand("SELECT id FROM team")->queryAll(); | ||
foreach($res as $rec) | ||
{ | ||
$now=new \yii\db\Expression('NOW()'); | ||
$this->upsert('team_invite',['team_id'=>$rec['id'],'token'=>\Yii::$app->security->generateRandomString(8),'created_at'=>$now]); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m241101_102909_populate_invite_urls cannot be reverted.\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
backend/modules/frontend/controllers/TeamInviteController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
namespace app\modules\frontend\controllers; | ||
|
||
use app\modules\frontend\models\TeamInvite; | ||
use app\modules\frontend\models\TeamInviteSearch; | ||
use app\components\BaseController; | ||
use yii\web\NotFoundHttpException; | ||
use yii\filters\VerbFilter; | ||
|
||
/** | ||
* TeamInviteController implements the CRUD actions for TeamInvite model. | ||
*/ | ||
class TeamInviteController extends BaseController | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function behaviors() | ||
{ | ||
return array_merge( | ||
parent::behaviors(), | ||
[ | ||
'verbs' => [ | ||
'class' => VerbFilter::className(), | ||
'actions' => [ | ||
'delete' => ['POST'], | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Lists all TeamInvite models. | ||
* | ||
* @return string | ||
*/ | ||
public function actionIndex() | ||
{ | ||
$searchModel = new TeamInviteSearch(); | ||
$dataProvider = $searchModel->search($this->request->queryParams); | ||
|
||
return $this->render('index', [ | ||
'searchModel' => $searchModel, | ||
'dataProvider' => $dataProvider, | ||
]); | ||
} | ||
|
||
/** | ||
* Displays a single TeamInvite model. | ||
* @param int $id ID | ||
* @return string | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
public function actionView($id) | ||
{ | ||
return $this->render('view', [ | ||
'model' => $this->findModel($id), | ||
]); | ||
} | ||
|
||
/** | ||
* Creates a new TeamInvite model. | ||
* If creation is successful, the browser will be redirected to the 'view' page. | ||
* @return string|\yii\web\Response | ||
*/ | ||
public function actionCreate() | ||
{ | ||
$model = new TeamInvite(); | ||
|
||
if ($this->request->isPost) { | ||
if ($model->load($this->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'id' => $model->id]); | ||
} | ||
} else { | ||
$model->loadDefaultValues(); | ||
} | ||
|
||
return $this->render('create', [ | ||
'model' => $model, | ||
]); | ||
} | ||
|
||
/** | ||
* Updates an existing TeamInvite model. | ||
* If update is successful, the browser will be redirected to the 'view' page. | ||
* @param int $id ID | ||
* @return string|\yii\web\Response | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
public function actionUpdate($id) | ||
{ | ||
$model = $this->findModel($id); | ||
|
||
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'id' => $model->id]); | ||
} | ||
|
||
return $this->render('update', [ | ||
'model' => $model, | ||
]); | ||
} | ||
|
||
/** | ||
* Deletes an existing TeamInvite model. | ||
* If deletion is successful, the browser will be redirected to the 'index' page. | ||
* @param int $id ID | ||
* @return \yii\web\Response | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
public function actionDelete($id) | ||
{ | ||
$this->findModel($id)->delete(); | ||
|
||
return $this->redirect(['index']); | ||
} | ||
|
||
/** | ||
* Finds the TeamInvite model based on its primary key value. | ||
* If the model is not found, a 404 HTTP exception will be thrown. | ||
* @param int $id ID | ||
* @return TeamInvite the loaded model | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
protected function findModel($id) | ||
{ | ||
if (($model = TeamInvite::findOne(['id' => $id])) !== null) { | ||
return $model; | ||
} | ||
|
||
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace app\modules\frontend\models; | ||
|
||
use Yii; | ||
use yii\behaviors\TimestampBehavior; | ||
use yii\db\Expression; | ||
|
||
/** | ||
* This is the model class for table "team_invite". | ||
* | ||
* @property int $id | ||
* @property int|null $team_id | ||
* @property string $token | ||
* @property string|null $created_at | ||
* @property string $updated_at | ||
* | ||
* @property Team $team | ||
*/ | ||
class TeamInvite extends \yii\db\ActiveRecord | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tableName() | ||
{ | ||
return 'team_invite'; | ||
} | ||
|
||
public function behaviors() | ||
{ | ||
return [ | ||
[ | ||
'class' => TimestampBehavior::class, | ||
'createdAtAttribute' => 'created_at', | ||
'updatedAtAttribute' => 'updated_at', | ||
'value' => new Expression('NOW()'), | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['team_id','token'],'required'], | ||
[['token'],'unique'], | ||
[['team_id'], 'integer'], | ||
[['created_at', 'updated_at'], 'safe'], | ||
[['token'], 'string', 'max' => 32], | ||
[['token'], 'default', 'value' => Yii::$app->security->generateRandomString(8),'on'=>'insert'], | ||
[['team_id'], 'exist', 'skipOnError' => true, 'targetClass' => Team::class, 'targetAttribute' => ['team_id' => 'id']], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
return [ | ||
'id' => Yii::t('app', 'ID'), | ||
'team_id' => Yii::t('app', 'Team ID'), | ||
'token' => Yii::t('app', 'Token'), | ||
'created_at' => Yii::t('app', 'Created At'), | ||
'updated_at' => Yii::t('app', 'Updated At'), | ||
]; | ||
} | ||
|
||
/** | ||
* Gets query for [[Team]]. | ||
* | ||
* @return \yii\db\ActiveQuery|yii\db\ActiveQuery | ||
*/ | ||
public function getTeam() | ||
{ | ||
return $this->hasOne(Team::class, ['id' => 'team_id']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @return TeamInviteQuery the active query used by this AR class. | ||
*/ | ||
public static function find() | ||
{ | ||
return new TeamInviteQuery(get_called_class()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace app\modules\frontend\models; | ||
|
||
/** | ||
* This is the ActiveQuery class for [[TeamInvite]]. | ||
* | ||
* @see TeamInvite | ||
*/ | ||
class TeamInviteQuery extends \yii\db\ActiveQuery | ||
{ | ||
/*public function active() | ||
{ | ||
return $this->andWhere('[[status]]=1'); | ||
}*/ | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @return TeamInvite[]|array | ||
*/ | ||
public function all($db = null) | ||
{ | ||
return parent::all($db); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @return TeamInvite|array|null | ||
*/ | ||
public function one($db = null) | ||
{ | ||
return parent::one($db); | ||
} | ||
} |
Oops, something went wrong.