Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmackay committed Nov 17, 2016
2 parents 1ee01d1 + a04e816 commit 3f6dfa6
Show file tree
Hide file tree
Showing 17 changed files with 355 additions and 49 deletions.
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"logo": "http://www.ushahidi.com/assets/img/favicon.ico",
"success_url": "/",
"addons": [
"cleardb"
"cleardb",
"scheduler"
]
}
20 changes: 8 additions & 12 deletions application/classes/Log/Raven.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,17 @@ public function write(array $messages)
{
// Write each message into the log file
// Format: time --- level: body
$this->raven->getIdent(
$this->raven->captureException($message['additional']['exception'])
);
$this->raven->captureException($message['additional']['exception']);
} else {
// Write each message into the log file
// Format: time --- level: body
$this->raven->getIdent(
$this->raven->captureMessage(
$this->format_message($message),
$message,
[
'level' => $this->mapRavenLevel($message['level'])
],
$message['trace']
)
$this->raven->captureMessage(
$this->format_message($message),
$message,
[
'level' => $this->mapRavenLevel($message['level'])
],
$message['trace']
);
}
}
Expand Down
8 changes: 8 additions & 0 deletions application/classes/Ushahidi/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ public static function init()
$di->set('repository.post.point', $di->lazyNew('Ushahidi_Repository_Post_Point'));
$di->set('repository.post.relation', $di->lazyNew('Ushahidi_Repository_Post_Relation'));
$di->set('repository.post.text', $di->lazyNew('Ushahidi_Repository_Post_Text'));
$di->set('repository.post.description', $di->lazyNew('Ushahidi_Repository_Post_Description'));
$di->set('repository.post.varchar', $di->lazyNew('Ushahidi_Repository_Post_Varchar'));
$di->set('repository.post.title', $di->lazyNew('Ushahidi_Repository_Post_Title'));
$di->set('repository.post.media', $di->lazyNew('Ushahidi_Repository_Post_Media'));

// The post value repo factory
Expand All @@ -482,7 +484,9 @@ public static function init()
'point' => $di->lazyGet('repository.post.point'),
'relation' => $di->lazyGet('repository.post.relation'),
'text' => $di->lazyGet('repository.post.text'),
'description' => $di->lazyGet('repository.post.description'),
'varchar' => $di->lazyGet('repository.post.varchar'),
'title' => $di->lazyGet('repository.post.title'),
'media' => $di->lazyGet('repository.post.media'),
],
];
Expand Down Expand Up @@ -612,6 +616,8 @@ public static function init()
$di->set('validator.post.point', $di->lazyNew('Ushahidi_Validator_Post_Point'));
$di->set('validator.post.relation', $di->lazyNew('Ushahidi_Validator_Post_Relation'));
$di->set('validator.post.varchar', $di->lazyNew('Ushahidi_Validator_Post_Varchar'));
$di->set('validator.post.video', $di->lazyNew('Ushahidi_Validator_Post_Video'));
$di->set('validator.post.title', $di->lazyNew('Ushahidi_Validator_Post_Title'));
$di->set('validator.post.media', $di->lazyNew('Ushahidi_Validator_Post_Media'));
$di->params['Ushahidi_Validator_Post_Media'] = [
'media_repo' => $di->lazyGet('repository.media')
Expand All @@ -630,7 +636,9 @@ public static function init()
'point' => $di->lazyGet('validator.post.point'),
'relation' => $di->lazyGet('validator.post.relation'),
'varchar' => $di->lazyGet('validator.post.varchar'),
'title' => $di->lazyGet('validator.post.title'),
'media' => $di->lazyGet('validator.post.media'),
'video' => $di->lazyGet('validator.post.video'),
],
];

Expand Down
2 changes: 0 additions & 2 deletions application/classes/Ushahidi/Formatter/Post/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ protected function generateCSVRecords($records)
// Sort the columns from the heading so that they match with the record keys
ksort($heading);

Kohana::$log->add(Log::INFO, print_r($heading, true));

// Send response as CSV download
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/csv; charset=utf-8');
Expand Down
32 changes: 32 additions & 0 deletions application/classes/Ushahidi/Repository/Post/Description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi Post Varchar Repository
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

use Ushahidi\Core\Entity\PostValue;
use Ushahidi\Core\Entity\PostValueRepository;

class Ushahidi_Repository_Post_Description extends Ushahidi_Repository_Post_Text
{
public function getAllForPost($post_id, Array $include_attributes = [])
{
return [];
}
// DeleteRepository
// This value should be immutable and unchangeable
public function createValue($value, $form_attribute_id, $post_id)
{
return 0;
}

public function updateValue($id, $value)
{
return 0;
}
}
30 changes: 30 additions & 0 deletions application/classes/Ushahidi/Repository/Post/Title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi Post Varchar Repository
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

use Ushahidi\Core\Entity\PostValue;
use Ushahidi\Core\Entity\PostValueRepository;

class Ushahidi_Repository_Post_Title extends Ushahidi_Repository_Post_Varchar
{
public function getAllForPost($post_id, Array $include_attributes = [])
{
return [];
}
public function createValue($value, $form_attribute_id, $post_id)
{
return 0;
}

public function updateValue($id, $value)
{
return 0;
}
}
1 change: 0 additions & 1 deletion application/classes/Ushahidi/Repository/Post/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function getAllForPost($post_id, Array $include_attributes = [])
}

$results = $query->execute($this->db);

return $this->getCollection($results->as_array());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected function getRules()
'location',
'number',
'relation',
'upload'
'upload',
'video'
]]],
],
'type' => [
Expand All @@ -65,7 +66,9 @@ protected function getRules()
'datetime',
'link',
'relation',
'media'
'media',
'title',
'description'
]]],
],
'required' => [
Expand Down
23 changes: 23 additions & 0 deletions application/classes/Ushahidi/Validator/Post/Title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');

/**
* Ushahidi Post Varchar Validator
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/

class Ushahidi_Validator_Post_Title extends Ushahidi_Validator_Post_Varchar
{
protected function validate($value)
{
if (!is_scalar($value)) {
return 'scalar';
}
if (!Valid::max_length($value, 255)) {
return 'max_length';
}
}
}
25 changes: 25 additions & 0 deletions application/classes/Ushahidi/Validator/Post/Video.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Ushahidi Post Video Validator
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application
* @copyright 2016 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
class Ushahidi_Validator_Post_Video extends Ushahidi_Validator_Post_ValueValidator
{
protected function validate($value)
{
if (!Valid::url($value)) {
return 'url';
}
if (!$this->checkVideoTypes($value)) {
return 'video_type';
}
}

protected function checkVideoTypes($value) {
return (strpos($value, 'youtube') !== false || strpos($value, 'vimeo') !== false);
}
}
1 change: 1 addition & 0 deletions application/messages/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
'lat' => 'the field :param1 must contain a valid latitude',
'lon' => 'the field :param1 must contain a valid longitude',
'url' => 'The field :param1 must be a url, Given: :param2',
'video_type' => 'The field :param1 must be either a youtube or vimeo url, Given: :param2',
]
];
40 changes: 37 additions & 3 deletions application/tests/datasets/ushahidi/Base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ forms:
description: "Missing persons"
require_approval: 0
everyone_can_create: 0
-
id: 3
name: "Video Embed"
type: "report"
description: "Test video embed"
require_approval: 0
everyone_can_create: 0
form_roles:
-
id: 1
Expand All @@ -95,6 +102,10 @@ form_stages:
id: 4
form_id: 2
label: "Main"
-
id: 5
form_id: 3
label: "Post"
form_attributes:
-
id: 1
Expand Down Expand Up @@ -133,10 +144,10 @@ form_attributes:
id: 4
label: "Description"
key: "description"
type: "text"
type: "description"
input: "textarea"
required: 0
priority: 2
priority: 0
options: ""
cardinality: 1
form_stage_id: 1
Expand Down Expand Up @@ -260,6 +271,29 @@ form_attributes:
cardinality: 0
config: '[]'
form_stage_id: 1
-
id: 16
label: "Video"
key: "video_field"
type: "video"
input: "video"
required: 0
options: '[]'
priority: 5
cardinality: 0
config: '[]'
form_stage_id: 5
-
id: 17
label: "Title"
key: "title"
type: "title"
input: "text"
required: 0
priority: 0
options: ""
cardinality: 1
form_stage_id: 1
posts:
-
id: 1
Expand Down Expand Up @@ -605,7 +639,7 @@ post_varchar:
value: "some-string"
-
id: 7
post_id: 105
post_id: 106
form_attribute_id: 1
value: "some-string"
-
Expand Down
Loading

0 comments on commit 3f6dfa6

Please sign in to comment.