-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Concerns #253
- Loading branch information
Showing
5 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
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,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()); | ||
} | ||
} |
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,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(); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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