Skip to content

Commit

Permalink
Added domain for Scribble
Browse files Browse the repository at this point in the history
Concerns #253
  • Loading branch information
mikron-ia committed Oct 3, 2023
1 parent ebca52c commit ae32126
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 0 deletions.
73 changes: 73 additions & 0 deletions common/models/Scribble.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace common\models;

use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;

/**
* This is the model class for table "scribble".
*
* @property int $scribble_id
* @property int|null $scribble_pack_id
* @property int|null $user_id
* @property int|null $favorite
*
* @property ScribblePack $scribblePack
* @property User $user
*/
class Scribble extends ActiveRecord
{
public static function tableName(): string
{
return 'scribble';
}

public function rules(): array
{
return [
[['scribble_pack_id', 'user_id', 'favorite'], 'integer'],
[['scribble_pack_id'], 'exist', 'skipOnError' => true, 'targetClass' => ScribblePack::class, 'targetAttribute' => ['scribble_pack_id' => 'scribble_pack_id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
];
}

public function attributeLabels()
{
return [
'scribble_id' => Yii::t('app', 'Scribble ID'),
'scribble_pack_id' => Yii::t('app', 'Scribble Pack ID'),
'user_id' => Yii::t('app', 'User ID'),
'favorite' => Yii::t('app', 'Favorite'),
];
}

/**
* Gets query for [[ScribblePack]].
*
* @return ActiveQuery|ScribblePackQuery
*/
public function getScribblePack(): ActiveQuery|ScribblePackQuery
{
return $this->hasOne(ScribblePack::class, ['scribble_pack_id' => 'scribble_pack_id']);
}

/**
* Gets query for [[User]].
*
* @return ActiveQuery
*/
public function getUser(): ActiveQuery
{
return $this->hasOne(User::class, ['id' => 'user_id']);
}

/**
* @return ScribbleQuery the active query used by this AR class.
*/
public static function find(): ScribbleQuery
{
return new ScribbleQuery(get_called_class());
}
}
94 changes: 94 additions & 0 deletions common/models/ScribblePack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace common\models;

use common\models\core\HasEpicControl;
use common\models\core\IsPack;
use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;

/**
* This is the model class for table "scribble_pack".
*
* @property int $scribble_pack_id
* @property string $class Name of class this pack belongs to; necessary for proper type assignment
*
* @property Character[] $characters
* @property Group[] $groups
* @property Scribble[] $scribbles
*/
class ScribblePack extends ActiveRecord implements IsPack
{
public static function tableName(): string
{
return 'scribble_pack';
}

public function rules(): array
{
return [
[['class'], 'required'],
[['class'], 'string', 'max' => 20],
];
}

public function attributeLabels(): array
{
return [
'scribble_pack_id' => Yii::t('app', 'SCRIBBLE_PACK_ID'),
'class' => Yii::t('app', 'SCRIBBLE_PACK_CLASS'),
];
}

/**
* Gets query for [[Characters]].
*
* @return ActiveQuery
*/
public function getCharacters(): ActiveQuery
{
return $this->hasMany(Character::class, ['scribble_pack_id' => 'scribble_pack_id']);
}

/**
* Gets query for [[Groups]].
*
* @return ActiveQuery
*/
public function getGroups(): ActiveQuery
{
return $this->hasMany(Group::class, ['scribble_pack_id' => 'scribble_pack_id']);
}

/**
* Gets query for [[Scribbles]].
*
* @return ActiveQuery|ScribbleQuery
*/
public function getScribbles()
{
return $this->hasMany(Scribble::class, ['scribble_pack_id' => 'scribble_pack_id']);
}

public static function find(): ScribblePackQuery
{
return new ScribblePackQuery(get_called_class());
}

public function canUserReadYou(): bool
{
$className = 'common\models\\' . $this->class;
/** @var HasEpicControl $object */
$object = ($className)::findOne(['description_pack_id' => $this->description_pack_id]);
return $object->canUserViewYou();
}

public function canUserControlYou(): bool
{
$className = 'common\models\\' . $this->class;
/** @var HasEpicControl $object */
$object = ($className)::findOne(['description_pack_id' => $this->description_pack_id]);
return $object->canUserControlYou();
}
}
35 changes: 35 additions & 0 deletions common/models/ScribblePackQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace common\models;

use yii\db\ActiveRecord;

/**
* This is the ActiveQuery class for [[ScribblePack]].
*
* @see ScribblePack
*/
class ScribblePackQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/

/**
* @return ScribblePack[]|array
*/
public function all($db = null): array
{
return parent::all($db);
}

/**
* @param null $db
* @return array|ActiveRecord|null
*/
public function one($db = null): array|ActiveRecord|null
{
return parent::one($db);
}
}
32 changes: 32 additions & 0 deletions common/models/ScribbleQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace common\models;

/**
* This is the ActiveQuery class for [[Scribble]].
*
* @see Scribble
*/
class ScribbleQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/

/**
* @return Scribble[]|array
*/
public function all($db = null): array
{
return parent::all($db);
}

/**
* @return Scribble|array|null
*/
public function one($db = null): Scribble|array|null
{
return parent::one($db);
}
}
80 changes: 80 additions & 0 deletions console/migrations/m230910_123838_v1_1_0.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,90 @@ public function safeUp()

/* Session location added */
$this->addColumn('{{%game}}', 'planned_location', $this->string(80)->after('planned_date'));

/* Scribbles created */
$this->createTable(
'{{%scribble_pack}}',
[
'scribble_pack_id' => $this->primaryKey()->unsigned(),
'class' => $this->string(20)->notNull()->comment("Name of class this pack belongs to; necessary for proper type assignment"),
],
$tableOptions
);

$this->createTable(
'{{%scribble}}',
[
'scribble_id' => $this->primaryKey()->unsigned(),
'scribble_pack_id' => $this->integer(11)->unsigned(),
'user_id' => $this->integer(10)->unsigned(),
'favorite' => $this->boolean(),
],
$tableOptions
);

$this->addForeignKey(
'scribble_pack',
'{{%scribble}}',
'scribble_pack_id',
'{{%scribble_pack}}',
'scribble_pack_id',
'RESTRICT',
'CASCADE'
);
$this->addForeignKey(
'scribble_user',
'{{%scribble}}',
'user_id',
'{{%user}}',
'id',
'RESTRICT',
'CASCADE'
);

$this->addColumn(
'{{%character}}',
'scribble_pack_id',
$this->integer(11)->unsigned()->after('importance_pack_id')
);
$this->addColumn(
'{{%group}}',
'scribble_pack_id',
$this->integer(11)->unsigned()->after('importance_pack_id')
);

$this->addForeignKey(
'character_scribble_pack',
'{{%character}}',
'scribble_pack_id',
'{{%scribble_pack}}',
'scribble_pack_id',
'RESTRICT',
'CASCADE'
);
$this->addForeignKey(
'group_scribble_pack',
'{{%group}}',
'scribble_pack_id',
'{{%scribble_pack}}',
'scribble_pack_id',
'RESTRICT',
'CASCADE'
);
}

public function safeDown()
{
/* Scribbles removed */
$this->dropForeignKey('group_scribble_pack', '{{%group}}');
$this->dropForeignKey('character_scribble_pack', '{{%character}}');

$this->dropColumn('{{%group}}', 'scribble_pack_id');
$this->dropColumn('{{%character}}', 'scribble_pack_id');

$this->dropTable('{{%scribble}}');
$this->dropTable('{{%scribble_pack}}');

/* Group updated_at removed */
$this->dropColumn('{{%group}}', 'updated_at');

Expand Down

0 comments on commit ae32126

Please sign in to comment.