diff --git a/database/migrations/phinx/20241101041234_create_phone_field_table.php b/database/migrations/phinx/20241101041234_create_phone_field_table.php new file mode 100644 index 000000000..16443ca62 --- /dev/null +++ b/database/migrations/phinx/20241101041234_create_phone_field_table.php @@ -0,0 +1,47 @@ +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(); + } +} diff --git a/src/Ushahidi/Modules/V5/Models/Post/Post.php b/src/Ushahidi/Modules/V5/Models/Post/Post.php index c92060cab..8fcff36c6 100644 --- a/src/Ushahidi/Modules/V5/Models/Post/Post.php +++ b/src/Ushahidi/Modules/V5/Models/Post/Post.php @@ -33,7 +33,7 @@ class Post extends BaseModel use HasFactory; public const DEFAULT_SOURCE_TYPE = "web"; - + /** Data used for only parameters * * @@ -96,7 +96,8 @@ class Post extends BaseModel 'valuesRelation', 'valuesPostsMedia', // 'valuesPostsSet', - 'valuesPostTag' + 'valuesPostTag', + 'valuesPhone' ] ] @@ -660,7 +661,8 @@ protected static function valueTypesRelationships() 'Relation', 'PostsMedia', // 'PostsSet', - 'PostTag' + 'PostTag', + 'Phone' ]; return array_map(function ($t) { return "values${t}"; @@ -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'); diff --git a/src/Ushahidi/Modules/V5/Models/PostValues/PostPhone.php b/src/Ushahidi/Modules/V5/Models/PostValues/PostPhone.php new file mode 100644 index 000000000..64d501527 --- /dev/null +++ b/src/Ushahidi/Modules/V5/Models/PostValues/PostPhone.php @@ -0,0 +1,40 @@ + ['string', 'max:32'], + ]; + return array_merge(parent::getRules(), $rules); + }//end getRules() + + /** + * @return bool + */ + public function getValueAttribute($value) + { + return $value; + } +}//end class diff --git a/src/Ushahidi/Modules/V5/Requests/SurveyRequest.php b/src/Ushahidi/Modules/V5/Requests/SurveyRequest.php index 4bcc98a5e..09ed00324 100644 --- a/src/Ushahidi/Modules/V5/Requests/SurveyRequest.php +++ b/src/Ushahidi/Modules/V5/Requests/SurveyRequest.php @@ -264,6 +264,7 @@ private function postMethodRules() 'title', 'description', 'tags', + 'phone', ] ) ],