Initial import of animal_management module
This commit is contained in:
87
models/AnimalProgressUpdate.php
Normal file
87
models/AnimalProgressUpdate.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\animal_management\models;
|
||||
|
||||
use humhub\components\ActiveRecord;
|
||||
use Yii;
|
||||
|
||||
class AnimalProgressUpdate extends ActiveRecord
|
||||
{
|
||||
public static function tableName()
|
||||
{
|
||||
return 'rescue_animal_progress_update';
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['animal_id'], 'required'],
|
||||
[['animal_id', 'created_by', 'post_to_space_feed', 'post_to_animal_feed'], 'integer'],
|
||||
[['update_at'], 'safe'],
|
||||
[['vitals', 'behavior_notes', 'meal_plan_changes', 'housing_changes', 'medical_concerns'], 'string'],
|
||||
[['weight'], 'string', 'max' => 32],
|
||||
];
|
||||
}
|
||||
|
||||
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 getFieldValues()
|
||||
{
|
||||
return $this->hasMany(AnimalProgressUpdateFieldValue::class, ['progress_update_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getCustomFieldDisplayValues(bool $includeRestricted = false): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
foreach ($this->getFieldValues()->with('fieldDefinition')->all() as $fieldValue) {
|
||||
$definition = $fieldValue->fieldDefinition;
|
||||
if ($definition === null || (string)$definition->module_id !== 'animal_management') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((int)$definition->is_active !== 1 || (string)$definition->group_key !== 'animal_progress_update') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$visibility = (string)$definition->visibility;
|
||||
if (!$includeRestricted && $visibility !== 'public') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$raw = trim((string)$fieldValue->value_text);
|
||||
if ($raw === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$display = $raw;
|
||||
$inputType = (string)$definition->input_type;
|
||||
if ($inputType === 'boolean') {
|
||||
$display = in_array(strtolower($raw), ['1', 'true', 'yes', 'on'], true)
|
||||
? Yii::t('AnimalManagementModule.base', 'Yes')
|
||||
: Yii::t('AnimalManagementModule.base', 'No');
|
||||
}
|
||||
|
||||
$values[] = [
|
||||
'field_key' => (string)$definition->field_key,
|
||||
'label' => trim((string)$definition->label) !== '' ? (string)$definition->label : (string)$definition->field_key,
|
||||
'value' => $display,
|
||||
];
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user