Initial import of space_profiles module

This commit is contained in:
Kelin Rescue Hub
2026-04-04 13:11:50 -04:00
commit 87a59e5a0a
35 changed files with 1627 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
<?php
use humhub\components\Migration;
class m260401_130000_initial extends Migration
{
public function safeUp()
{
$this->safeCreateTable('rescue_space_profile', [
'id' => $this->primaryKey(),
'contentcontainer_id' => $this->integer()->notNull(),
'rescue_name' => $this->string(190)->notNull(),
'address' => $this->string(255)->notNull(),
'city' => $this->string(120)->notNull(),
'state' => $this->string(2)->notNull(),
'zip' => $this->string(10)->notNull(),
'email' => $this->string(190)->notNull(),
'phone' => $this->string(32)->notNull(),
'animals_we_accept' => $this->text()->notNull(),
'description' => $this->text()->notNull(),
'mission_statement' => $this->text()->notNull(),
'template_key' => $this->string(64)->defaultValue('rescue_center')->notNull(),
'header_html' => $this->text()->null(),
'body_html' => $this->text()->null(),
'footer_html' => $this->text()->null(),
'icon_path' => $this->string(255)->null(),
'background_image_path' => $this->string(255)->null(),
'created_at' => $this->dateTime()->null(),
'updated_at' => $this->dateTime()->null(),
]);
$this->safeCreateIndex('idx_rescue_space_profile_container', 'rescue_space_profile', 'contentcontainer_id', true);
$this->safeAddForeignKey(
'fk_rescue_space_profile_container',
'rescue_space_profile',
'contentcontainer_id',
'contentcontainer',
'id',
'CASCADE'
);
$this->seedFieldMetadata();
}
public function safeDown()
{
$this->safeDropTable('rescue_space_profile');
}
private function seedFieldMetadata(): void
{
if ($this->db->getSchema()->getTableSchema('rescue_field_definition', true) === null) {
return;
}
$createdAt = date('Y-m-d H:i:s');
$rows = [
['rescue_name', 'Rescue name', 'text', 1, 1, 110],
['address', 'Address', 'text', 1, 1, 120],
['city', 'City', 'text', 1, 1, 130],
['state', 'State', 'text', 1, 1, 140],
['zip', 'ZIP', 'text', 1, 1, 150],
['email', 'Email', 'email', 1, 1, 160],
['phone', 'Phone', 'text', 1, 1, 170],
['animals_we_accept', 'Animals we accept', 'textarea', 1, 1, 180],
['description', 'Description', 'textarea', 1, 1, 190],
['mission_statement', 'Mission statement', 'textarea', 1, 1, 200],
['template_key', 'Template', 'select', 1, 1, 205],
['header_html', 'Header HTML', 'html', 0, 1, 210],
['body_html', 'Body HTML', 'html', 0, 1, 220],
['footer_html', 'Footer HTML', 'html', 0, 1, 230],
['icon_path', 'Icon', 'image', 0, 1, 240],
['background_image_path', 'Background image', 'image', 0, 1, 250],
];
foreach ($rows as $row) {
[$fieldKey, $label, $inputType, $required, $isCore, $sortOrder] = $row;
$exists = (new \yii\db\Query())
->from('rescue_field_definition')
->where(['module_id' => 'space_profiles', 'field_key' => $fieldKey])
->exists($this->db);
if ($exists) {
continue;
}
$this->insert('rescue_field_definition', [
'module_id' => 'space_profiles',
'group_key' => 'space_profile',
'field_key' => $fieldKey,
'label' => $label,
'input_type' => $inputType,
'required' => $required,
'is_core' => $isCore,
'is_active' => 1,
'visibility' => 'public',
'options' => '{}',
'sort_order' => $sortOrder,
'created_at' => $createdAt,
'updated_at' => $createdAt,
]);
}
}
}