Skip to content

Commit 5610ab7

Browse files
ushahidleetuxpiper
authored andcommitted
field config and db table (#5010)
1 parent a909ec4 commit 5610ab7

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
use Phinx\Migration\AbstractMigration;
4+
5+
class CreatePhoneFieldTable extends AbstractMigration
6+
{
7+
/**
8+
* Change Method.
9+
*
10+
* Write your reversible migrations using this method.
11+
*
12+
* More information on writing migrations is available here:
13+
* https://book.cakephp.org/phinx/0/en/migrations.html
14+
*
15+
* The following commands can be used in this method and Phinx will
16+
* automatically reverse them when rolling back:
17+
*
18+
* createTable
19+
* renameTable
20+
* addColumn
21+
* addCustomColumn
22+
* renameColumn
23+
* addIndex
24+
* addForeignKey
25+
*
26+
* Any other destructive changes will result in an error when trying to
27+
* rollback the migration.
28+
*
29+
* Remember to call "create()" or "update()" and NOT "save()" when working
30+
* with the Table class.
31+
*/
32+
public function change()
33+
{
34+
$this->table('post_phone')
35+
->addColumn('post_id', 'integer')
36+
->addColumn('form_attribute_id', 'integer')
37+
->addColumn('value', 'string', [
38+
'limit' => 32,
39+
])
40+
->addColumn('created', 'integer', ['default' => 0])
41+
->addForeignKey('post_id', 'posts', 'id', [
42+
'delete' => 'CASCADE',
43+
'update' => 'CASCADE',
44+
])
45+
->create();
46+
}
47+
}

src/Ushahidi/Modules/V5/Models/Post/Post.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Post extends BaseModel
3333
use HasFactory;
3434

3535
public const DEFAULT_SOURCE_TYPE = "web";
36-
36+
3737
/** Data used for only parameters
3838
*
3939
*
@@ -96,7 +96,8 @@ class Post extends BaseModel
9696
'valuesRelation',
9797
'valuesPostsMedia',
9898
// 'valuesPostsSet',
99-
'valuesPostTag'
99+
'valuesPostTag',
100+
'valuesPhone'
100101
]
101102
]
102103

@@ -660,7 +661,8 @@ protected static function valueTypesRelationships()
660661
'Relation',
661662
'PostsMedia',
662663
// 'PostsSet',
663-
'PostTag'
664+
'PostTag',
665+
'Phone'
664666
];
665667
return array_map(function ($t) {
666668
return "values${t}";
@@ -780,6 +782,12 @@ public function valuesPostTag()
780782
->select('posts_tags.*');
781783
}
782784

785+
public function valuesPhone()
786+
{
787+
return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostPhone', 'post_id', 'id')
788+
->select('post_phone.*');
789+
}
790+
783791
public function postStages()
784792
{
785793
return $this->hasMany('Ushahidi\Modules\V5\Models\PostStages', 'post_id', 'id');
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Ushahidi\Modules\V5\Models\PostValues;
4+
5+
class PostPhone extends PostValue
6+
{
7+
public $table = 'post_phone';
8+
9+
/**
10+
* Get the error messages for the defined validation rules.
11+
*
12+
* @return array
13+
*/
14+
public function validationMessages()
15+
{
16+
return [
17+
];
18+
}//end validationMessages()
19+
20+
/**
21+
* Return all validation rules
22+
*
23+
* @return array
24+
*/
25+
public function getRules()
26+
{
27+
$rules = [
28+
'value' => ['string', 'max:32'],
29+
];
30+
return array_merge(parent::getRules(), $rules);
31+
}//end getRules()
32+
33+
/**
34+
* @return bool
35+
*/
36+
public function getValueAttribute($value)
37+
{
38+
return $value;
39+
}
40+
}//end class

src/Ushahidi/Modules/V5/Requests/SurveyRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ private function postMethodRules()
264264
'title',
265265
'description',
266266
'tags',
267+
'phone',
267268
]
268269
)
269270
],

0 commit comments

Comments
 (0)