Skip to content

Commit

Permalink
field config and db table
Browse files Browse the repository at this point in the history
  • Loading branch information
ushahidlee committed Nov 2, 2024
1 parent 9376f6f commit e169627
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use Phinx\Migration\AbstractMigration;

class CreatePhoneFieldTable extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$this->table('post_phone')
->addColumn('post_id', 'integer')
->addColumn('form_attribute_id', 'integer')
->addColumn('value', 'string', [
'limit' => 32,
])
->addColumn('created', 'integer', ['default' => 0])
->addForeignKey('post_id', 'posts', 'id', [
'delete' => 'CASCADE',
'update' => 'CASCADE',
])
->create();
}
}
14 changes: 11 additions & 3 deletions src/Ushahidi/Modules/V5/Models/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Post extends BaseModel
use HasFactory;

public const DEFAULT_SOURCE_TYPE = "web";

/** Data used for only parameters
*
*
Expand Down Expand Up @@ -96,7 +96,8 @@ class Post extends BaseModel
'valuesRelation',
'valuesPostsMedia',
// 'valuesPostsSet',
'valuesPostTag'
'valuesPostTag',
'valuesPhone'
]
]

Expand Down Expand Up @@ -660,7 +661,8 @@ protected static function valueTypesRelationships()
'Relation',
'PostsMedia',
// 'PostsSet',
'PostTag'
'PostTag',
'Phone'
];
return array_map(function ($t) {
return "values${t}";
Expand Down Expand Up @@ -777,6 +779,12 @@ public function valuesPostTag()
->select('posts_tags.*');
}

public function valuesPhone()
{
return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostPhone', 'post_id', 'id')
->select('post_phone.*');
}

public function postStages()
{
return $this->hasMany('Ushahidi\Modules\V5\Models\PostStages', 'post_id', 'id');
Expand Down
40 changes: 40 additions & 0 deletions src/Ushahidi/Modules/V5/Models/PostValues/PostPhone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Ushahidi\Modules\V5\Models\PostValues;

class PostPhone extends PostValue
{
public $table = 'post_phone';

/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function validationMessages()
{
return [
];
}//end validationMessages()

/**
* Return all validation rules
*
* @return array
*/
public function getRules()
{
$rules = [
'value' => ['string', 'max:32'],
];
return array_merge(parent::getRules(), $rules);
}//end getRules()

/**
* @return bool
*/
public function getValueAttribute($value)
{
return $value;
}
}//end class
1 change: 1 addition & 0 deletions src/Ushahidi/Modules/V5/Requests/SurveyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ private function postMethodRules()
'title',
'description',
'tags',
'phone',
]
)
],
Expand Down

0 comments on commit e169627

Please sign in to comment.