Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USH-1496 - Add backend "phone" field and database table. #5010

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -780,6 +782,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
Loading