Initial import of animal_management module
This commit is contained in:
49
models/AnimalMedicalVisitFieldValue.php
Normal file
49
models/AnimalMedicalVisitFieldValue.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\animal_management\models;
|
||||
|
||||
use humhub\components\ActiveRecord;
|
||||
use humhub\modules\rescue_foundation\models\RescueFieldDefinition;
|
||||
|
||||
class AnimalMedicalVisitFieldValue extends ActiveRecord
|
||||
{
|
||||
public static function tableName()
|
||||
{
|
||||
return 'rescue_animal_medical_visit_field_value';
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['medical_visit_id', 'field_definition_id'], 'required'],
|
||||
[['medical_visit_id', 'field_definition_id'], 'integer'],
|
||||
[['value_text', 'value_json'], 'string'],
|
||||
[['medical_visit_id', 'field_definition_id'], 'unique', 'targetAttribute' => ['medical_visit_id', 'field_definition_id']],
|
||||
];
|
||||
}
|
||||
|
||||
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 getMedicalVisit()
|
||||
{
|
||||
return $this->hasOne(AnimalMedicalVisit::class, ['id' => 'medical_visit_id']);
|
||||
}
|
||||
|
||||
public function getFieldDefinition()
|
||||
{
|
||||
return $this->hasOne(RescueFieldDefinition::class, ['id' => 'field_definition_id']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user