44 lines
982 B
PHP
44 lines
982 B
PHP
<?php
|
|
|
|
namespace humhub\modules\animal_management\models;
|
|
|
|
use humhub\components\ActiveRecord;
|
|
|
|
class AnimalGalleryLink extends ActiveRecord
|
|
{
|
|
public static function tableName()
|
|
{
|
|
return 'rescue_animal_gallery_link';
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['animal_id', 'gallery_id', 'contentcontainer_id'], 'required'],
|
|
[['animal_id', 'gallery_id', 'contentcontainer_id'], 'integer'],
|
|
[['animal_id'], 'unique'],
|
|
[['gallery_id'], 'unique'],
|
|
];
|
|
}
|
|
|
|
public function beforeSave($insert)
|
|
{
|
|
if (!parent::beforeSave($insert)) {
|
|
return false;
|
|
}
|
|
|
|
$now = date('Y-m-d H:i:s');
|
|
if ($insert && empty($this->created_at)) {
|
|
$this->created_at = $now;
|
|
}
|
|
|
|
$this->updated_at = $now;
|
|
return true;
|
|
}
|
|
|
|
public function getAnimal()
|
|
{
|
|
return $this->hasOne(Animal::class, ['id' => 'animal_id']);
|
|
}
|
|
}
|