Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Jun 29, 2016
2 parents 09916fc + 962d98d commit af6618d
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 247 deletions.
9 changes: 9 additions & 0 deletions application/classes/Ushahidi/Repository/Form/Attribute.php
Expand Up @@ -14,6 +14,9 @@
use Ushahidi\Core\Entity\FormAttribute;
use Ushahidi\Core\Entity\FormAttributeRepository;

use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;

class Ushahidi_Repository_Form_Attribute extends Ushahidi_Repository implements
FormAttributeRepository
{
Expand All @@ -31,6 +34,12 @@ public function create(Entity $entity)
{
$record = $entity->asArray();
unset($record['form_id']);
try {
$uuid = Uuid::uuid4();
$record['key'] = $uuid->toString();
} catch (UnsatisfiedDependencyException $e) {
Kohana::$log->add(Log::ERROR, $e->getMessage());
}
return $this->executeInsertAttribute($this->removeNullValues($record));
}

Expand Down
Expand Up @@ -18,9 +18,6 @@ class Ushahidi_Validator_Form_Attribute_Create extends Ushahidi_Validator_Form_A
public function getRules()
{
return array_merge_recursive(parent::getRules(), [
'key' => [
['not_empty'],
],
'label' => [
['not_empty'],
],
Expand Down
8 changes: 4 additions & 4 deletions application/classes/Ushahidi/Validator/Post/Create.php
Expand Up @@ -194,7 +194,7 @@ public function checkValues(Validation $validation, $attributes, $data)
if (count($values) > $attribute->cardinality AND $attribute->cardinality != 0)
{
$validation->error('values', 'tooManyValues', [
$key,
$attribute->label,
$attribute->cardinality
]);
}
Expand All @@ -207,11 +207,11 @@ public function checkValues(Validation $validation, $attributes, $data)

if (!is_array($values))
{
$validation->error('values', 'notAnArray', [$key]);
$validation->error('values', 'notAnArray', [$attribute->label]);
}
elseif ($error = $validator->check($values))
{
$validation->error('values', $error, [$key, $values]);
$validation->error('values', $error, [$attribute->label, $values]);
}
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ public function checkRequiredAttributes(Validation $validation, $attributes, $da
{
$stage = $this->stage_repo->get($stage_id);
// If a required attribute isn't completed, throw an error
$validation->error('values', 'attributeRequired', [$attr->key, $stage->label]);
$validation->error('values', 'attributeRequired', [$attr->label, $stage->label]);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions application/messages/post.php
Expand Up @@ -21,16 +21,16 @@
'stageRequired' => 'Stage ":param1" is required before publishing',

'values' => [
'date' => ':field.:param1 must be a date, Given: :param2',
'decimal' => ':field.:param1 must be a decimal with :param2 places, Given: :param2',
'digit' => ':field.:param1 must be a digit, Given: :param2',
'email' => ':field.:param1 must be an email address, Given: :param2',
'exists' => ':field.:param1 must be a valid post id, Post id: :param2',
'max_length' => ':field.:param1 must not exceed :param2 characters long, Given: :param2',
'invalidForm' => ':field.:param1 has the wrong post type, Post id: :param2',
'numeric' => ':field.:param1 must be numeric, Given: :param2',
'scalar' => ':field.:param1 must be scalar, Given: :param2',
'point' => ':field.:param1 must be an array of lat and lon',
'url' => ':field.:param1 must be a url, Given: :param2',
'date' => 'The field :param1 must be a date, Given: :param2',
'decimal' => 'The field :param1 must be a decimal with 2 places, Given: :param2',
'digit' => 'The field :param1 must be a digit, Given: :param2',
'email' => 'The field :param1 must be an email address, Given: :param2',
'exists' => 'The field :param1 must be a valid post id, Post id: :param2',
'max_length' => 'The field :param1 must not exceed :param2 characters long, Given: :param2',
'invalidForm' => 'The field :param1 has the wrong post type, Post id: :param2',
'numeric' => 'The field :param1 must be numeric, Given: :param2',
'scalar' => 'The field :param1 must be scalar, Given: :param2',
'point' => 'The field :param1 must be an array of lat and lon',
'url' => 'The field :param1 must be a url, Given: :param2',
]
];
1 change: 0 additions & 1 deletion application/tests/features/forms/api.attributes.feature
Expand Up @@ -116,7 +116,6 @@ Feature: Testing the Form Attributes API
"""
When I request "/forms/1/attributes"
Then the response is JSON
And the "key" property equals "value_test"
And the "label" property equals "Value test"
And the "instructions" property equals "Much longer boring instructions"
And the "type" property equals "varchar"
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -45,7 +45,8 @@
"beheh/flaps": "dev-master",
"doctrine/cache": "^1.5@dev",
"satooshi/php-coveralls": "^2.0@dev",
"henrikbjorn/phpspec-code-coverage": "~2.0"
"henrikbjorn/phpspec-code-coverage": "~2.0",
"ramsey/uuid": "^3.4.1"
},
"require-dev": {
"behat/behat": "~2.5.2",
Expand Down

0 comments on commit af6618d

Please sign in to comment.