chore: bootstrap module from working instance and add install guide
This commit is contained in:
69
models/DonationGoal.php
Normal file
69
models/DonationGoal.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\donations\models;
|
||||
|
||||
use humhub\components\ActiveRecord;
|
||||
use Yii;
|
||||
|
||||
class DonationGoal extends ActiveRecord
|
||||
{
|
||||
public const TYPE_RESCUE_GENERAL = 'rescue_general';
|
||||
public const TYPE_ANIMAL = 'animal';
|
||||
public const TYPE_NEED = 'need';
|
||||
public const TYPE_SPECIAL_NEED = 'special_need';
|
||||
public const TYPE_SPONSORSHIP = 'sponsorship';
|
||||
|
||||
public static function tableName()
|
||||
{
|
||||
return 'rescue_donation_goal';
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['contentcontainer_id', 'goal_type', 'title'], 'required'],
|
||||
[['contentcontainer_id', 'target_animal_id', 'is_active'], 'integer'],
|
||||
[['description'], 'string'],
|
||||
[['target_amount', 'current_amount'], 'number', 'min' => 0],
|
||||
[['goal_type'], 'string', 'max' => 32],
|
||||
[['title'], 'string', 'max' => 190],
|
||||
[['image_path'], 'string', 'max' => 255],
|
||||
[['currency'], 'string', 'max' => 8],
|
||||
[['goal_type'], 'in', 'range' => array_keys(self::goalTypeOptions())],
|
||||
];
|
||||
}
|
||||
|
||||
public static function goalTypeOptions(): array
|
||||
{
|
||||
return [
|
||||
self::TYPE_RESCUE_GENERAL => Yii::t('DonationsModule.base', 'Rescue General'),
|
||||
self::TYPE_ANIMAL => Yii::t('DonationsModule.base', 'Animal'),
|
||||
self::TYPE_NEED => Yii::t('DonationsModule.base', 'Need Specific'),
|
||||
self::TYPE_SPECIAL_NEED => Yii::t('DonationsModule.base', 'Special Need'),
|
||||
self::TYPE_SPONSORSHIP => Yii::t('DonationsModule.base', 'Sponsorship'),
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (empty($this->currency)) {
|
||||
$this->currency = 'USD';
|
||||
}
|
||||
|
||||
if ($this->is_active === null) {
|
||||
$this->is_active = 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user