diff --git a/app/Http/Controllers/API/Posts/GeoJSONController.php b/app/Http/Controllers/API/Posts/GeoJSONController.php
index b9635235d5..16e95bb2cf 100644
--- a/app/Http/Controllers/API/Posts/GeoJSONController.php
+++ b/app/Http/Controllers/API/Posts/GeoJSONController.php
@@ -13,6 +13,9 @@
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
+use Ushahidi\App\Util\Tile;
+use Ushahidi\App\Util\BoundingBox;
+
class GeoJSONController extends PostsController
{
@@ -27,9 +30,9 @@ public function prepBoundingBox(Request $request)
if ($zoom !== false and
$x !== false and
$y !== false) {
- $boundingBox = \Util_Tile::tileToBoundingBox($zoom, $x, $y);
+ $boundingBox = Tile::tileToBoundingBox($zoom, $x, $y);
- $request->merge(['bbox' => implode(',', $boundingBox->as_array())]);
+ $request->merge(['bbox' => implode(',', $boundingBox->asArray())]);
}
}
diff --git a/app/Http/Controllers/RESTController.php b/app/Http/Controllers/RESTController.php
index 7fe7372dfa..668923c55e 100644
--- a/app/Http/Controllers/RESTController.php
+++ b/app/Http/Controllers/RESTController.php
@@ -44,10 +44,9 @@ public function __construct(UsecaseFactory $usecaseFactory)
/**
* @var array List of HTTP methods which may be cached
*/
- protected $cacheableMethods = array
- (
+ protected $cacheableMethods = [
Request::METHOD_GET,
- );
+ ];
/**
* Get current api version
diff --git a/app/Passport/TokenGuard.php b/app/Passport/TokenGuard.php
index f7ef9fd297..b1cd65f148 100644
--- a/app/Passport/TokenGuard.php
+++ b/app/Passport/TokenGuard.php
@@ -146,9 +146,10 @@ protected function authenticateViaBearerToken($request)
return $token ? $user->withAccessToken($token) : null;
} catch (OAuthServerException $e) {
- // return Container::getInstance()->make(
- // ExceptionHandler::class
- // )->report($e);
+ // Log the error
+ Container::getInstance()->make(
+ ExceptionHandler::class
+ )->report($e);
// Adding WWW-Authenticate ourselves because thephpleague/oauth2-server sucks
// https://github.com/thephpleague/oauth2-server/issues/738
@@ -157,6 +158,8 @@ protected function authenticateViaBearerToken($request)
$e->getMessage(),
$e->getHttpHeaders() + ['WWW-Authenticate' => 'Bearer realm="OAuth"']
);
+
+ return;
}
}
diff --git a/application/classes/OAuth2/Request.php b/application/classes/OAuth2/Request.php
deleted file mode 100644
index 3e290d98b2..0000000000
--- a/application/classes/OAuth2/Request.php
+++ /dev/null
@@ -1,54 +0,0 @@
-
- * @package Ushahidi\OAuth2
- * @copyright 2014 Ushahidi
- * @license http://mit-license.org/
- * @link http://github.com/php-loep/oauth2-server
- */
-
-use League\OAuth2\Server\Util\RequestInterface;
-
-class OAuth2_Request implements RequestInterface {
-
- public function __construct()
- {
- $this->request = Request::current();
- }
-
- public function get($index = null)
- {
- return $this->request->query($index);
- }
-
- public function post($index = null)
- {
- return $this->request->post($index);
- }
-
- public function cookie($index = null)
- {
- return Arr::get($_COOKIE, $index);
- }
-
- public function file($index = null)
- {
- return Arr::get($_FILE, $index);
- }
-
- public function server($index = null)
- {
- return Arr::get($_SERVER, $index);
- }
-
- public function header($index = null)
- {
- return $this->request->headers($index);
- }
-}
-
diff --git a/application/classes/OAuth2/Storage.php b/application/classes/OAuth2/Storage.php
deleted file mode 100644
index d8a58e295a..0000000000
--- a/application/classes/OAuth2/Storage.php
+++ /dev/null
@@ -1,90 +0,0 @@
-
- * @package Ushahidi\OAuth2
- * @copyright 2014 Ushahidi
- * @license http://mit-license.org/
- * @link http://github.com/php-loep/oauth2-server
- */
-
-abstract class OAuth2_Storage {
-
- protected $db = 'default';
-
- public function __construct($db = null)
- {
- if ($db)
- {
- $this->db = $db;
- }
- }
-
- private function apply_where_to_query(Database_Query $query, array $where)
- {
- foreach ($where as $col => $value)
- {
- $query->where($col, is_array($value) ? 'IN' : '=', $value);
- }
- return $query;
- }
-
- protected function select_results(Database_Query $query)
- {
- $results = $query->execute($this->db);
- return count($results) ? $results->as_array() : FALSE;
- }
-
- protected function select_one_result(Database_Query $query)
- {
- $results = $query->execute($this->db);
- return count($results) ? $results->current() : FALSE;
- }
-
- protected function select_one_column(Database_Query $query, $column)
- {
- $results = $query->execute($this->db);
- return count($results) ? $results->get($column) : FALSE;
- }
-
- protected function select($table, array $where = NULL)
- {
- $query = DB::select()
- ->from($table);
- if ($where)
- {
- $this->apply_where_to_query($query, $where);
- }
- return $query;
- }
-
- protected function insert($table, array $data)
- {
- $query = DB::insert($table)
- ->columns(array_keys($data))
- ->values(array_values($data));
- list($id) = $query->execute($this->db);
- return $id;
- }
-
- protected function update($table, array $data, array $where)
- {
- $query = DB::update($table)
- ->set($data);
- $this->apply_where_to_query($query, $where);
- $count = $query->execute($this->db);
- return $count;
- }
-
- protected function delete($table, array $where)
- {
- $query = DB::delete($table);
- $this->apply_where_to_query($query, $where);
- $count = $query->execute($this->db);
- return $count;
- }
-}
diff --git a/application/classes/OAuth2/Storage/Client.php b/application/classes/OAuth2/Storage/Client.php
deleted file mode 100644
index 6d0dbb6a94..0000000000
--- a/application/classes/OAuth2/Storage/Client.php
+++ /dev/null
@@ -1,138 +0,0 @@
-
- * @package Ushahidi\OAuth2
- * @copyright 2014 Ushahidi
- * @license http://mit-license.org/
- * @link http://github.com/php-loep/oauth2-server
- */
-
-use League\OAuth2\Server\Storage\ClientInterface;
-
-class OAuth2_Storage_Client extends OAuth2_Storage implements ClientInterface
-{
- /**
- * Validate a client
- *
- * Example SQL query:
- *
- *
- * # Client ID + redirect URI
- * SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name,
- * oauth_clients.auto_approve
- * FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id
- * WHERE oauth_clients.id = :clientId AND oauth_client_endpoints.redirect_uri = :redirectUri
- *
- * # Client ID + client secret
- * SELECT oauth_clients.id, oauth_clients.secret, oauth_clients.name, oauth_clients.auto_approve FROM oauth_clients
- * WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret
- *
- * # Client ID + client secret + redirect URI
- * SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name,
- * oauth_clients.auto_approve FROM oauth_clients LEFT JOIN oauth_client_endpoints
- * ON oauth_client_endpoints.client_id = oauth_clients.id
- * WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret AND
- * oauth_client_endpoints.redirect_uri = :redirectUri
- *
- *
- * Response:
- *
- *
- * Array
- * (
- * [client_id] => (string) The client ID
- * [client secret] => (string) The client secret
- * [redirect_uri] => (string) The redirect URI used in this request
- * [name] => (string) The name of the client
- * [auto_approve] => (bool) Whether the client should auto approve
- * )
- *
- *
- * @param string $clientId The client's ID
- * @param string $clientSecret The client's secret (default = "null")
- * @param string $redirectUri The client's redirect URI (default = "null")
- * @param string $grantType The grant type used in the request (default = "null")
- * @return bool|array Returns false if the validation fails, array on success
- */
- public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType = null)
- {
- // NOTE: this implementation does not implement any grant type checks!
-
- if (!$clientSecret AND !$redirectUri)
- return FALSE;
-
- if ($redirectUri AND $clientId === $this->get_internal_client_id())
- {
- // The internal client only supports local redirects, so we strip the
- // domain information from the URI. This also prevents accidental redirect
- // outside of the current domain.
- $redirectUri = parse_url($redirectUri, PHP_URL_PATH);
-
- // We attempt to strip out the base URL, so that deployments work properly
- // when installed to a sub-directory.
- $baseUrl = preg_quote(URL::base(NULL, true), '~');
- $redirectUri = preg_replace("~^{$baseUrl}~", '/', $redirectUri);
- }
-
- if ($clientSecret AND $redirectUri)
- {
- $query = $this->query_secret_and_redirect_uri($clientId, $clientSecret, $redirectUri);
- }
- else if ($clientSecret)
- {
- $query = $this->query_secret($clientId, $clientSecret);
- }
- else if ($redirectUri)
- {
- $query = $this->query_redirect_uri($clientId, $redirectUri);
- }
-
- $query
- ->param(':clientId', $clientId)
- ->param(':clientSecret', $clientSecret)
- ->param(':redirectUri', $redirectUri);
-
- return $this->select_one_result($query);
- }
-
- private function get_internal_client_id()
- {
- return Kohana::$config->load('ushahidiui.oauth.client');
- }
-
- private function query_secret_and_redirect_uri()
- {
- return DB::query(Database::SELECT, '
- SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name, oauth_clients.auto_approve
- FROM oauth_clients
- LEFT JOIN oauth_client_endpoints
- ON oauth_client_endpoints.client_id = oauth_clients.id
- WHERE oauth_clients.id = :clientId
- AND oauth_clients.secret = :clientSecret
- AND oauth_client_endpoints.redirect_uri = :redirectUri');
- }
-
- private function query_secret()
- {
- return DB::query(Database::SELECT, '
- SELECT oauth_clients.id, oauth_clients.secret, "" AS redirect_uri, oauth_clients.name, oauth_clients.auto_approve
- FROM oauth_clients
- WHERE oauth_clients.id = :clientId
- AND oauth_clients.secret = :clientSecret');
- }
-
- private function query_redirect_uri()
- {
- return DB::query(Database::SELECT, '
- SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name, oauth_clients.auto_approve
- FROM oauth_clients
- LEFT JOIN oauth_client_endpoints
- ON oauth_client_endpoints.client_id = oauth_clients.id
- WHERE oauth_clients.id = :clientId
- AND oauth_client_endpoints.redirect_uri = :redirectUri');
- }
-}
diff --git a/application/classes/OAuth2/Storage/Scope.php b/application/classes/OAuth2/Storage/Scope.php
deleted file mode 100644
index 2157f3bd8d..0000000000
--- a/application/classes/OAuth2/Storage/Scope.php
+++ /dev/null
@@ -1,54 +0,0 @@
-
- * @package Ushahidi\OAuth2
- * @copyright 2014 Ushahidi
- * @license http://mit-license.org/
- * @link http://github.com/php-loep/oauth2-server
- */
-
-use League\OAuth2\Server\Storage\ScopeInterface;
-
-class OAuth2_Storage_Scope extends OAuth2_Storage implements ScopeInterface
-{
- /**
- * Return information about a scope
- *
- * Example SQL query:
- *
- *
- * SELECT * FROM oauth_scopes WHERE scope = :scope
- *
- *
- * Response:
- *
- *
- * Array
- * (
- * [id] => (int) The scope's ID
- * [scope] => (string) The scope itself
- * [name] => (string) The scope's name
- * [description] => (string) The scope's description
- * )
- *
- *
- * @param string $scope The scope
- * @param string $clientId The client ID (default = "null")
- * @param string $grantType The grant type used in the request (default = "null")
- * @return bool|array If the scope doesn't exist return false
- */
- public function getScope($scope, $clientId = null, $grantType = null)
- {
- // NOTE: this implementation does not implement any grant type checks!
-
- $where = array(
- 'scope' => $scope,
- );
- $query = $this->select('oauth_scopes', $where);
- return $this->select_one_result($query);
- }
-}
diff --git a/application/classes/OAuth2/Storage/Session.php b/application/classes/OAuth2/Storage/Session.php
deleted file mode 100644
index 158ed7f06a..0000000000
--- a/application/classes/OAuth2/Storage/Session.php
+++ /dev/null
@@ -1,472 +0,0 @@
-
- * @package Ushahidi\OAuth2
- * @copyright 2014 Ushahidi
- * @license http://mit-license.org/
- * @link http://github.com/php-loep/oauth2-server
- */
-
-use League\OAuth2\Server\Storage\SessionInterface;
-
-class OAuth2_Storage_Session extends OAuth2_Storage implements SessionInterface
-{
- /**
- * Create a new session
- *
- * Example SQL query:
- *
- *
- * INSERT INTO oauth_sessions (client_id, owner_type, owner_id)
- * VALUE (:clientId, :ownerType, :ownerId)
- *
- *
- * @param string $clientId The client ID
- * @param string $ownerType The type of the session owner (e.g. "user")
- * @param string $ownerId The ID of the session owner (e.g. "123")
- * @return int The session ID
- */
- public function createSession($clientId, $ownerType, $ownerId)
- {
- $data = array(
- 'client_id' => $clientId,
- 'owner_type' => $ownerType,
- 'owner_id' => $ownerId,
- );
- return $this->insert('oauth_sessions', $data);
- }
-
- /**
- * Delete a session
- *
- * Example SQL query:
- *
- *
- * DELETE FROM oauth_sessions WHERE client_id = :clientId AND owner_type = :type AND owner_id = :typeId
- *
- *
- * @param string $clientId The client ID
- * @param string $ownerType The type of the session owner (e.g. "user")
- * @param string $ownerId The ID of the session owner (e.g. "123")
- * @return void
- */
- public function deleteSession($clientId, $ownerType, $ownerId)
- {
- $data = array(
- 'client_id' => $clientId,
- 'owner_type' => $ownerType,
- 'owner_id' => $ownerId,
- );
- $this->delete('oauth_sessions', $data);
- }
-
- /**
- * Associate a redirect URI with a session
- *
- * Example SQL query:
- *
- *
- * INSERT INTO oauth_session_redirects (session_id, redirect_uri) VALUE (:sessionId, :redirectUri)
- *
- *
- * @param int $sessionId The session ID
- * @param string $redirectUri The redirect URI
- * @return void
- */
- public function associateRedirectUri($sessionId, $redirectUri)
- {
- $data = array(
- 'session_id' => $sessionId,
- 'redirect_uri' => $redirectUri,
- );
- $this->insert('oauth_session_redirects', $data);
- }
-
- /**
- * Associate an access token with a session
- *
- * Example SQL query:
- *
- *
- * INSERT INTO oauth_session_access_tokens (session_id, access_token, access_token_expires)
- * VALUE (:sessionId, :accessToken, :accessTokenExpire)
- *
- *
- * @param int $sessionId The session ID
- * @param string $accessToken The access token
- * @param int $expireTime Unix timestamp of the access token expiry time
- * @return int The access token ID
- */
- public function associateAccessToken($sessionId, $accessToken, $expireTime)
- {
- $data = array(
- 'session_id' => $sessionId,
- 'access_token' => $accessToken,
- 'access_token_expires' => $expireTime,
- );
- return $this->insert('oauth_session_access_tokens', $data);
- }
-
- /**
- * Associate a refresh token with a session
- *
- * Example SQL query:
- *
- *
- * INSERT INTO oauth_session_refresh_tokens (session_access_token_id, refresh_token, refresh_token_expires,
- * client_id) VALUE (:accessTokenId, :refreshToken, :expireTime, :clientId)
- *
- *
- * @param int $accessTokenId The access token ID
- * @param string $refreshToken The refresh token
- * @param int $expireTime Unix timestamp of the refresh token expiry time
- * @param string $clientId The client ID
- * @return void
- */
- public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId)
- {
- $data = array(
- 'session_access_token_id' => $accessTokenId,
- 'refresh_token' => $refreshToken,
- 'refresh_token_expires' => $expireTime,
- 'client_id' => $clientId,
- );
- $this->insert('oauth_session_refresh_tokens', $data);
- }
-
- /**
- * Assocate an authorization code with a session
- *
- * Example SQL query:
- *
- *
- * INSERT INTO oauth_session_authcodes (session_id, auth_code, auth_code_expires)
- * VALUE (:sessionId, :authCode, :authCodeExpires)
- *
- *
- * @param int $sessionId The session ID
- * @param string $authCode The authorization code
- * @param int $expireTime Unix timestamp of the access token expiry time
- * @return int The auth code ID
- */
- public function associateAuthCode($sessionId, $authCode, $expireTime)
- {
- $data = array(
- 'session_id' => $sessionId,
- 'auth_code' => $authCode,
- 'auth_code_expires' => $expireTime,
- );
- return $this->insert('oauth_session_authcodes', $data);
- }
-
- /**
- * Remove an associated authorization token from a session
- *
- * Example SQL query:
- *
- *
- * DELETE FROM oauth_session_authcodes WHERE session_id = :sessionId
- *
- *
- * @param int $sessionId The session ID
- * @return void
- */
- public function removeAuthCode($sessionId)
- {
- $where = array(
- 'session_id' => $sessionId,
- );
- return $this->delete('oauth_session_authcodes', $where);
- }
-
- /**
- * Validate an authorization code
- *
- * Example SQL query:
- *
- *
- * SELECT oauth_sessions.id AS session_id, oauth_session_authcodes.id AS authcode_id FROM oauth_sessions
- * JOIN oauth_session_authcodes ON oauth_session_authcodes.`session_id` = oauth_sessions.id
- * JOIN oauth_session_redirects ON oauth_session_redirects.`session_id` = oauth_sessions.id WHERE
- * oauth_sessions.client_id = :clientId AND oauth_session_authcodes.`auth_code` = :authCode
- * AND `oauth_session_authcodes`.`auth_code_expires` >= :time AND
- * `oauth_session_redirects`.`redirect_uri` = :redirectUri
- *
- *
- * Expected response:
- *
- *
- * array(
- * 'session_id' => (int)
- * 'authcode_id' => (int)
- * )
- *
- *
- * @param string $clientId The client ID
- * @param string $redirectUri The redirect URI
- * @param string $authCode The authorization code
- * @return array|bool False if invalid or array as above
- */
- public function validateAuthCode($clientId, $redirectUri, $authCode)
- {
- $query = DB::query(Database::SELECT, '
- SELECT oauth_sessions.id AS session_id, oauth_session_authcodes.id AS authcode_id FROM oauth_sessions
- JOIN oauth_session_authcodes ON oauth_session_authcodes.session_id = oauth_sessions.id
- JOIN oauth_session_redirects ON oauth_session_redirects.session_id = oauth_sessions.id
- WHERE oauth_sessions.client_id = :clientId
- AND oauth_session_authcodes.auth_code = :authCode
- AND oauth_session_authcodes.auth_code_expires >= :time
- AND oauth_session_redirects.redirect_uri = :redirectUri')
- ->param(':clientId', $clientId)
- ->param(':redirectUri', $redirectUri)
- ->param(':authCode', $authCode)
- ->param(':time', time());
- return $this->select_one_result($query);
- }
-
- /**
- * Validate an access token
- *
- * Example SQL query:
- *
- *
- * SELECT session_id, oauth_sessions.`client_id`, oauth_sessions.`owner_id`, oauth_sessions.`owner_type`
- * FROM `oauth_session_access_tokens` JOIN oauth_sessions ON oauth_sessions.`id` = session_id WHERE
- * access_token = :accessToken AND access_token_expires >= UNIX_TIMESTAMP(NOW())
- *
- *
- * Expected response:
- *
- *
- * array(
- * 'session_id' => (int),
- * 'client_id' => (string),
- * 'owner_id' => (string),
- * 'owner_type' => (string)
- * )
- *
- *
- * @param string $accessToken The access token
- * @return array|bool False if invalid or an array as above
- */
- public function validateAccessToken($accessToken)
- {
- $query = DB::query(Database::SELECT, '
- SELECT oauth_session_access_tokens.session_id, oauth_sessions.client_id, oauth_sessions.owner_id, oauth_sessions.owner_type
- FROM oauth_session_access_tokens
- JOIN oauth_sessions ON oauth_sessions.id = session_id
- WHERE access_token = :accessToken
- AND access_token_expires >= :time')
- ->param(':accessToken', $accessToken)
- ->param(':time', time());
- return $this->select_one_result($query);
- }
-
- /**
- * Removes a refresh token
- *
- * Example SQL query:
- *
- *
- * DELETE FROM `oauth_session_refresh_tokens` WHERE refresh_token = :refreshToken
- *
- *
- * @param string $refreshToken The refresh token to be removed
- * @return void
- */
- public function removeRefreshToken($refreshToken)
- {
- $where = array(
- 'refresh_token' => $refreshToken,
- );
- $this->delete('oauth_session_refresh_tokens', $where);
- }
-
- /**
- * Validate a refresh token
- *
- * Example SQL query:
- *
- *
- * SELECT session_access_token_id FROM `oauth_session_refresh_tokens` WHERE refresh_token = :refreshToken
- * AND refresh_token_expires >= UNIX_TIMESTAMP(NOW()) AND client_id = :clientId
- *
- *
- * @param string $refreshToken The refresh token
- * @param string $clientId The client ID
- * @return int|bool The ID of the access token the refresh token is linked to (or false if invalid)
- */
- public function validateRefreshToken($refreshToken, $clientId)
- {
- $query = DB::query(Database::SELECT, '
- SELECT session_access_token_id
- FROM oauth_session_refresh_tokens
- WHERE refresh_token = :refreshToken
- AND client_id = :clientId
- AND refresh_token_expires >= :time')
- ->param(':refreshToken', $refreshToken)
- ->param(':clientId', $clientId)
- ->param(':time', time());
- return $this->select_one_column($query, 'session_access_token_id');
- }
-
- /**
- * Get an access token by ID
- *
- * Example SQL query:
- *
- *
- * SELECT * FROM `oauth_session_access_tokens` WHERE `id` = :accessTokenId
- *
- *
- * Expected response:
- *
- *
- * array(
- * 'id' => (int),
- * 'session_id' => (int),
- * 'access_token' => (string),
- * 'access_token_expires' => (int)
- * )
- *
- *
- * @param int $accessTokenId The access token ID
- * @return array
- */
- public function getAccessToken($accessTokenId)
- {
- $where = array(
- 'id' => $accessTokenId,
- );
- $query = $this->select('oauth_session_access_tokens', $where);
- return $this->select_one_result($query) ?: array();
- }
-
- /**
- * Associate scopes with an auth code (bound to the session)
- *
- * Example SQL query:
- *
- *
- * INSERT INTO `oauth_session_authcode_scopes` (`oauth_session_authcode_id`, `scope_id`) VALUES
- * (:authCodeId, :scopeId)
- *
- *
- * @param int $authCodeId The auth code ID
- * @param int $scopeId The scope ID
- * @return void
- */
- public function associateAuthCodeScope($authCodeId, $scopeId)
- {
- $data = array(
- 'oauth_session_authcode_id' => $authCodeId,
- 'scope_id' => $scopeId,
- );
- $this->insert('oauth_session_authcode_scopes', $data);
- }
-
- /**
- * Get the scopes associated with an auth code
- *
- * Example SQL query:
- *
- *
- * SELECT scope_id FROM `oauth_session_authcode_scopes` WHERE oauth_session_authcode_id = :authCodeId
- *
- *
- * Expected response:
- *
- *
- * array(
- * array(
- * 'scope_id' => (int)
- * ),
- * array(
- * 'scope_id' => (int)
- * ),
- * ...
- * )
- *
- *
- * @param int $oauthSessionAuthCodeId The session ID
- * @return array
- */
- public function getAuthCodeScopes($oauthSessionAuthCodeId)
- {
- $where = array(
- 'oauth_session_authcode_id' => $oauthSessionAuthCodeId,
- );
- $query = $this->select('oauth_session_authcode_scopes', $where)->select('scope_id');
- return $this->select_results($query) ?: array();
- }
-
- /**
- * Associate a scope with an access token
- *
- * Example SQL query:
- *
- *
- * INSERT INTO `oauth_session_token_scopes` (`session_access_token_id`, `scope_id`) VALUE (:accessTokenId, :scopeId)
- *
- *
- * @param int $accessTokenId The ID of the access token
- * @param int $scopeId The ID of the scope
- * @return void
- */
- public function associateScope($accessTokenId, $scopeId)
- {
- $data = array(
- 'session_access_token_id' => $accessTokenId,
- 'scope_id' => $scopeId,
- );
- $this->insert('oauth_session_token_scopes', $data);
- }
-
- /**
- * Get all associated access tokens for an access token
- *
- * Example SQL query:
- *
- *
- * SELECT oauth_scopes.* FROM oauth_session_token_scopes JOIN oauth_session_access_tokens
- * ON oauth_session_access_tokens.`id` = `oauth_session_token_scopes`.`session_access_token_id`
- * JOIN oauth_scopes ON oauth_scopes.id = `oauth_session_token_scopes`.`scope_id`
- * WHERE access_token = :accessToken
- *
- *
- * Expected response:
- *
- *
- * array (
- * array(
- * 'id' => (int),
- * 'scope' => (string),
- * 'name' => (string),
- * 'description' => (string)
- * ),
- * ...
- * ...
- * )
- *
- *
- * @param string $accessToken The access token
- * @return array
- */
- public function getScopes($accessToken)
- {
- $query = DB::query(Database::SELECT, '
- SELECT oauth_scopes.*
- FROM oauth_session_token_scopes
- JOIN oauth_session_access_tokens
- ON oauth_session_access_tokens.id = oauth_session_token_scopes.session_access_token_id
- JOIN oauth_scopes
- ON oauth_scopes.id = oauth_session_token_scopes.scope_id
- WHERE access_token = :accessToken')
- ->param(':accessToken', $accessToken);
- return $this->select_results($query) ?: array();
- }
-}
diff --git a/application/classes/Ushahidi/Console/Oauth/Client.php b/application/classes/Ushahidi/Console/Oauth/Client.php
deleted file mode 100644
index 9279ee9225..0000000000
--- a/application/classes/Ushahidi/Console/Oauth/Client.php
+++ /dev/null
@@ -1,152 +0,0 @@
-
- * @package Ushahidi\Console
- * @copyright 2014 Ushahidi
- * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
- */
-
-use Ushahidi\Console\Command;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Output\OutputInterface;
-
-class Ushahidi_Console_OAuth_Client extends Command {
-
- // todo: put me in a repo!
- public static function db_list($client = null)
- {
- $query = DB::select()
- ->from('oauth_clients');
-
- if ($client)
- {
- $query->where('id', '=', $client);
- }
-
- return $query->execute()->as_array();
- }
-
- // todo: put me in a repo!
- public static function db_create(array $data)
- {
- $query = DB::insert('oauth_clients')
- ->columns(array_keys($data))
- ->values(array_values($data))
- ;
-
- list($id, $count) = $query->execute();
-
- return $id;
- }
-
- // todo: put me in a repo!
- public static function db_delete($client)
- {
- $query = DB::delete('oauth_clients')
- ->where('id', '=', $client);
-
- return $query->execute();
- }
-
- protected function configure()
- {
- $this
- ->setName('oauth:client')
- ->setDescription('List, create, and delete OAuth clients')
- ->addArgument('action', InputArgument::OPTIONAL, 'list, create, or delete', 'list')
- ->addOption('client', ['c'], InputOption::VALUE_OPTIONAL, 'client id')
- ->addOption('name', [], InputOption::VALUE_OPTIONAL, 'client name')
- ->addOption('secret', ['s'], InputOption::VALUE_OPTIONAL, 'secret key')
- ;
- }
-
- protected function executeList(InputInterface $input, OutputInterface $output)
- {
- $client = $input->getOption('client');
- return static::db_list($client);
- }
-
- protected function executeCreate(InputInterface $input, OutputInterface $output)
- {
- $client = $input->getOption('client');
- $name = $input->getOption('name');
- $secret = $input->getOption('secret');
-
- if (!$client)
- {
- // We can't use the generic `get_client()` for **creation**,
- // because we need to verify that the user does **not** exist.
- $clients = Arr::pluck(self::db_list(), 'id');
- $ask = function($client) use ($clients)
- {
- if (in_array($client, $clients))
- throw new RuntimeException('Client "' . $client . '" already exists, try another name');
-
- return $client;
- };
-
- $client = $this->getHelperSet()->get('dialog')
- ->askAndValidate($output, 'Enter id of new client: ', $ask, FALSE)
- ;
- }
-
- if (!$name)
- $name = $client;
-
- if (!$secret)
- $secret = Text::random('distinct', 24);
-
- static::db_create([
- 'id' => $client,
- 'secret' => $secret,
- 'name' => $name,
- ]);
-
- $input->setOption('client', $client);
-
- return $this->executeList($input, $output);
- }
-
- protected function getClient(InputInterface $input, OutputInterface $output = NULL)
- {
- $client = $input->getOption('client');
-
- if (!$client AND $output)
- {
- // If no client was given, and `$output` is passed, we can ask for
- // the user interactively and validate it against the known clients.
- $clients = Arr::pluck(self::db_list(), 'id');
- $ask = function($client) use ($clients)
- {
- if (!in_array($client, $clients))
- throw new RuntimeException('Unknown client "' . $client . '", valid options are: ' . implode(', ', $clients));
-
- return $client;
- };
-
- $client = $this->getHelperSet()->get('dialog')
- ->askAndValidate($output, 'For which client? ', $ask, FALSE, NULL, $clients)
- ;
- }
-
- return $client;
- }
-
- protected function executeDelete(InputInterface $input, OutputInterface $output)
- {
- $client = $this->getClient($input, $output);
-
- if (static::db_delete($client))
- return "Deleted {$client}";
-
- // TODO: This should result in an error return (code 1) but would
- // require writing directly to output, rather than passing control back
- // to `Command::execute`.
- return "Client {$client} was not found";
- }
-}
diff --git a/application/classes/Ushahidi/Core.php b/application/classes/Ushahidi/Core.php
index 53f4980a9b..caf295e344 100644
--- a/application/classes/Ushahidi/Core.php
+++ b/application/classes/Ushahidi/Core.php
@@ -109,6 +109,7 @@ public static function init()
'db' => $di->lazyGet('kohana.db.multisite')
];
+ // @todo move into lumen service provider
$di->set('session.user', function() use ($di) {
// Using the OAuth resource server, get the userid (owner id) for this request
// $server = $di->get('oauth.server.resource');
@@ -122,525 +123,7 @@ public static function init()
return $user;
});
- // Console commands (oauth is disabled, pending T305)
- $di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi_Console_Oauth_Client');
- $di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi_Console_Dataprovider');
- $di->setter['Ushahidi_Console_Dataprovider']['setRepo'] = $di->lazyGet('repository.dataprovider');
-
- // Notification Collection command
- $di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi_Console_Notification');
- $di->setter['Ushahidi_Console_Notification']['setDatabase'] = $di->lazyGet('kohana.db');
- $di->setter['Ushahidi_Console_Notification']['setPostRepo'] = $di->lazyGet('repository.post');
- $di->setter['Ushahidi_Console_Notification']['setMessageRepo'] = $di->lazyGet('repository.message');
- $di->setter['Ushahidi_Console_Notification']['setContactRepo'] = $di->lazyGet('repository.contact');
- $di->setter['Ushahidi_Console_Notification']['setNotificationQueueRepo'] = $di->lazyGet('repository.notification.queue');
-
- // Notification SavedSearch command
- $di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi_Console_SavedSearch');
- $di->setter['Ushahidi_Console_SavedSearch']['setSetRepo'] = $di->lazyGet('repository.savedsearch');
- $di->setter['Ushahidi_Console_SavedSearch']['setPostRepo'] = $di->lazyGet('repository.post');
- $di->setter['Ushahidi_Console_SavedSearch']['setMessageRepo'] = $di->lazyGet('repository.message');
- $di->setter['Ushahidi_Console_SavedSearch']['setContactRepo'] = $di->lazyGet('repository.contact');
- $di->setter['Ushahidi_Console_SavedSearch']['setDataFactory'] = $di->lazyGet('factory.data');
-
- // Webhook command
- $di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi_Console_Webhook');
- $di->setter['Ushahidi_Console_Webhook']['setDatabase'] = $di->lazyGet('kohana.db');
- $di->setter['Ushahidi_Console_Webhook']['setPostRepo'] = $di->lazyGet('repository.post');
- $di->setter['Ushahidi_Console_Webhook']['setWebhookRepo'] = $di->lazyGet('repository.webhook');
- $di->setter['Ushahidi_Console_Webhook']['setWebhookJobRepo'] = $di->lazyGet('repository.webhook.job');
-
- // Validator mapping
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['config'] = [
- 'update' => $di->lazyNew('Ushahidi_Validator_Config_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['forms'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Form_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Form_Update'),
- 'delete' => $di->lazyNew('Ushahidi_Validator_Form_Delete'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['form_attributes'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Form_Attribute_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Form_Attribute_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['form_roles'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Form_Role_Create'),
- 'update_collection' => $di->lazyNew('Ushahidi_Validator_Form_Role_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['form_stages'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Form_Stage_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Form_Stage_Update'),
- 'delete' => $di->lazyNew('Ushahidi_Validator_Form_Stage_Delete'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['layers'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Layer_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Layer_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['media'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Media_Create'),
- 'delete' => $di->lazyNew('Ushahidi_Validator_Media_Delete'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['posts'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Post_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Post_Create'),
- 'import' => $di->lazyNew('Ushahidi_Validator_Post_Import'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['tags'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Tag_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Tag_Update'),
- 'delete' => $di->lazyNew('Ushahidi_Validator_Tag_Delete'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['users'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_User_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_User_Update'),
- 'register' => $di->lazyNew('Ushahidi_Validator_User_Register')
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['messages'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Message_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Message_Update'),
- 'receive' => $di->lazyNew('Ushahidi_Validator_Message_Receive'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['savedsearches'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_SavedSearch_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_SavedSearch_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['sets'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Set_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Set_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['notifications'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Notification_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Notification_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['webhooks'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Webhook_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Webhook_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['contacts'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Contact_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Contact_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['sets_posts'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Set_Post_Create'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['csv'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_CSV_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_CSV_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['csv'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_CSV_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_CSV_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['roles'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Role_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Role_Update'),
- ];
- $di->params['Ushahidi\Factory\ValidatorFactory']['map']['permissions'] = [
- 'create' => $di->lazyNew('Ushahidi_Validator_Permission_Create'),
- 'update' => $di->lazyNew('Ushahidi_Validator_Permission_Update'),
- ];
-
- // Validation Trait
- $di->setter['Ushahidi\Core\Tool\ValidationEngineTrait']['setValidation'] = $di->newFactory('Ushahidi_ValidationEngine');
- $di->params['Ushahidi_ValidationEngine']['array'] = [];
-
- // Formatter mapping
- $di->params['Ushahidi\Factory\FormatterFactory']['map'] = [
- 'config' => $di->lazyNew('Ushahidi_Formatter_Config'),
- 'dataproviders' => $di->lazyNew('Ushahidi_Formatter_Dataprovider'),
- 'forms' => $di->lazyNew('Ushahidi_Formatter_Form'),
- 'form_attributes' => $di->lazyNew('Ushahidi_Formatter_Form_Attribute'),
- 'form_roles' => $di->lazyNew('Ushahidi_Formatter_Form_Role'),
- 'form_stages' => $di->lazyNew('Ushahidi_Formatter_Form_Stage'),
- 'layers' => $di->lazyNew('Ushahidi_Formatter_Layer'),
- 'media' => $di->lazyNew('Ushahidi_Formatter_Media'),
- 'messages' => $di->lazyNew('Ushahidi_Formatter_Message'),
- 'posts' => $di->lazyNew('Ushahidi_Formatter_Post'),
- 'tags' => $di->lazyNew('Ushahidi_Formatter_Tag'),
- 'savedsearches' => $di->lazyNew('Ushahidi_Formatter_Set'),
- 'sets' => $di->lazyNew('Ushahidi_Formatter_Set'),
- 'sets_posts' => $di->lazyNew('Ushahidi_Formatter_Post'),
- 'savedsearches_posts' => $di->lazyNew('Ushahidi_Formatter_Post'),
- 'users' => $di->lazyNew('Ushahidi_Formatter_User'),
- 'notifications' => $di->lazyNew('Ushahidi_Formatter_Notification'),
- 'webhooks' => $di->lazyNew('Ushahidi_Formatter_Webhook'),
- 'contacts' => $di->lazyNew('Ushahidi_Formatter_Contact'),
- 'csv' => $di->lazyNew('Ushahidi_Formatter_CSV'),
- 'roles' => $di->lazyNew('Ushahidi_Formatter_Role'),
- 'permissions' => $di->lazyNew('Ushahidi_Formatter_Permission'),
- // Formatter for post exports. Defaults to CSV export
- 'posts_export' => $di->lazyNew('Ushahidi_Formatter_Post_CSV'),
- ];
-
- // Formatter parameters
- foreach ([
- 'config',
- 'dataprovider',
- 'form',
- 'form_attribute',
- 'form_role',
- 'form_stage',
- 'layer',
- 'media',
- 'message',
- 'post',
- 'tag',
- 'user',
- 'savedsearch',
- 'set_post',
- 'notification',
- 'webhook',
- 'contact',
- 'role',
- 'permission',
- ] as $name)
- {
- $di->setter['Ushahidi_Formatter_' . Text::ucfirst($name, '_')]['setAuth'] =
- $di->lazyGet("authorizer.$name");
- }
-
- $di->setter['Ushahidi_Formatter_Set']['setAuth'] = $di->lazyGet("authorizer.set");
- $di->setter['Ushahidi_Formatter_CSV']['setAuth'] = $di->lazyGet("authorizer.csv");
-
- // Set Formatter factory
- $di->params['Ushahidi\Factory\FormatterFactory']['factory'] = $di->newFactory('Ushahidi_Formatter_Collection');
-
$di->set('tool.validation', $di->lazyNew('Ushahidi_ValidationEngine'));
- $di->set('tool.jsontranscode', $di->lazyNew('Ushahidi\Core\Tool\JsonTranscode'));
-
- // Formatters
- $di->set('formatter.entity.api', $di->lazyNew('Ushahidi_Formatter_API'));
- $di->set('formatter.entity.console', $di->lazyNew('Ushahidi_Formatter_Console'));
- $di->set('formatter.entity.post.value', $di->lazyNew('Ushahidi_Formatter_PostValue'));
- $di->set('formatter.entity.post.geojson', $di->lazyNew('Ushahidi_Formatter_Post_GeoJSON'));
- $di->set('formatter.entity.post.geojsoncollection', $di->lazyNew('Ushahidi_Formatter_Post_GeoJSONCollection'));
- $di->set('formatter.entity.post.stats', $di->lazyNew('Ushahidi_Formatter_Post_Stats'));
- $di->set('formatter.entity.post.csv', $di->lazyNew('Ushahidi_Formatter_Post_CSV'));
-
- $di->set('formatter.output.json', $di->lazyNew('Ushahidi_Formatter_JSON'));
- $di->set('formatter.output.jsonp', $di->lazyNew('Ushahidi_Formatter_JSONP'));
-
- // Formatter parameters
- $di->setter['Ushahidi_Formatter_JSONP']['setCallback'] = function() {
- return Request::current()->query('callback');
- };
- $di->params['Ushahidi_Formatter_Post'] = [
- 'value_formatter' => $di->lazyGet('formatter.entity.post.value')
- ];
- $di->setter['Ushahidi_Formatter_Post_GeoJSON']['setDecoder'] = $di->lazyNew('Symm\Gisconverter\Decoders\WKT');
- $di->setter['Ushahidi_Formatter_Post_GeoJSONCollection']['setDecoder'] = $di->lazyNew('Symm\Gisconverter\Decoders\WKT');
-
- // Repositories
- $di->set('repository.config', $di->lazyNew('Ushahidi_Repository_Config'));
- $di->set('repository.contact', $di->lazyNew('Ushahidi_Repository_Contact'));
- $di->set('repository.dataprovider', $di->lazyNew('Ushahidi_Repository_Dataprovider'));
- $di->set('repository.form', $di->lazyNew('Ushahidi_Repository_Form'));
- $di->set('repository.form_role', $di->lazyNew('Ushahidi_Repository_Form_Role'));
- $di->set('repository.form_stage', $di->lazyNew('Ushahidi_Repository_Form_Stage'));
- $di->set('repository.form_attribute', $di->lazyNew('Ushahidi_Repository_Form_Attribute'));
- $di->set('repository.layer', $di->lazyNew('Ushahidi_Repository_Layer'));
- $di->set('repository.media', $di->lazyNew('Ushahidi_Repository_Media'));
- $di->set('repository.message', $di->lazyNew('Ushahidi_Repository_Message'));
- $di->set('repository.post', $di->lazyNew('Ushahidi_Repository_Post'));
- $di->set('repository.tag', $di->lazyNew('Ushahidi_Repository_Tag'));
- $di->set('repository.set', $di->lazyNew('Ushahidi_Repository_Set'));
- $di->set('repository.savedsearch', $di->lazyNew(
- 'Ushahidi_Repository_Set',
- [],
- [
- 'setSavedSearch' => true
- ]
- ));
- $di->set('repository.user', $di->lazyNew('Ushahidi_Repository_User'));
- $di->set('repository.role', $di->lazyNew('Ushahidi_Repository_Role'));
- $di->set('repository.notification', $di->lazyNew('Ushahidi_Repository_Notification'));
- $di->set('repository.webhook', $di->lazyNew('Ushahidi_Repository_Webhook'));
- $di->set('repository.csv', $di->lazyNew('Ushahidi_Repository_CSV'));
- $di->set('repository.notification.queue', $di->lazyNew('Ushahidi_Repository_Notification_Queue'));
- $di->set('repository.webhook.job', $di->lazyNew('Ushahidi_Repository_Webhook_Job'));
- $di->set('repository.permission', $di->lazyNew('Ushahidi_Repository_Permission'));
- // $di->set('repository.oauth.client', $di->lazyNew('OAuth2_Storage_Client'));
- // $di->set('repository.oauth.session', $di->lazyNew('OAuth2_Storage_Session'));
- // $di->set('repository.oauth.scope', $di->lazyNew('OAuth2_Storage_Scope'));
- $di->set('repository.posts_export', $di->lazyNew('Ushahidi_Repository_Post_Export'));
-
- $di->setter['Ushahidi_Repository_User']['setHasher'] = $di->lazyGet('tool.hasher.password');
-
- // Repository parameters
-
- // Abstract repository parameters
- $di->params['Ushahidi_Repository'] = [
- 'db' => $di->lazyGet('kohana.db'),
- ];
-
- // Set up Json Transcode Repository Trait
- $di->setter['Ushahidi_JsonTranscodeRepository']['setTranscoder'] = $di->lazyGet('tool.jsontranscode');
-
- // Media repository parameters
- $di->params['Ushahidi_Repository_Media'] = [
- 'upload' => $di->lazyGet('tool.uploader'),
- ];
-
- // Form Stage repository parameters
- $di->params['Ushahidi_Repository_Form_Stage'] = [
- 'form_repo' => $di->lazyGet('repository.form')
- ];
-
- // Form Attribute repository parameters
- $di->params['Ushahidi_Repository_Form_Attribute'] = [
- 'form_stage_repo' => $di->lazyGet('repository.form_stage'),
- 'form_repo' => $di->lazyGet('repository.form')
- ];
-
- // Post repository parameters
- $di->params['Ushahidi_Repository_Post'] = [
- 'form_attribute_repo' => $di->lazyGet('repository.form_attribute'),
- 'form_stage_repo' => $di->lazyGet('repository.form_stage'),
- 'form_repo' => $di->lazyGet('repository.form'),
- 'post_value_factory' => $di->lazyGet('repository.post_value_factory'),
- 'bounding_box_factory' => $di->newFactory('Util_BoundingBox'),
- 'tag_repo' => $di->lazyGet('repository.tag')
- ];
-
- $di->set('repository.post.datetime', $di->lazyNew('Ushahidi_Repository_Post_Datetime'));
- $di->set('repository.post.decimal', $di->lazyNew('Ushahidi_Repository_Post_Decimal'));
- $di->set('repository.post.geometry', $di->lazyNew('Ushahidi_Repository_Post_Geometry'));
- $di->set('repository.post.int', $di->lazyNew('Ushahidi_Repository_Post_Int'));
- $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.markdown', $di->lazyNew('Ushahidi_Repository_Post_Markdown'));
- $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
- $di->set('repository.post_value_factory', $di->lazyNew('Ushahidi_Repository_Post_ValueFactory'));
- $di->params['Ushahidi_Repository_Post_ValueFactory'] = [
- // a map of attribute types to repositories
- 'map' => [
- 'datetime' => $di->lazyGet('repository.post.datetime'),
- 'decimal' => $di->lazyGet('repository.post.decimal'),
- 'geometry' => $di->lazyGet('repository.post.geometry'),
- 'int' => $di->lazyGet('repository.post.int'),
- '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'),
- 'markdown' => $di->lazyGet('repository.post.markdown'),
- 'title' => $di->lazyGet('repository.post.title'),
- 'media' => $di->lazyGet('repository.post.media'),
- ],
- ];
-
- $di->params['Ushahidi_Repository_Post_Point'] = [
- 'decoder' => $di->lazyNew('Symm\Gisconverter\Decoders\WKT')
- ];
-
- // Validators
- $di->set('validator.user.login', $di->lazyNew('Ushahidi_Validator_User_Login'));
- $di->set('validator.contact.create', $di->lazyNew('Ushahidi_Validator_Contact_Create'));
- $di->set('validator.contact.receive', $di->lazyNew('Ushahidi_Validator_Contact_Receive'));
-
- $di->params['Ushahidi_Validator_Contact_Update'] = [
- 'repo' => $di->lazyGet('repository.user'),
- ];
-
- // Dependencies of validators
- $di->params['Ushahidi_Validator_Post_Create'] = [
- 'repo' => $di->lazyGet('repository.post'),
- 'attribute_repo' => $di->lazyGet('repository.form_attribute'),
- 'stage_repo' => $di->lazyGet('repository.form_stage'),
- 'tag_repo' => $di->lazyGet('repository.tag'),
- 'user_repo' => $di->lazyGet('repository.user'),
- 'form_repo' => $di->lazyGet('repository.form'),
- 'role_repo' => $di->lazyGet('repository.role'),
- 'post_value_factory' => $di->lazyGet('repository.post_value_factory'),
- 'post_value_validator_factory' => $di->lazyGet('validator.post.value_factory'),
- ];
-
- $di->params['Ushahidi_Validator_Form_Update'] = [
- 'repo' => $di->lazyGet('repository.form'),
- ];
-
- $di->param['Ushahidi_Validator_Form_Attribute_Update'] = [
- 'repo' => $di->lazyGet('repository.form_attribute'),
- 'form_stage_repo' => $di->lazyGet('repository.form_stage'),
- ];
- $di->params['Ushahidi_Validator_Layer_Update'] = [
- 'media_repo' => $di->lazyGet('repository.media'),
- ];
- $di->params['Ushahidi_Validator_Message_Update'] = [
- 'repo' => $di->lazyGet('repository.message'),
- ];
- $di->params['Ushahidi_Validator_Message_Create'] = [
- 'repo' => $di->lazyGet('repository.message'),
- 'user_repo' => $di->lazyGet('repository.user')
- ];
-
- $di->params['Ushahidi_Validator_Message_Receive'] = [
- 'repo' => $di->lazyGet('repository.message'),
- ];
-
- $di->params['Ushahidi_Validator_Set_Update'] = [
- 'repo' => $di->lazyGet('repository.user'),
- 'role_repo' => $di->lazyGet('repository.role'),
- ];
- $di->params['Ushahidi_Validator_Notification_Update'] = [
- 'user_repo' => $di->lazyGet('repository.user'),
- 'collection_repo' => $di->lazyGet('repository.set'),
- 'savedsearch_repo' => $di->lazyGet('repository.savedsearch'),
- ];
- $di->params['Ushahidi_Validator_Webhook_Update'] = [
- 'user_repo' => $di->lazyGet('repository.user'),
- ];
- $di->params['Ushahidi_Validator_SavedSearch_Create'] = [
- 'repo' => $di->lazyGet('repository.user'),
- 'role_repo' => $di->lazyGet('repository.role'),
- ];
- $di->params['Ushahidi_Validator_SavedSearch_Update'] = [
- 'repo' => $di->lazyGet('repository.user'),
- 'role_repo' => $di->lazyGet('repository.role'),
- ];
-
- $di->params['Ushahidi_Validator_Set_Post_Create'] = [
- 'post_repo' => $di->lazyGet('repository.post')
- ];
-
- $di->params['Ushahidi_Validator_Tag_Update'] = [
- 'repo' => $di->lazyGet('repository.tag'),
- 'role_repo' => $di->lazyGet('repository.role'),
- ];
-
- $di->params['Ushahidi_Validator_User_Create'] = [
- 'repo' => $di->lazyGet('repository.user'),
- 'role_repo' => $di->lazyGet('repository.role'),
- ];
- $di->params['Ushahidi_Validator_User_Update'] = [
- 'repo' => $di->lazyGet('repository.user'),
- 'user' => $di->lazyGet('session.user'),
- 'role_repo' => $di->lazyGet('repository.role'),
- ];
- $di->params['Ushahidi_Validator_User_Register'] = [
- 'repo' => $di->lazyGet('repository.user')
- ];
- $di->params['Ushahidi_Validator_CSV_Create'] = [
- 'form_repo' => $di->lazyGet('repository.form'),
- ];
- $di->params['Ushahidi_Validator_CSV_Update'] = [
- 'form_repo' => $di->lazyGet('repository.form'),
- ];
- $di->params['Ushahidi_Validator_Role_Update'] = [
- 'permission_repo' => $di->lazyGet('repository.permission'),
- ];
-
- // Validator Setters
- $di->setter['Ushahidi_Validator_Form_Stage_Update'] = [
- 'setFormRepo' => $di->lazyGet('repository.form'),
- ];
- $di->setter['Ushahidi_Validator_Form_Role_Update'] = [
- 'setFormRepo' => $di->lazyGet('repository.form'),
- 'setRoleRepo' => $di->lazyGet('repository.role'),
- ];
- $di->setter['Ushahidi_Validator_Media_Create'] = [
- 'setMaxBytes' => $di->lazy(function() {
- return \Kohana::$config->load('media.max_upload_bytes');
- }),
- ];
- $di->setter['Ushahidi_Validator_CSV_Create'] = [
- // @todo load from config
- 'setMaxBytes' => '2048000',
- ];
-
-
- $di->set('validator.post.datetime', $di->lazyNew('Ushahidi_Validator_Post_Datetime'));
- $di->set('validator.post.decimal', $di->lazyNew('Ushahidi_Validator_Post_Decimal'));
- $di->set('validator.post.geometry', $di->lazyNew('Ushahidi_Validator_Post_Geometry'));
- $di->set('validator.post.int', $di->lazyNew('Ushahidi_Validator_Post_Int'));
- $di->set('validator.post.link', $di->lazyNew('Ushahidi_Validator_Post_Link'));
- $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.markdown', $di->lazyNew('Ushahidi_Validator_Post_Markdown'));
- $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')
- ];
-
-
- $di->set('validator.post.value_factory', $di->lazyNew('Ushahidi_Validator_Post_ValueFactory'));
- $di->params['Ushahidi_Validator_Post_ValueFactory'] = [
- // a map of attribute types to validators
- 'map' => [
- 'datetime' => $di->lazyGet('validator.post.datetime'),
- 'decimal' => $di->lazyGet('validator.post.decimal'),
- 'geometry' => $di->lazyGet('validator.post.geometry'),
- 'int' => $di->lazyGet('validator.post.int'),
- 'link' => $di->lazyGet('validator.post.link'),
- 'point' => $di->lazyGet('validator.post.point'),
- 'relation' => $di->lazyGet('validator.post.relation'),
- 'varchar' => $di->lazyGet('validator.post.varchar'),
- 'markdown' => $di->lazyGet('validator.post.markdown'),
- 'title' => $di->lazyGet('validator.post.title'),
- 'media' => $di->lazyGet('validator.post.media'),
- 'video' => $di->lazyGet('validator.post.video'),
- ],
- ];
-
- $di->params['Ushahidi_Validator_Post_Relation'] = [
- 'repo' => $di->lazyGet('repository.post')
- ];
-
- $di->set('transformer.mapping', $di->lazyNew('Ushahidi_Transformer_MappingTransformer'));
- $di->set('transformer.csv', $di->lazyNew('Ushahidi_Transformer_CSVPostTransformer'));
- // Post repo for mapping transformer
- $di->setter['Ushahidi_Transformer_CSVPostTransformer']['setRepo'] =
- $di->lazyGet('repository.post');
-
- $di->set('tool.mailer', $di->lazyNew('Ushahidi_Mailer'));
-
- // Event listener for the Set repo
- $di->setter['Ushahidi_Repository_Set']['setEvent'] = 'PostSetEvent';
-
- $di->setter['Ushahidi_Repository_Set']['setListener'] =
- $di->lazyNew('Ushahidi_Listener_PostSetListener');
-
- // NotificationQueue repo for Set listener
- $di->setter['Ushahidi_Listener_PostSetListener']['setRepo'] =
- $di->lazyGet('repository.notification.queue');
-
- // Event listener for the Post repo
- $di->setter['Ushahidi_Repository_Post']['setEvent'] = 'PostCreateEvent';
- $di->setter['Ushahidi_Repository_Post']['setListener'] =
- $di->lazyNew('Ushahidi_Listener_PostListener');
-
- // WebhookJob repo for Post listener
- $di->setter['Ushahidi_Listener_PostListener']['setRepo'] =
- $di->lazyGet('repository.webhook.job');
-
- // Webhook repo for Post listener
- $di->setter['Ushahidi_Listener_PostListener']['setWebhookRepo'] =
- $di->lazyGet('repository.webhook');
-
- // Add Intercom Listener to Config
- $di->setter['Ushahidi_Repository_Config']['setEvent'] = 'ConfigUpdateEvent';
- $di->setter['Ushahidi_Repository_Config']['setListener'] =
- $di->lazyNew('Ushahidi_Listener_IntercomListener');
-
- // Add Intercom Listener to Form
- $di->setter['Ushahidi_Repository_Form']['setEvent'] = 'FormUpdateEvent';
- $di->setter['Ushahidi_Repository_Form']['setListener'] =
- $di->lazyNew('Ushahidi_Listener_IntercomListener');
-
- // Add Intercom Listener to User
- $di->setter['Ushahidi_Repository_User']['setEvent'] = 'UserGetAllEvent';
- $di->setter['Ushahidi_Repository_User']['setListener'] =
- $di->lazyNew('Ushahidi_Listener_IntercomListener');
-
/**
* 1. Load the plugins
diff --git a/application/classes/Ushahidi/JsonTranscodeRepository.php b/application/classes/Ushahidi/JsonTranscodeRepository.php
deleted file mode 100644
index 823b2611c6..0000000000
--- a/application/classes/Ushahidi/JsonTranscodeRepository.php
+++ /dev/null
@@ -1,70 +0,0 @@
-
- * @package Ushahidi\Application\Controllers
- * @copyright 2013 Ushahidi
- * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
- */
-
-use Ushahidi\Core\Tool\JsonTranscode;
-
-trait Ushahidi_JsonTranscodeRepository {
-
- protected $json_transcoder;
-
- /**
- * Return an array of properties to be json encoded
- * @return Array
- */
- abstract protected function getJsonProperties();
-
- public function setTranscoder(JsonTranscode $transcoder)
- {
- $this->json_transcoder = $transcoder;
- }
-
- // Temporary override function for attribute addition
- public function executeInsertAttribute(Array $input)
- {
- // JSON Encode defined properties
- $input = $this->json_transcoder->encode(
- $input,
- $this->getJsonProperties()
- );
-
- return parent::executeInsert($input);
- }
-
- // Ushahidi_Repository
- public function executeInsert(Array $input)
- {
- // JSON Encode defined properties
- // The use of array_filter causes issues with array items set as 0
- // the items are removed. This code should ultimately be refactored.
- $input = array_filter($this->json_transcoder->encode(
- $input,
- $this->getJsonProperties()
- ));
-
- return parent::executeInsert($input);
- }
-
- // Ushahidi_Repository
- public function executeUpdate(Array $where, Array $input)
- {
- // JSON Encode defined properties
- $input = $this->json_transcoder->encode(
- $input,
- $this->getJsonProperties()
- );
-
- return parent::executeUpdate($where, $input);
- }
-
-}
diff --git a/application/classes/Ushahidi/Repository/Post/Description.php b/application/classes/Ushahidi/Repository/Post/Description.php
deleted file mode 100644
index 36d7633216..0000000000
--- a/application/classes/Ushahidi/Repository/Post/Description.php
+++ /dev/null
@@ -1,32 +0,0 @@
-
- * @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 = [], Array $exclude_stages = [], $restricted = false)
- {
- 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;
- }
-}
diff --git a/application/classes/Ushahidi/Repository/Post/Export.php b/application/classes/Ushahidi/Repository/Post/Export.php
deleted file mode 100644
index 44b57607fb..0000000000
--- a/application/classes/Ushahidi/Repository/Post/Export.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
- * @package Ushahidi\Application
- * @copyright 2016 Ushahidi
- * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
- */
-use Ushahidi\Core\Entity\Post;
-use Ushahidi\Core\Entity\PostRepository;
-
-class Ushahidi_Repository_Post_Export extends Ushahidi_Repository_Post
-{
- public function getFormAttributes($values) {
- $attributes = [];
- foreach ($values as $key => $val)
- {
- $attribute = $this->form_attribute_repo->getByKey($key);
- $attributes[$key] = $attribute->label;
- }
- return $attributes;
- }
-}
diff --git a/application/classes/Ushahidi/Repository/Post/Title.php b/application/classes/Ushahidi/Repository/Post/Title.php
deleted file mode 100644
index e34c52a2af..0000000000
--- a/application/classes/Ushahidi/Repository/Post/Title.php
+++ /dev/null
@@ -1,30 +0,0 @@
-
- * @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 = [], Array $exclude_stages = [], $restricted = false)
- {
- return [];
- }
- public function createValue($value, $form_attribute_id, $post_id)
- {
- return 0;
- }
-
- public function updateValue($id, $value)
- {
- return 0;
- }
-}
diff --git a/application/classes/Ushahidi/SoftDelete.php b/application/classes/Ushahidi/SoftDelete.php
deleted file mode 100644
index 4c2b42b1ae..0000000000
--- a/application/classes/Ushahidi/SoftDelete.php
+++ /dev/null
@@ -1,34 +0,0 @@
-
- * @package Ushahidi\Application
- * @copyright 2014 Ushahidi
- * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
- */
-
-trait Ushahidi_SoftDelete
-{
- /**
- * Set your own soft delete column name
- *
- * @return String name of the column
- */
- abstract protected function _get_soft_delete_column();
-
- public function delete()
- {
- $this->{$this->_get_soft_delete_column()} = true;
- $this->save();
- return $this;
- }
-
- public function undelete()
- {
- $this->{$this->_get_soft_delete_column()} = false;
- $this->save();
- return $this;
- }
-}
diff --git a/application/classes/Ushahidi/Validator/Media/Update.php b/application/classes/Ushahidi/Validator/Media/Update.php
deleted file mode 100644
index f16ae8a846..0000000000
--- a/application/classes/Ushahidi/Validator/Media/Update.php
+++ /dev/null
@@ -1,29 +0,0 @@
-
- * @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;
-use Ushahidi\Core\Tool\Validator;
-
-class Ushahidi_Validator_Media_Update extends Ushahidi_Validator_Media_Create
-{
- protected function getRules()
- {
- return [
- 'user_id' => [
- ['digit'],
- ],
- 'caption' => [
- // alphas, numbers, punctuation, and spaces
- ['regex', [':value', '/^[\pL\pN\pP ]++$/uD']],
- ]
- ];
- }
-}
diff --git a/application/classes/Ushahidi/Validator/Post/Video.php b/application/classes/Ushahidi/Validator/Post/Video.php
deleted file mode 100644
index 412e28ea10..0000000000
--- a/application/classes/Ushahidi/Validator/Post/Video.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
- * @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);
- }
-}
diff --git a/composer.json b/composer.json
index 5931772858..1db8bbd347 100644
--- a/composer.json
+++ b/composer.json
@@ -82,6 +82,7 @@
},
"autoload-dev": {
"psr-4": {
+ "Tests\\": "tests",
"Tests\\Unit\\": "tests/unit",
"Tests\\Integration\\Bootstrap\\": "tests/integration/bootstrap"
},
@@ -100,6 +101,11 @@
"phpcs --standard=tests/spec/ruleset.xml --tab-width=4 ./tests/spec/",
"phpcs --standard=migrations/ruleset.xml --tab-width=4 ./migrations/ ./database"
],
+ "fixlint" : [
+ "phpcbf --ignore=vendor/*,application/*,modules/*,plugins/*,httpdocs/*,tests/spec/*,migrations/*,bin/*,database/* --standard=src/ruleset.xml --tab-width=4 ./",
+ "phpcbf --standard=tests/spec/ruleset.xml --tab-width=4 ./tests/spec/",
+ "phpcbf --standard=migrations/ruleset.xml --tab-width=4 ./migrations/ ./database"
+ ],
"pre-coverage" : [
"rm -rf coverage/"
],
diff --git a/migrations/20170419000000_drop_old_oauth_tables.php b/migrations/20170419000000_drop_old_oauth_tables.php
index 85ec3b622a..4f3b9148bf 100644
--- a/migrations/20170419000000_drop_old_oauth_tables.php
+++ b/migrations/20170419000000_drop_old_oauth_tables.php
@@ -7,7 +7,8 @@ class DropOldOauthTables extends AbstractMigration
/**
* Drop Oauth tables
*/
- public function up() {
+ public function up()
+ {
$this->dropTable('oauth_session_refresh_tokens');
$this->dropTable('oauth_session_token_scopes');
$this->dropTable('oauth_session_authcode_scopes');
diff --git a/migrations/20170419000003_create_oauth_refresh_tokens_table.php b/migrations/20170419000003_create_oauth_refresh_tokens_table.php
index d010c5215f..733af9cd67 100644
--- a/migrations/20170419000003_create_oauth_refresh_tokens_table.php
+++ b/migrations/20170419000003_create_oauth_refresh_tokens_table.php
@@ -19,6 +19,5 @@ public function change()
->addColumn('expires_at', 'datetime', ['null' => true])
->addIndex(['access_token_id'])
->create();
-
}
}
diff --git a/migrations/20170419204826_restore_default_oauth_client.php b/migrations/20170419204826_restore_default_oauth_client.php
index 67094c3574..8fcc7b47c8 100644
--- a/migrations/20170419204826_restore_default_oauth_client.php
+++ b/migrations/20170419204826_restore_default_oauth_client.php
@@ -13,8 +13,9 @@ public function up()
// by endpoint, not the secret.
$secret = sha1('ushahidiui');
$this->execute(
- "INSERT IGNORE INTO oauth_clients (id, secret, name, password_client, personal_access_client, revoked, created_at, updated_at, redirect)
- VALUES (
+ "INSERT IGNORE INTO oauth_clients (
+ id, secret, name, password_client, personal_access_client, revoked, created_at, updated_at, redirect
+ ) VALUES (
'ushahidiui',
'$secret',
'Ushahidi Platform Web Client',
diff --git a/application/classes/Ushahidi/Formatter/API.php b/src/App/Formatter/API.php
similarity index 62%
rename from application/classes/Ushahidi/Formatter/API.php
rename to src/App/Formatter/API.php
index df8786af91..45fd28656b 100644
--- a/application/classes/Ushahidi/Formatter/API.php
+++ b/src/App/Formatter/API.php
@@ -1,4 +1,4 @@
-asArray();
@@ -31,38 +35,31 @@ public function __invoke($entity)
'url' => url(RESTController::url($entity->getResource(), $entity->id)),
];
- if (isset($fields['parent_id']))
- {
- $data['parent'] = $this->get_relation($entity->getResource(), $entity->parent_id);
+ if (isset($fields['parent_id'])) {
+ $data['parent'] = $this->getRelation($entity->getResource(), $entity->parent_id);
unset($fields['parent_id']);
}
- if (isset($fields['user_id']))
- {
- $data['user'] = $this->get_relation('users', $entity->user_id);
+ if (isset($fields['user_id'])) {
+ $data['user'] = $this->getRelation('users', $entity->user_id);
unset($fields['user_id']);
}
- foreach ($fields as $field => $value)
- {
- $name = $this->get_field_name($field);
- if (is_string($value))
- {
+ foreach ($fields as $field => $value) {
+ $name = $this->getFieldName($field);
+ if (is_string($value)) {
$value = trim($value);
}
- $method = 'format_' . $field;
- if (method_exists($this, $method))
- {
+ $method = 'format' . Str::studly($field);
+ if (method_exists($this, $method)) {
$data[$name] = $this->$method($value);
- }
- else
- {
+ } else {
$data[$name] = $value;
}
}
- $data = $this->add_metadata($data, $entity);
+ $data = $this->addMetadata($data, $entity);
return $data;
}
@@ -77,26 +74,26 @@ public function __invoke($entity)
* @param Entity $entity resource
* @return Array
*/
- protected function add_metadata(Array $data, Entity $entity)
+ protected function addMetadata(array $data, Entity $entity)
{
// By default, noop
return $data;
}
- protected function get_field_name($field)
+ protected function getFieldName($field)
{
// can be overloaded to remap specific fields to different public names
return $field;
}
- protected function format_created($value)
+ protected function formatCreated($value)
{
- return date(DateTime::W3C, $value);
+ return date(\DateTime::W3C, $value);
}
- protected function format_updated($value)
+ protected function formatUpdated($value)
{
- return $value ? $this->format_created($value) : NULL;
+ return $value ? $this->formatCreated($value) : null;
}
/**
@@ -105,9 +102,9 @@ protected function format_updated($value)
* @param int $id resource id
* @return array
*/
- protected function get_relation($resource, $id)
+ protected function getRelation($resource, $id)
{
- return !$id ? NULL : [
+ return !$id ? null : [
'id' => $id,
'url' => url(RESTController::url($resource, $id)),
];
diff --git a/application/classes/Ushahidi/Formatter/CSV.php b/src/App/Formatter/CSV.php
similarity index 74%
rename from application/classes/Ushahidi/Formatter/CSV.php
rename to src/App/Formatter/CSV.php
index d57203f3e5..9ae9301d42 100644
--- a/application/classes/Ushahidi/Formatter/CSV.php
+++ b/src/App/Formatter/CSV.php
@@ -1,4 +1,4 @@
-config_group == 'map') {
return (bool) $val;
@@ -35,7 +37,7 @@ protected function format_clustering($val)
return $val;
}
- protected function format_cluster_radius($val)
+ protected function formatClusterRadius($val)
{
if ($this->config_group == 'map') {
return (integer) $val;
diff --git a/application/classes/Ushahidi/Formatter/Console.php b/src/App/Formatter/Console.php
similarity index 63%
rename from application/classes/Ushahidi/Formatter/Console.php
rename to src/App/Formatter/Console.php
index ae79755ab1..49ad8decd7 100644
--- a/application/classes/Ushahidi/Formatter/Console.php
+++ b/src/App/Formatter/Console.php
@@ -1,4 +1,4 @@
-asArray();
@@ -29,26 +33,21 @@ public function __invoke($entity)
'id' => $entity->id,
];
- foreach ($fields as $field => $value)
- {
- $name = $this->get_field_name($field);
- if (is_string($value))
- {
+ foreach ($fields as $field => $value) {
+ $name = $this->getFieldName($field);
+ if (is_string($value)) {
$value = trim($value);
}
- $method = 'format_' . $field;
- if (method_exists($this, $method))
- {
+ $method = 'format' . Str::studly($field);
+ if (method_exists($this, $method)) {
$data[$name] = $this->$method($value);
- }
- else
- {
+ } else {
$data[$name] = $value;
}
}
- $data = $this->add_metadata($data, $entity);
+ $data = $this->addMetadata($data, $entity);
return $data;
}
@@ -63,25 +62,25 @@ public function __invoke($entity)
* @param Entity $entity resource
* @return Array
*/
- protected function add_metadata(Array $data, Entity $entity)
+ protected function addMetadata(array $data, Entity $entity)
{
// By default, noop
return $data;
}
- protected function get_field_name($field)
+ protected function getFieldName($field)
{
// can be overloaded to remap specific fields to different public names
return $field;
}
- protected function format_created($value)
+ protected function formatCreated($value)
{
- return date(DateTime::W3C, $value);
+ return date(\DateTime::W3C, $value);
}
- protected function format_updated($value)
+ protected function formatUpdated($value)
{
- return $value ? $this->format_created($value) : NULL;
+ return $value ? $this->formatCreated($value) : null;
}
}
diff --git a/application/classes/Ushahidi/Formatter/Contact.php b/src/App/Formatter/Contact.php
similarity index 74%
rename from application/classes/Ushahidi/Formatter/Contact.php
rename to src/App/Formatter/Contact.php
index d89e4ed71e..79c4cd106f 100644
--- a/application/classes/Ushahidi/Formatter/Contact.php
+++ b/src/App/Formatter/Contact.php
@@ -1,4 +1,4 @@
- $input)
- {
- if (isset($input['description']) AND $input['description'] instanceof \Closure)
- {
+ foreach ($options as $name => $input) {
+ if (isset($input['description']) and $input['description'] instanceof \Closure) {
$options[$name]['description'] = $options[$name]['description']();
}
- if (isset($input['label']) AND $input['label'] instanceof \Closure)
- {
+ if (isset($input['label']) and $input['label'] instanceof \Closure) {
$options[$name]['label'] = $options[$name]['label']();
}
- if (isset($input['rules']) AND $input['rules'] instanceof \Closure)
- {
+ if (isset($input['rules']) and $input['rules'] instanceof \Closure) {
$options[$name]['rules'] = $options[$name]['rules']();
}
}
diff --git a/application/classes/Ushahidi/Formatter/Form.php b/src/App/Formatter/Form.php
similarity index 71%
rename from application/classes/Ushahidi/Formatter/Form.php
rename to src/App/Formatter/Form.php
index dc9d0e8866..53e1837f13 100644
--- a/application/classes/Ushahidi/Formatter/Form.php
+++ b/src/App/Formatter/Form.php
@@ -1,4 +1,4 @@
- $entity->role_id,
];
- $data = $this->add_metadata($data, $entity);
+ $data = $this->addMetadata($data, $entity);
return $data;
}
diff --git a/application/classes/Ushahidi/Formatter/Form/Stage.php b/src/App/Formatter/Form/Stage.php
similarity index 74%
rename from application/classes/Ushahidi/Formatter/Form/Stage.php
rename to src/App/Formatter/Form/Stage.php
index 596337b94e..0e34357dd2 100644
--- a/application/classes/Ushahidi/Formatter/Form/Stage.php
+++ b/src/App/Formatter/Form/Stage.php
@@ -1,4 +1,4 @@
-getOptions();
$json = json_encode($input, $opts);
- if ($json === FALSE)
+ if ($json === false) {
throw new FormatterException('Unable to format data as JSON: ' . json_last_error());
+ }
return $json;
}
@@ -40,4 +44,3 @@ public function getMimeType()
return 'application/json';
}
}
-
diff --git a/application/classes/Ushahidi/Formatter/JSONP.php b/src/App/Formatter/JSONP.php
similarity index 88%
rename from application/classes/Ushahidi/Formatter/JSONP.php
rename to src/App/Formatter/JSONP.php
index 2ea59df412..0407e1c937 100644
--- a/application/classes/Ushahidi/Formatter/JSONP.php
+++ b/src/App/Formatter/JSONP.php
@@ -1,4 +1,4 @@
-callback = $callback;
return $this;
@@ -70,4 +73,3 @@ public function getMimeType()
return 'application/javascript';
}
}
-
diff --git a/application/classes/Ushahidi/Formatter/Layer.php b/src/App/Formatter/Layer.php
similarity index 61%
rename from application/classes/Ushahidi/Formatter/Layer.php
rename to src/App/Formatter/Layer.php
index 83f629f891..8f171d0402 100644
--- a/application/classes/Ushahidi/Formatter/Layer.php
+++ b/src/App/Formatter/Layer.php
@@ -1,4 +1,4 @@
- 'media',
@@ -25,11 +27,11 @@ protected function get_field_name($field)
return $remap[$field];
}
- return parent::get_field_name($field);
+ return parent::getFieldName($field);
}
- protected function format_media_id($media_id)
+ protected function formatMediaId($media_id)
{
- return $this->get_relation('media', $media_id);
+ return $this->getRelation('media', $media_id);
}
}
diff --git a/application/classes/Ushahidi/Formatter/Media.php b/src/App/Formatter/Media.php
similarity index 66%
rename from application/classes/Ushahidi/Formatter/Media.php
rename to src/App/Formatter/Media.php
index 1a44ed10e3..e8de82ab58 100644
--- a/application/classes/Ushahidi/Formatter/Media.php
+++ b/src/App/Formatter/Media.php
@@ -1,4 +1,4 @@
-load('media.image_medium_width');
@@ -26,10 +29,10 @@ protected function add_metadata(Array $data, Entity $media)
return $data + [
// Add additional URLs and sizes
- // 'medium_file_url' => $this->resized_url($medium_width, $medium_height, $media->o_filename),
+ // 'medium_file_url' => $this->resizedUrl($medium_width, $medium_height, $media->o_filename),
// 'medium_width' => $medium_width,
// 'medium_height' => $medium_height,
- // 'thumbnail_file_url' => $this->resized_url($thumbnail_width, $thumbnail_height, $media->o_filename),
+ // 'thumbnail_file_url' => $this->resizedUrl($thumbnail_width, $thumbnail_height, $media->o_filename),
// 'thumbnail_width' => $thumbnail_width,
// 'thumbnail_height' => $thumbnail_height,
@@ -38,7 +41,7 @@ protected function add_metadata(Array $data, Entity $media)
];
}
- protected function get_field_name($field)
+ protected function getFieldName($field)
{
$remap = [
'o_filename' => 'original_file_url',
@@ -51,21 +54,25 @@ protected function get_field_name($field)
return $remap[$field];
}
- return parent::get_field_name($field);
+ return parent::getFieldName($field);
}
- protected function format_o_filename($value)
+ protected function formatOFilename($value)
{
if ($cdnBaseUrl = Kohana::$config->load('cdn.baseurl')) {
return $cdnBaseUrl . $value;
} else {
- return URL::site(Media::uri($this->get_relative_path() . $value), Request::current());
+ return \URL::site(\Media::uri($this->getRelativePath() . $value), \Request::current());
}
}
- private function get_relative_path()
+ private function getRelativePath()
{
- return str_replace(Kohana::$config->load('imagefly.source_dir'), '', Kohana::$config->load('media.media_upload_dir'));
+ return str_replace(
+ Kohana::$config->load('imagefly.source_dir'),
+ '',
+ Kohana::$config->load('media.media_upload_dir')
+ );
}
/**
@@ -76,26 +83,23 @@ private function get_relative_path()
* @param string $filename The file name of the image
* @return string URL to the resized image
*/
- private function resized_url($width, $height, $filename)
+ private function resizedUrl($width, $height, $filename)
{
// Format demensions appropriately depending on the value of the height
- if ($height != NULL)
- {
+ if ($height != null) {
// Image height has been set
$dimension = sprintf('w%s-h%s', $width, $height);
- }
- else
- {
+ } else {
// No image height set.
$dimension = sprintf('w%s', $width);
}
- return URL::site(
- Route::get('imagefly')->uri(array(
+ return \URL::site(
+ \Route::get('imagefly')->uri(array(
'params' => $dimension,
- 'imagepath' => $this->get_relative_path() . $filename,
+ 'imagepath' => $this->getRelativePath() . $filename,
)),
- Request::current()
+ \Request::current()
);
}
}
diff --git a/application/classes/Ushahidi/Formatter/Message.php b/src/App/Formatter/Message.php
similarity index 74%
rename from application/classes/Ushahidi/Formatter/Message.php
rename to src/App/Formatter/Message.php
index ae79b3b00e..206174ef72 100644
--- a/application/classes/Ushahidi/Formatter/Message.php
+++ b/src/App/Formatter/Message.php
@@ -1,4 +1,4 @@
- 'set'
@@ -25,11 +27,11 @@ protected function get_field_name($field)
return $remap[$field];
}
- return parent::get_field_name($field);
+ return parent::getFieldName($field);
}
- protected function format_set_id($set_id)
+ protected function formatSetId($set_id)
{
- return $this->get_relation('sets', $set_id);
+ return $this->getRelation('sets', $set_id);
}
}
diff --git a/application/classes/Ushahidi/Formatter/Permission.php b/src/App/Formatter/Permission.php
similarity index 74%
rename from application/classes/Ushahidi/Formatter/Permission.php
rename to src/App/Formatter/Permission.php
index f27936efb0..d3099d2520 100644
--- a/application/classes/Ushahidi/Formatter/Permission.php
+++ b/src/App/Formatter/Permission.php
@@ -1,4 +1,4 @@
- 'form',
@@ -28,44 +30,43 @@ protected function get_field_name($field)
return $remap[$field];
}
- return parent::get_field_name($field);
+ return parent::getFieldName($field);
}
- protected function format_form_id($form_id)
+ protected function formatFormId($form_id)
{
- return $this->get_relation('forms', $form_id);
+ return $this->getRelation('forms', $form_id);
}
- protected function format_message_id($form_id)
+ protected function formatMessageId($form_id)
{
- return $this->get_relation('messages', $form_id);
+ return $this->getRelation('messages', $form_id);
}
- protected function format_contact_id($contact_id)
+ protected function formatContactId($contact_id)
{
- return $this->get_relation('contact', $contact_id);
+ return $this->getRelation('contact', $contact_id);
}
- protected function format_color($value)
+ protected function formatColor($value)
{
// enforce a leading hash on color, or null if unset
$value = ltrim($value, '#');
return $value ? '#' . $value : null;
}
- protected function format_tags($tags)
+ protected function formatTags($tags)
{
$output = [];
- foreach ($tags as $tagid)
- {
- $output[] = $this->get_relation('tags', $tagid);
+ foreach ($tags as $tagid) {
+ $output[] = $this->getRelation('tags', $tagid);
}
return $output;
}
- protected function format_post_date($value)
+ protected function formatPostDate($value)
{
- return $value ? $value->format(DateTime::W3C) : NULL;
+ return $value ? $value->format(\DateTime::W3C) : null;
}
}
diff --git a/application/classes/Ushahidi/Formatter/Post/CSV.php b/src/App/Formatter/Post/CSV.php
similarity index 79%
rename from application/classes/Ushahidi/Formatter/Post/CSV.php
rename to src/App/Formatter/Post/CSV.php
index fbcf155cc8..d72540189f 100644
--- a/application/classes/Ushahidi/Formatter/Post/CSV.php
+++ b/src/App/Formatter/Post/CSV.php
@@ -1,4 +1,4 @@
-format("Y-m-d H:i:s");
}
- foreach ($record as $key => $val)
- {
+ foreach ($record as $key => $val) {
// Assign form values
- if ($key == 'values')
- {
+ if ($key == 'values') {
unset($record[$key]);
- foreach ($val as $key => $val)
- {
+ foreach ($val as $key => $val) {
$this->assignRowValue($record, $key, $val[0]);
}
- }
-
- // Assign post values
- else
- {
+ } // Assign post values
+ else {
unset($record[$key]);
$this->assignRowValue($record, $key, $val);
}
@@ -100,43 +95,31 @@ protected function generateCSVRecords($records)
private function assignRowValue(&$record, $key, $value)
{
- if (is_array($value))
- {
+ if (is_array($value)) {
// Assign in multiple columns
- foreach ($value as $sub_key => $sub_value)
- {
+ foreach ($value as $sub_key => $sub_value) {
$record[$key.'.'.$sub_key] = $sub_value;
}
- }
-
- // ... else assign value as single string
- else
- {
+ } // ... else assign value as single string
+ else {
$record[$key] = $value;
}
}
private function assignColumnHeading(&$columns, $key, $label, $value)
{
- if (is_array($value))
- {
+ if (is_array($value)) {
// Assign in multiple columns
- foreach ($value as $sub_key => $sub_value)
- {
+ foreach ($value as $sub_key => $sub_value) {
$multivalue_key = $key.'.'.$sub_key;
- if (! in_array($multivalue_key, $columns))
- {
+ if (! in_array($multivalue_key, $columns)) {
$columns[$multivalue_key] = $label.'.'.$sub_key;
}
}
- }
-
- // ... else assign single key
- else
- {
- if (! in_array($key, $columns))
- {
+ } // ... else assign single key
+ else {
+ if (! in_array($key, $columns)) {
$columns[$key] = $label;
}
}
@@ -154,29 +137,21 @@ protected function getCSVHeading($records)
$columns = [];
// Collect all column headings
- foreach ($records as $record)
- {
+ foreach ($records as $record) {
//$record = $record->asArray();
$attributes = $record['attributes'];
unset($record['attributes']);
- foreach ($record as $key => $val)
- {
+ foreach ($record as $key => $val) {
// Assign form keys
- if ($key == 'values')
- {
-
- foreach ($val as $key => $val)
- {
+ if ($key == 'values') {
+ foreach ($val as $key => $val) {
$label = $attributes[$key];
$this->assignColumnHeading($columns, $key, $label, $val[0]);
}
- }
-
- // Assign post keys
- else
- {
+ } // Assign post keys
+ else {
$this->assignColumnHeading($columns, $key, $key, $val);
}
}
diff --git a/application/classes/Ushahidi/Formatter/Post/GeoJSON.php b/src/App/Formatter/Post/GeoJSON.php
similarity index 80%
rename from application/classes/Ushahidi/Formatter/Post/GeoJSON.php
rename to src/App/Formatter/Post/GeoJSON.php
index 06750d7cfe..fed7a2250c 100644
--- a/application/classes/Ushahidi/Formatter/Post/GeoJSON.php
+++ b/src/App/Formatter/Post/GeoJSON.php
@@ -1,4 +1,4 @@
-values as $attribute => $values)
- {
- foreach($values as $value)
- {
- if ($geometry = $this->valueToGeometry($value))
- {
+ foreach ($entity->values as $attribute => $values) {
+ foreach ($values as $value) {
+ if ($geometry = $this->valueToGeometry($value)) {
$color = ltrim($entity->color, '#');
$color = $color ? '#' . $color : null;
@@ -54,5 +53,4 @@ public function __invoke($entity)
// @todo include bbox
];
}
-
}
diff --git a/application/classes/Ushahidi/Formatter/Post/GeoJSONCollection.php b/src/App/Formatter/Post/GeoJSONCollection.php
similarity index 82%
rename from application/classes/Ushahidi/Formatter/Post/GeoJSONCollection.php
rename to src/App/Formatter/Post/GeoJSONCollection.php
index d4fd6cc715..3973731395 100644
--- a/application/classes/Ushahidi/Formatter/Post/GeoJSONCollection.php
+++ b/src/App/Formatter/Post/GeoJSONCollection.php
@@ -1,4 +1,4 @@
- []
];
- foreach ($entities as $entity)
- {
+ foreach ($entities as $entity) {
$geometries = [];
- foreach($entity->values as $attribute => $values)
- {
- foreach ($values as $value)
- {
- if ($geometry = $this->valueToGeometry($value))
- {
+ foreach ($entity->values as $attribute => $values) {
+ foreach ($values as $value) {
+ if ($geometry = $this->valueToGeometry($value)) {
$geometries[] = $geometry;
}
}
}
- if (! empty($geometries))
- {
+ if (! empty($geometries)) {
$color = ltrim($entity->color, '#');
$color = $color ? '#' . $color : null;
@@ -70,14 +67,10 @@ public function __invoke($entities)
}
}
- if ($this->search->bbox)
- {
- if (is_array($this->search->bbox))
- {
+ if ($this->search->bbox) {
+ if (is_array($this->search->bbox)) {
$bbox = $this->search->bbox;
- }
- else
- {
+ } else {
$bbox = explode(',', $this->search->bbox);
}
@@ -104,5 +97,4 @@ public function setSearch(SearchData $search, $total = null)
$this->total = $total;
return $this;
}
-
}
diff --git a/application/classes/Ushahidi/Formatter/Post/Stats.php b/src/App/Formatter/Post/Stats.php
similarity index 94%
rename from application/classes/Ushahidi/Formatter/Post/Stats.php
rename to src/App/Formatter/Post/Stats.php
index 0a23f0bb9b..e5b291c5a6 100644
--- a/application/classes/Ushahidi/Formatter/Post/Stats.php
+++ b/src/App/Formatter/Post/Stats.php
@@ -1,4 +1,4 @@
- $record['label'],
diff --git a/application/classes/Ushahidi/Formatter/PostValue.php b/src/App/Formatter/PostValue.php
similarity index 75%
rename from application/classes/Ushahidi/Formatter/PostValue.php
rename to src/App/Formatter/PostValue.php
index 6897855a08..b056cc4354 100644
--- a/application/classes/Ushahidi/Formatter/PostValue.php
+++ b/src/App/Formatter/PostValue.php
@@ -1,4 +1,4 @@
-map[$entity->type]))
- {
+ if (isset($this->map[$entity->type])) {
$formatter = $this->map[$entity->type];
return $formatter($entity);
}
diff --git a/application/classes/Ushahidi/Formatter/Role.php b/src/App/Formatter/Role.php
similarity index 74%
rename from application/classes/Ushahidi/Formatter/Role.php
rename to src/App/Formatter/Role.php
index 07ff7a6a1d..a1f6eac55f 100644
--- a/application/classes/Ushahidi/Formatter/Role.php
+++ b/src/App/Formatter/Role.php
@@ -1,4 +1,4 @@
-get_relation('forms', $formid);
+ foreach ($forms as $formid) {
+ $output[] = $this->getRelation('forms', $formid);
}
-
+
return $output;
}
}
diff --git a/application/classes/Ushahidi/Formatter/User.php b/src/App/Formatter/User.php
similarity index 51%
rename from application/classes/Ushahidi/Formatter/User.php
rename to src/App/Formatter/User.php
index 7cff1e2906..72ca96ed33 100644
--- a/application/classes/Ushahidi/Formatter/User.php
+++ b/src/App/Formatter/User.php
@@ -1,4 +1,4 @@
- 'user'
@@ -25,11 +27,11 @@ protected function get_field_name($field)
return $remap[$field];
}
- return parent::get_field_name($field);
+ return parent::getFieldName($field);
}
- protected function format_user_id($user_id)
+ protected function formatUserId($user_id)
{
- return $this->get_relation('users', $user_id);
+ return $this->getRelation('users', $user_id);
}
}
diff --git a/src/App/Init.php b/src/App/Init.php
index 23cb3893d4..1054059cdb 100644
--- a/src/App/Init.php
+++ b/src/App/Init.php
@@ -8,41 +8,41 @@
$di = service();
// Helpers, tools, etc
-$di->set('tool.acl', $di->lazyNew('Ushahidi\App\Acl'));
-$di->setter['Ushahidi\App\Acl']['setRoleRepo'] = $di->lazyGet('repository.role');
+$di->set('tool.acl', $di->lazyNew(Ushahidi\App\Acl::class));
+$di->setter[Ushahidi\App\Acl::class]['setRoleRepo'] = $di->lazyGet('repository.role');
-$di->set('tool.hasher.password', $di->lazyNew('Ushahidi\App\Hasher\Password'));
-$di->set('tool.authenticator.password', $di->lazyNew('Ushahidi\App\Authenticator\Password'));
+$di->set('tool.hasher.password', $di->lazyNew(Ushahidi\App\Hasher\Password::class));
+$di->set('tool.authenticator.password', $di->lazyNew(Ushahidi\App\Authenticator\Password::class));
-$di->set('filereader.csv', $di->lazyNew('Ushahidi\App\FileReader\CSV'));
-$di->setter['Ushahidi\App\FileReader\CSV']['setReaderFactory'] =
+$di->set('filereader.csv', $di->lazyNew(Ushahidi\App\FileReader\CSV::class));
+$di->setter[Ushahidi\App\FileReader\CSV::class]['setReaderFactory'] =
$di->lazyGet('csv.reader_factory');
-$di->set('csv.reader_factory', $di->lazyNew('Ushahidi\App\FileReader\CSVReaderFactory'));
+$di->set('csv.reader_factory', $di->lazyNew(Ushahidi\App\FileReader\CSVReaderFactory::class));
// Register filesystem adapter types
// Currently supported: Local filesysten, AWS S3 v3, Rackspace
// the naming scheme must match the cdn type set in config/cdn
$di->set('adapter.local', $di->lazyNew(
- 'Ushahidi\App\FilesystemAdapter\Local',
+ Ushahidi\App\FilesystemAdapter\Local::class,
['config' => $di->lazyGet('cdn.config')]
));
$di->set('adapter.aws', $di->lazyNew(
- 'Ushahidi\App\FilesystemAdapter\AWS',
+ Ushahidi\App\FilesystemAdapter\AWS::class,
['config' => $di->lazyGet('cdn.config')]
));
$di->set('adapter.rackspace', $di->lazyNew(
- 'Ushahidi\App\FilesystemAdapter\Rackspace',
+ Ushahidi\App\FilesystemAdapter\Rackspace::class,
['config' => $di->lazyGet('cdn.config')]
));
// Media Filesystem
// The Ushahidi filesystem adapter returns a flysystem adapter for a given
// cdn type based on the provided configuration
-$di->set('tool.filesystem', $di->lazyNew('Ushahidi\App\Filesystem'));
-$di->params['Ushahidi\App\Filesystem'] = [
+$di->set('tool.filesystem', $di->lazyNew(Ushahidi\App\Filesystem::class));
+$di->params[Ushahidi\App\Filesystem::class] = [
'adapter' => $di->lazy(function () use ($di) {
$adapter_type = $di->get('cdn.config');
$fsa = $di->get('adapter.' . $adapter_type['type']);
@@ -77,9 +77,9 @@
'timeSpan' => '1m'
];
-$di->set('ratelimiter.login', $di->lazyNew('Ushahidi\App\RateLimiter'));
+$di->set('ratelimiter.login', $di->lazyNew(Ushahidi\App\RateLimiter::class));
-$di->params['Ushahidi\App\RateLimiter'] = [
+$di->params[Ushahidi\App\RateLimiter::class] = [
'flap' => $di->lazyGet('ratelimiter.login.flap'),
'throttlingStrategy' => $di->lazyGet('ratelimiter.login.strategy'),
];
@@ -112,4 +112,491 @@
// Rate limiter violation handler
$di->setter['BehEh\Flaps\Flap']['setViolationHandler'] =
- $di->lazyNew('Ushahidi\App\ThrottlingViolationHandler');
+ $di->lazyNew(Ushahidi\App\ThrottlingViolationHandler::class);
+
+
+// Validator mapping
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['config'] = [
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Config\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['forms'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Form\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Form\Update::class),
+ 'delete' => $di->lazyNew(Ushahidi\App\Validator\Form\Delete::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['form_attributes'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Form\Attribute\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Form\Attribute\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['form_roles'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Form\Role\Create::class),
+ 'update_collection' => $di->lazyNew(Ushahidi\App\Validator\Form\Role\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['form_stages'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Form\Stage\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Form\Stage\Update::class),
+ 'delete' => $di->lazyNew(Ushahidi\App\Validator\Form\Stage\Delete::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['layers'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Layer\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Layer\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['media'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Media\Create::class),
+ 'delete' => $di->lazyNew(Ushahidi\App\Validator\Media\Delete::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['posts'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Post\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Post\Create::class),
+ 'import' => $di->lazyNew(Ushahidi\App\Validator\Post\Import::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['tags'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Tag\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Tag\Update::class),
+ 'delete' => $di->lazyNew(Ushahidi\App\Validator\Tag\Delete::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['users'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\User\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\User\Update::class),
+ 'register' => $di->lazyNew(Ushahidi\App\Validator\User\Register::class)
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['messages'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Message\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Message\Update::class),
+ 'receive' => $di->lazyNew(Ushahidi\App\Validator\Message\Receive::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['savedsearches'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\SavedSearch\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\SavedSearch\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['sets'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Set\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Set\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['notifications'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Notification\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Notification\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['webhooks'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Webhook\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Webhook\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['contacts'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Contact\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Contact\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['sets_posts'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Set\Post\Create::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['csv'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\CSV\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\CSV\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['csv'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\CSV\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\CSV\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['roles'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Role\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Role\Update::class),
+];
+$di->params['Ushahidi\Factory\ValidatorFactory']['map']['permissions'] = [
+ 'create' => $di->lazyNew(Ushahidi\App\Validator\Permission\Create::class),
+ 'update' => $di->lazyNew(Ushahidi\App\Validator\Permission\Update::class),
+];
+
+// Validation Trait
+$di->setter['Ushahidi\Core\Tool\ValidationEngineTrait']['setValidation'] = $di->newFactory('Ushahidi_ValidationEngine');
+$di->params['Ushahidi_ValidationEngine']['array'] = [];
+
+// Formatter mapping
+$di->params['Ushahidi\Factory\FormatterFactory']['map'] = [
+ 'config' => $di->lazyNew(Ushahidi\App\Formatter\Config::class),
+ 'dataproviders' => $di->lazyNew(Ushahidi\App\Formatter\Dataprovider::class),
+ 'forms' => $di->lazyNew(Ushahidi\App\Formatter\Form::class),
+ 'form_attributes' => $di->lazyNew(Ushahidi\App\Formatter\Form\Attribute::class),
+ 'form_roles' => $di->lazyNew(Ushahidi\App\Formatter\Form\Role::class),
+ 'form_stages' => $di->lazyNew(Ushahidi\App\Formatter\Form\Stage::class),
+ 'layers' => $di->lazyNew(Ushahidi\App\Formatter\Layer::class),
+ 'media' => $di->lazyNew(Ushahidi\App\Formatter\Media::class),
+ 'messages' => $di->lazyNew(Ushahidi\App\Formatter\Message::class),
+ 'posts' => $di->lazyNew(Ushahidi\App\Formatter\Post::class),
+ 'tags' => $di->lazyNew(Ushahidi\App\Formatter\Tag::class),
+ 'savedsearches' => $di->lazyNew(Ushahidi\App\Formatter\Set::class),
+ 'sets' => $di->lazyNew(Ushahidi\App\Formatter\Set::class),
+ 'sets_posts' => $di->lazyNew(Ushahidi\App\Formatter\Post::class),
+ 'savedsearches_posts' => $di->lazyNew(Ushahidi\App\Formatter\Post::class),
+ 'users' => $di->lazyNew(Ushahidi\App\Formatter\User::class),
+ 'notifications' => $di->lazyNew(Ushahidi\App\Formatter\Notification::class),
+ 'webhooks' => $di->lazyNew(Ushahidi\App\Formatter\Webhook::class),
+ 'contacts' => $di->lazyNew(Ushahidi\App\Formatter\Contact::class),
+ 'csv' => $di->lazyNew(Ushahidi\App\Formatter\CSV::class),
+ 'roles' => $di->lazyNew(Ushahidi\App\Formatter\Role::class),
+ 'permissions' => $di->lazyNew(Ushahidi\App\Formatter\Permission::class),
+ // Formatter for post exports. Defaults to CSV export
+ 'posts_export' => $di->lazyNew(Ushahidi\App\Formatter\Post\CSV::class),
+];
+
+// Formatter parameters
+$di->setter[Ushahidi\App\Formatter\Config::class]['setAuth'] = $di->lazyGet("authorizer.config");
+$di->setter[Ushahidi\App\Formatter\CSV::class]['setAuth'] = $di->lazyGet("authorizer.csv");
+$di->setter[Ushahidi\App\Formatter\Dataprovider::class]['setAuth'] = $di->lazyGet("authorizer.dataprovider");
+$di->setter[Ushahidi\App\Formatter\Form::class]['setAuth'] = $di->lazyGet("authorizer.form");
+$di->setter[Ushahidi\App\Formatter\Form\Attribute::class]['setAuth'] = $di->lazyGet("authorizer.form_attribute");
+$di->setter[Ushahidi\App\Formatter\Form\Role::class]['setAuth'] = $di->lazyGet("authorizer.form_role");
+$di->setter[Ushahidi\App\Formatter\Form\Stage::class]['setAuth'] = $di->lazyGet("authorizer.form_stage");
+$di->setter[Ushahidi\App\Formatter\Layer::class]['setAuth'] = $di->lazyGet("authorizer.layer");
+$di->setter[Ushahidi\App\Formatter\Media::class]['setAuth'] = $di->lazyGet("authorizer.media");
+$di->setter[Ushahidi\App\Formatter\Message::class]['setAuth'] = $di->lazyGet("authorizer.message");
+$di->setter[Ushahidi\App\Formatter\Post::class]['setAuth'] = $di->lazyGet("authorizer.post");
+$di->setter[Ushahidi\App\Formatter\Tag::class]['setAuth'] = $di->lazyGet("authorizer.tag");
+$di->setter[Ushahidi\App\Formatter\User::class]['setAuth'] = $di->lazyGet("authorizer.user");
+$di->setter[Ushahidi\App\Formatter\Savedsearch::class]['setAuth'] = $di->lazyGet("authorizer.savedsearch");
+$di->setter[Ushahidi\App\Formatter\Set::class]['setAuth'] = $di->lazyGet("authorizer.set");
+$di->setter[Ushahidi\App\Formatter\Set\Post::class]['setAuth'] = $di->lazyGet("authorizer.set_post");
+$di->setter[Ushahidi\App\Formatter\Notification::class]['setAuth'] = $di->lazyGet("authorizer.notification");
+$di->setter[Ushahidi\App\Formatter\Webhook::class]['setAuth'] = $di->lazyGet("authorizer.webhook");
+$di->setter[Ushahidi\App\Formatter\Contact::class]['setAuth'] = $di->lazyGet("authorizer.contact");
+$di->setter[Ushahidi\App\Formatter\Role::class]['setAuth'] = $di->lazyGet("authorizer.role");
+$di->setter[Ushahidi\App\Formatter\Permission::class]['setAuth'] = $di->lazyGet("authorizer.permission");
+
+// Set Formatter factory
+$di->params['Ushahidi\Factory\FormatterFactory']['factory'] = $di->newFactory(Ushahidi\App\Formatter\Collection::class);
+
+
+$di->set('tool.jsontranscode', $di->lazyNew('Ushahidi\Core\Tool\JsonTranscode'));
+
+// Formatters
+$di->set('formatter.entity.api', $di->lazyNew(Ushahidi\App\Formatter\API::class));
+$di->set('formatter.entity.console', $di->lazyNew(Ushahidi\App\Formatter\Console::class));
+$di->set('formatter.entity.post.value', $di->lazyNew(Ushahidi\App\Formatter\PostValue::class));
+$di->set('formatter.entity.post.geojson', $di->lazyNew(Ushahidi\App\Formatter\Post\GeoJSON::class));
+$di->set('formatter.entity.post.geojsoncollection', $di->lazyNew(Ushahidi\App\Formatter\Post\GeoJSONCollection::class));
+$di->set('formatter.entity.post.stats', $di->lazyNew(Ushahidi\App\Formatter\Post\Stats::class));
+$di->set('formatter.entity.post.csv', $di->lazyNew(Ushahidi\App\Formatter\Post\CSV::class));
+
+$di->set('formatter.output.json', $di->lazyNew(Ushahidi\App\Formatter\JSON::class));
+$di->set('formatter.output.jsonp', $di->lazyNew(Ushahidi\App\Formatter\JSONP::class));
+
+// Formatter parameters
+$di->setter[Ushahidi\App\Formatter\JSONP::class]['setCallback'] = function () {
+ return Request::current()->query('callback');
+};
+$di->params[Ushahidi\App\Formatter\Post::class] = [
+ 'value_formatter' => $di->lazyGet('formatter.entity.post.value')
+];
+$di->setter[Ushahidi\App\Formatter\Post\GeoJSON::class]['setDecoder'] = $di->lazyNew('Symm\Gisconverter\Decoders\WKT');
+$di->setter[Ushahidi\App\Formatter\Post\GeoJSONCollection::class]['setDecoder'] =
+ $di->lazyNew('Symm\Gisconverter\Decoders\WKT');
+
+// Repositories
+$di->set('repository.config', $di->lazyNew(Ushahidi\App\Repository\ConfigRepository::class));
+$di->set('repository.contact', $di->lazyNew(Ushahidi\App\Repository\ContactRepository::class));
+$di->set('repository.dataprovider', $di->lazyNew(Ushahidi\App\Repository\DataproviderRepository::class));
+$di->set('repository.form', $di->lazyNew(Ushahidi\App\Repository\FormRepository::class));
+$di->set('repository.form_role', $di->lazyNew(Ushahidi\App\Repository\Form\RoleRepository::class));
+$di->set('repository.form_stage', $di->lazyNew(Ushahidi\App\Repository\Form\StageRepository::class));
+$di->set('repository.form_attribute', $di->lazyNew(Ushahidi\App\Repository\Form\AttributeRepository::class));
+$di->set('repository.layer', $di->lazyNew(Ushahidi\App\Repository\LayerRepository::class));
+$di->set('repository.media', $di->lazyNew(Ushahidi\App\Repository\MediaRepository::class));
+$di->set('repository.message', $di->lazyNew(Ushahidi\App\Repository\MessageRepository::class));
+$di->set('repository.post', $di->lazyNew(Ushahidi\App\Repository\PostRepository::class));
+$di->set('repository.tag', $di->lazyNew(Ushahidi\App\Repository\TagRepository::class));
+$di->set('repository.set', $di->lazyNew(Ushahidi\App\Repository\SetRepository::class));
+$di->set('repository.savedsearch', $di->lazyNew(
+ Ushahidi\App\Repository\SetRepository::class,
+ [],
+ [
+ 'setSavedSearch' => true
+ ]
+));
+$di->set('repository.user', $di->lazyNew(Ushahidi\App\Repository\UserRepository::class));
+$di->set('repository.role', $di->lazyNew(Ushahidi\App\Repository\RoleRepository::class));
+$di->set('repository.notification', $di->lazyNew(Ushahidi\App\Repository\NotificationRepository::class));
+$di->set('repository.webhook', $di->lazyNew(Ushahidi\App\Repository\WebhookRepository::class));
+$di->set('repository.csv', $di->lazyNew(Ushahidi\App\Repository\CSVRepository::class));
+$di->set('repository.notification.queue', $di->lazyNew(Ushahidi\App\Repository\Notification\QueueRepository::class));
+$di->set('repository.webhook.job', $di->lazyNew(Ushahidi\App\Repository\Webhook\JobRepository::class));
+$di->set('repository.permission', $di->lazyNew(Ushahidi\App\Repository\PermissionRepository::class));
+// $di->set('repository.oauth.client', $di->lazyNew('OAuth2_Storage_Client'));
+// $di->set('repository.oauth.session', $di->lazyNew('OAuth2_Storage_Session'));
+// $di->set('repository.oauth.scope', $di->lazyNew('OAuth2_Storage_Scope'));
+$di->set('repository.posts_export', $di->lazyNew(Ushahidi\App\Repository\Post\ExportRepository::class));
+
+$di->setter[Ushahidi\App\Repository\UserRepository::class]['setHasher'] = $di->lazyGet('tool.hasher.password');
+
+// Repository parameters
+
+// Abstract repository parameters
+$di->params[Ushahidi\App\Repository\OhanzeeRepository::class] = [
+ 'db' => $di->lazyGet('kohana.db'),
+ ];
+
+// Set up Json Transcode Repository Trait
+$di->setter[Ushahidi\App\Repository\JsonTranscodeRepository::class]['setTranscoder'] =
+ $di->lazyGet('tool.jsontranscode');
+
+// Media repository parameters
+$di->params[Ushahidi\App\Repository\MediaRepository::class] = [
+ 'upload' => $di->lazyGet('tool.uploader'),
+ ];
+
+// Form Stage repository parameters
+$di->params[Ushahidi\App\Repository\Form\StageRepository::class] = [
+ 'form_repo' => $di->lazyGet('repository.form')
+];
+
+// Form Attribute repository parameters
+$di->params[Ushahidi\App\Repository\Form\AttributeRepository::class] = [
+ 'form_stage_repo' => $di->lazyGet('repository.form_stage'),
+ 'form_repo' => $di->lazyGet('repository.form')
+];
+
+// Post repository parameters
+$di->params[Ushahidi\App\Repository\PostRepository::class] = [
+ 'form_attribute_repo' => $di->lazyGet('repository.form_attribute'),
+ 'form_stage_repo' => $di->lazyGet('repository.form_stage'),
+ 'form_repo' => $di->lazyGet('repository.form'),
+ 'post_value_factory' => $di->lazyGet('repository.post_value_factory'),
+ 'bounding_box_factory' => $di->newFactory(Ushahidi\App\Util\BoundingBox::class),
+ 'tag_repo' => $di->lazyGet('repository.tag')
+ ];
+
+$di->set('repository.post.datetime', $di->lazyNew(Ushahidi\App\Repository\Post\DatetimeRepository::class));
+$di->set('repository.post.decimal', $di->lazyNew(Ushahidi\App\Repository\Post\DecimalRepository::class));
+$di->set('repository.post.geometry', $di->lazyNew(Ushahidi\App\Repository\Post\GeometryRepository::class));
+$di->set('repository.post.int', $di->lazyNew(Ushahidi\App\Repository\Post\IntRepository::class));
+$di->set('repository.post.point', $di->lazyNew(Ushahidi\App\Repository\Post\PointRepository::class));
+$di->set('repository.post.relation', $di->lazyNew(Ushahidi\App\Repository\Post\RelationRepository::class));
+$di->set('repository.post.text', $di->lazyNew(Ushahidi\App\Repository\Post\TextRepository::class));
+$di->set('repository.post.description', $di->lazyNew(Ushahidi\App\Repository\Post\DescriptionRepository::class));
+$di->set('repository.post.varchar', $di->lazyNew(Ushahidi\App\Repository\Post\VarcharRepository::class));
+$di->set('repository.post.markdown', $di->lazyNew(Ushahidi\App\Repository\Post\MarkdownRepository::class));
+$di->set('repository.post.title', $di->lazyNew(Ushahidi\App\Repository\Post\TitleRepository::class));
+$di->set('repository.post.media', $di->lazyNew(Ushahidi\App\Repository\Post\MediaRepository::class));
+
+// The post value repo factory
+$di->set('repository.post_value_factory', $di->lazyNew(Ushahidi\App\Repository\Post\ValueFactory::class));
+$di->params[Ushahidi\App\Repository\Post\ValueFactory::class] = [
+ // a map of attribute types to repositories
+ 'map' => [
+ 'datetime' => $di->lazyGet('repository.post.datetime'),
+ 'decimal' => $di->lazyGet('repository.post.decimal'),
+ 'geometry' => $di->lazyGet('repository.post.geometry'),
+ 'int' => $di->lazyGet('repository.post.int'),
+ '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'),
+ 'markdown' => $di->lazyGet('repository.post.markdown'),
+ 'title' => $di->lazyGet('repository.post.title'),
+ 'media' => $di->lazyGet('repository.post.media'),
+ ],
+ ];
+
+$di->params[Ushahidi\App\Repository\Post\PointRepository::class] = [
+ 'decoder' => $di->lazyNew('Symm\Gisconverter\Decoders\WKT')
+ ];
+
+// Validators
+$di->set('validator.user.login', $di->lazyNew(Ushahidi\App\Validator\User\Login::class));
+$di->set('validator.contact.create', $di->lazyNew(Ushahidi\App\Validator\Contact\Create::class));
+$di->set('validator.contact.receive', $di->lazyNew(Ushahidi\App\Validator\Contact\Receive::class));
+
+$di->params[Ushahidi\App\Validator\Contact\Update::class] = [
+ 'repo' => $di->lazyGet('repository.user'),
+];
+
+// Dependencies of validators
+$di->params[Ushahidi\App\Validator\Post\Create::class] = [
+ 'repo' => $di->lazyGet('repository.post'),
+ 'attribute_repo' => $di->lazyGet('repository.form_attribute'),
+ 'stage_repo' => $di->lazyGet('repository.form_stage'),
+ 'tag_repo' => $di->lazyGet('repository.tag'),
+ 'user_repo' => $di->lazyGet('repository.user'),
+ 'form_repo' => $di->lazyGet('repository.form'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+ 'post_value_factory' => $di->lazyGet('repository.post_value_factory'),
+ 'post_value_validator_factory' => $di->lazyGet('validator.post.value_factory'),
+ ];
+
+$di->params[Ushahidi\App\Validator\Form\Update::class] = [
+ 'repo' => $di->lazyGet('repository.form'),
+ ];
+
+$di->param[Ushahidi\App\Validator\Form\Attribute\Update::class] = [
+ 'repo' => $di->lazyGet('repository.form_attribute'),
+ 'form_stage_repo' => $di->lazyGet('repository.form_stage'),
+];
+$di->params[Ushahidi\App\Validator\Layer\Update::class] = [
+ 'media_repo' => $di->lazyGet('repository.media'),
+];
+$di->params[Ushahidi\App\Validator\Message\Update::class] = [
+ 'repo' => $di->lazyGet('repository.message'),
+];
+$di->params[Ushahidi\App\Validator\Message\Create::class] = [
+ 'repo' => $di->lazyGet('repository.message'),
+ 'user_repo' => $di->lazyGet('repository.user')
+];
+
+$di->params[Ushahidi\App\Validator\Message\Receive::class] = [
+ 'repo' => $di->lazyGet('repository.message'),
+];
+
+$di->params[Ushahidi\App\Validator\Set\Update::class] = [
+ 'repo' => $di->lazyGet('repository.user'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+];
+$di->params[Ushahidi\App\Validator\Notification\Update::class] = [
+ 'user_repo' => $di->lazyGet('repository.user'),
+ 'collection_repo' => $di->lazyGet('repository.set'),
+ 'savedsearch_repo' => $di->lazyGet('repository.savedsearch'),
+];
+$di->params[Ushahidi\App\Validator\Webhook\Update::class] = [
+ 'user_repo' => $di->lazyGet('repository.user'),
+];
+$di->params[Ushahidi\App\Validator\SavedSearch\Create::class] = [
+ 'repo' => $di->lazyGet('repository.user'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+];
+$di->params[Ushahidi\App\Validator\SavedSearch\Update::class] = [
+ 'repo' => $di->lazyGet('repository.user'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+];
+
+$di->params[Ushahidi\App\Validator\Set\Post\Create::class] = [
+ 'post_repo' => $di->lazyGet('repository.post')
+];
+
+$di->params[Ushahidi\App\Validator\Tag\Update::class] = [
+ 'repo' => $di->lazyGet('repository.tag'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+];
+
+$di->params[Ushahidi\App\Validator\User\Create::class] = [
+ 'repo' => $di->lazyGet('repository.user'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+];
+$di->params[Ushahidi\App\Validator\User\Update::class] = [
+ 'repo' => $di->lazyGet('repository.user'),
+ 'user' => $di->lazyGet('session.user'),
+ 'role_repo' => $di->lazyGet('repository.role'),
+];
+$di->params[Ushahidi\App\Validator\User\Register::class] = [
+ 'repo' => $di->lazyGet('repository.user')
+];
+$di->params[Ushahidi\App\Validator\CSV\Create::class] = [
+ 'form_repo' => $di->lazyGet('repository.form'),
+];
+$di->params[Ushahidi\App\Validator\CSV\Update::class] = [
+ 'form_repo' => $di->lazyGet('repository.form'),
+];
+$di->params[Ushahidi\App\Validator\Role\Update::class] = [
+ 'permission_repo' => $di->lazyGet('repository.permission'),
+];
+
+// Validator Setters
+$di->setter[Ushahidi\App\Validator\Form\Stage\Update::class] = [
+ 'setFormRepo' => $di->lazyGet('repository.form'),
+];
+$di->setter[Ushahidi\App\Validator\Form\Role\Update::class] = [
+ 'setFormRepo' => $di->lazyGet('repository.form'),
+ 'setRoleRepo' => $di->lazyGet('repository.role'),
+];
+$di->setter[Ushahidi\App\Validator\Media\Create::class] = [
+ 'setMaxBytes' => $di->lazy(function () {
+ return \Kohana::$config->load('media.max_upload_bytes');
+ }),
+];
+$di->setter[Ushahidi\App\Validator\CSV\Create::class] = [
+ // @todo load from config
+ 'setMaxBytes' => '2048000',
+];
+
+
+$di->set('validator.post.datetime', $di->lazyNew(Ushahidi\App\Validator\Post\Datetime::class));
+$di->set('validator.post.decimal', $di->lazyNew(Ushahidi\App\Validator\Post\Decimal::class));
+$di->set('validator.post.geometry', $di->lazyNew(Ushahidi\App\Validator\Post\Geometry::class));
+$di->set('validator.post.int', $di->lazyNew(Ushahidi\App\Validator\Post\Int::class));
+$di->set('validator.post.link', $di->lazyNew(Ushahidi\App\Validator\Post\Link::class));
+$di->set('validator.post.point', $di->lazyNew(Ushahidi\App\Validator\Post\Point::class));
+$di->set('validator.post.relation', $di->lazyNew(Ushahidi\App\Validator\Post\Relation::class));
+$di->set('validator.post.varchar', $di->lazyNew(Ushahidi\App\Validator\Post\Varchar::class));
+$di->set('validator.post.markdown', $di->lazyNew(Ushahidi\App\Validator\Post\Markdown::class));
+$di->set('validator.post.video', $di->lazyNew(Ushahidi\App\Validator\Post\Video::class));
+$di->set('validator.post.title', $di->lazyNew(Ushahidi\App\Validator\Post\Title::class));
+$di->set('validator.post.media', $di->lazyNew(Ushahidi\App\Validator\Post\Media::class));
+$di->params[Ushahidi\App\Validator\Post\Media::class] = [
+ 'media_repo' => $di->lazyGet('repository.media')
+];
+
+
+$di->set('validator.post.value_factory', $di->lazyNew(Ushahidi\App\Validator\Post\ValueFactory::class));
+$di->params[Ushahidi\App\Validator\Post\ValueFactory::class] = [
+ // a map of attribute types to validators
+ 'map' => [
+ 'datetime' => $di->lazyGet('validator.post.datetime'),
+ 'decimal' => $di->lazyGet('validator.post.decimal'),
+ 'geometry' => $di->lazyGet('validator.post.geometry'),
+ 'int' => $di->lazyGet('validator.post.int'),
+ 'link' => $di->lazyGet('validator.post.link'),
+ 'point' => $di->lazyGet('validator.post.point'),
+ 'relation' => $di->lazyGet('validator.post.relation'),
+ 'varchar' => $di->lazyGet('validator.post.varchar'),
+ 'markdown' => $di->lazyGet('validator.post.markdown'),
+ 'title' => $di->lazyGet('validator.post.title'),
+ 'media' => $di->lazyGet('validator.post.media'),
+ 'video' => $di->lazyGet('validator.post.video'),
+ ],
+ ];
+
+$di->params[Ushahidi\App\Validator\Post\Relation::class] = [
+ 'repo' => $di->lazyGet('repository.post')
+ ];
+
+$di->set('transformer.mapping', $di->lazyNew(Ushahidi\App\Transformer\MappingTransformer::class));
+$di->set('transformer.csv', $di->lazyNew(Ushahidi\App\Transformer\CSVPostTransformer::class));
+// Post repo for mapping transformer
+$di->setter[Ushahidi\App\Transformer\CSVPostTransformer::class]['setRepo'] =
+ $di->lazyGet('repository.post');
+
+$di->set('tool.mailer', $di->lazyNew('Ushahidi_Mailer'));
+
+// Event listener for the Set repo
+$di->setter[Ushahidi\App\Repository\SetRepository::class]['setEvent'] = 'PostSetEvent';
+
+$di->setter[Ushahidi\App\Repository\SetRepository::class]['setListener'] =
+ $di->lazyNew(Ushahidi\App\Listener\PostSetListener::class);
+
+// NotificationQueue repo for Set listener
+$di->setter[Ushahidi\App\Listener\PostSetListener::class]['setRepo'] =
+ $di->lazyGet('repository.notification.queue');
+
+// Event listener for the Post repo
+$di->setter[Ushahidi\App\Repository\PostRepository::class]['setEvent'] = 'PostCreateEvent';
+$di->setter[Ushahidi\App\Repository\PostRepository::class]['setListener'] =
+ $di->lazyNew(Ushahidi\App\Listener\PostListener::class);
+
+// WebhookJob repo for Post listener
+$di->setter[Ushahidi\App\Listener\PostListener::class]['setRepo'] =
+ $di->lazyGet('repository.webhook.job');
+
+// Webhook repo for Post listener
+$di->setter[Ushahidi\App\Listener\PostListener::class]['setWebhookRepo'] =
+ $di->lazyGet('repository.webhook');
+
+// Add Intercom Listener to Config
+$di->setter[Ushahidi\App\Repository\ConfigRepository::class]['setEvent'] = 'ConfigUpdateEvent';
+$di->setter[Ushahidi\App\Repository\ConfigRepository::class]['setListener'] =
+ $di->lazyNew(Ushahidi\App\Listener\IntercomListener::class);
+
+// Add Intercom Listener to Form
+$di->setter[Ushahidi\App\Repository\FormRepository::class]['setEvent'] = 'FormUpdateEvent';
+$di->setter[Ushahidi\App\Repository\FormRepository::class]['setListener'] =
+ $di->lazyNew(Ushahidi\App\Listener\IntercomListener::class);
+
+// Add Intercom Listener to User
+$di->setter[Ushahidi\App\Repository\UserRepository::class]['setEvent'] = 'UserGetAllEvent';
+$di->setter[Ushahidi\App\Repository\UserRepository::class]['setListener'] =
+ $di->lazyNew(Ushahidi\App\Listener\IntercomListener::class);
diff --git a/application/classes/Ushahidi/Listener/IntercomListener.php b/src/App/Listener/IntercomListener.php
similarity index 70%
rename from application/classes/Ushahidi/Listener/IntercomListener.php
rename to src/App/Listener/IntercomListener.php
index 08a62acf1f..634e7fbcf4 100644
--- a/application/classes/Ushahidi/Listener/IntercomListener.php
+++ b/src/App/Listener/IntercomListener.php
@@ -1,4 +1,4 @@
-users->update([
"email" => $user_email,
"custom_attributes" => $data
]);
- } catch(ClientException $e) {
- Kohana::$log->add(Log::ERROR, print_r($e,true));
+ } catch (ClientException $e) {
+ \Kohana::$log->add(Log::ERROR, print_r($e, true));
}
- }
- }
+ }
+ }
}
diff --git a/application/classes/Ushahidi/Listener/PostListener.php b/src/App/Listener/PostListener.php
similarity index 80%
rename from application/classes/Ushahidi/Listener/PostListener.php
rename to src/App/Listener/PostListener.php
index a5fed2c54f..15378d7682 100644
--- a/application/classes/Ushahidi/Listener/PostListener.php
+++ b/src/App/Listener/PostListener.php
@@ -1,4 +1,4 @@
-webhook_repo = $webhook_repo;
}
- public function handle(EventInterface $event, $post_id = null, $event_type = null)
- {
+ public function handle(EventInterface $event, $post_id = null, $event_type = null)
+ {
$state = [
'post_id' => $post_id,
'event_type' => $event_type
@@ -43,5 +45,5 @@ public function handle(EventInterface $event, $post_id = null, $event_type = nul
$entity = $this->repo->getEntity();
$entity->setState($state);
$this->repo->create($entity);
- }
+ }
}
diff --git a/application/classes/Ushahidi/Listener/PostSetListener.php b/src/App/Listener/PostSetListener.php
similarity index 77%
rename from application/classes/Ushahidi/Listener/PostSetListener.php
rename to src/App/Listener/PostSetListener.php
index 2552c7db7e..6d506c8e41 100644
--- a/application/classes/Ushahidi/Listener/PostSetListener.php
+++ b/src/App/Listener/PostSetListener.php
@@ -1,4 +1,4 @@
-repo = $repo;
}
- public function handle(EventInterface $event, $set_id = null, $post_id = null)
- {
+ public function handle(EventInterface $event, $set_id = null, $post_id = null)
+ {
// Insert into Notification Queue
$state = [
'set' => $set_id,
@@ -36,5 +38,5 @@ public function handle(EventInterface $event, $set_id = null, $post_id = null)
$entity = $this->repo->getEntity();
$entity->setState($state);
$this->repo->create($entity);
- }
+ }
}
diff --git a/application/classes/Ushahidi/Repository/CSV.php b/src/App/Repository/CSVRepository.php
similarity index 76%
rename from application/classes/Ushahidi/Repository/CSV.php
rename to src/App/Repository/CSVRepository.php
index d7bf610f9d..7b2b32d472 100644
--- a/application/classes/Ushahidi/Repository/CSV.php
+++ b/src/App/Repository/CSVRepository.php
@@ -1,4 +1,4 @@
-setState($state));
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
return new CSV($data);
}
@@ -71,5 +73,4 @@ public function getSearchFields()
{
return ['columns', 'maps_to', 'fixed', 'filename'];
}
-
}
diff --git a/application/classes/Ushahidi/Repository/Config.php b/src/App/Repository/ConfigRepository.php
similarity index 82%
rename from application/classes/Ushahidi/Repository/Config.php
rename to src/App/Repository/ConfigRepository.php
index 500998efb8..c31fafa317 100644
--- a/application/classes/Ushahidi/Repository/Config.php
+++ b/src/App/Repository/ConfigRepository.php
@@ -1,5 +1,4 @@
-getImmutable();
foreach ($entity->getChanged() as $key => $val) {
-
// Emit Intercom Update events
if ($key === 'description') {
$intercom_data['has_description'] = true;
@@ -83,11 +83,13 @@ public function update(Entity $entity)
}
if (! in_array($key, $immutable)) {
+ // Below is to reset the twitter-since_id when the search-terms are updated.
+ // This should be revised when the data-source tech-debt is addressed
- /* Below is to reset the twitter-since_id when the search-terms are updated. This should be revised when the data-source tech-debt is addressed*/
-
- if($key === 'twitter' && isset($config['twitter']) && $val['twitter_search_terms'] !== $config['twitter']['twitter_search_terms'])
- {
+ if ($key === 'twitter' &&
+ isset($config['twitter']) &&
+ $val['twitter_search_terms'] !== $config['twitter']['twitter_search_terms']
+ ) {
$twitter_config = \Kohana::$config->load('twitter');
$twitter_config->set('since_id', 0);
}
@@ -132,7 +134,7 @@ protected function verifyGroup($group)
* @throws InvalidArgumentException when any group is invalid
* @return void
*/
- protected function verifyGroups(Array $groups)
+ protected function verifyGroups(array $groups)
{
$invalid = array_diff(array_values($groups), $this->groups());
if ($invalid) {
@@ -143,7 +145,7 @@ protected function verifyGroups(Array $groups)
}
// ConfigRepository
- public function all(Array $groups = null)
+ public function all(array $groups = null)
{
if ($groups) {
$this->verifyGroups($groups);
@@ -160,4 +162,3 @@ public function all(Array $groups = null)
return $result;
}
}
-
diff --git a/application/classes/Ushahidi/Repository/Contact.php b/src/App/Repository/ContactRepository.php
similarity index 84%
rename from application/classes/Ushahidi/Repository/Contact.php
rename to src/App/Repository/ContactRepository.php
index aa760d5dde..634b8fd6f0 100644
--- a/application/classes/Ushahidi/Repository/Contact.php
+++ b/src/App/Repository/ContactRepository.php
@@ -1,4 +1,4 @@
-get('id', 0);
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'contacts';
@@ -42,7 +47,7 @@ protected function getTable()
// CreateRepository
// ReadRepository
- public function getEntity(Array $data = null)
+ public function getEntity(array $data = null)
{
return new Contact($data);
}
@@ -55,7 +60,7 @@ public function getSearchFields()
];
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
@@ -70,10 +75,8 @@ protected function setSearchConditions(SearchData $search)
foreach ([
'user',
- ] as $fk)
- {
- if ($search->$fk)
- {
+ ] as $fk) {
+ if ($search->$fk) {
$query->where("contacts.{$fk}_id", '=', $search->$fk);
}
}
@@ -82,10 +85,8 @@ protected function setSearchConditions(SearchData $search)
'type',
'data_provider',
'contact'
- ] as $key)
- {
- if ($search->$key)
- {
+ ] as $key) {
+ if ($search->$key) {
$query->where("contacts.{$key}", '=', $search->$key);
}
}
@@ -129,8 +130,8 @@ public function getByContact($contact, $type)
// ContactRepository
public function getNotificationContacts($set_id, $limit = false, $offset = 0)
{
- $query = DB::select('contacts.id', 'contacts.type', 'contacts.contact')
- ->distinct(TRUE)
+ $query = \DB::select('contacts.id', 'contacts.type', 'contacts.contact')
+ ->distinct(true)
->from('contacts')
->join('notifications')
->on('contacts.user_id', '=', 'notifications.user_id')
diff --git a/application/classes/Ushahidi/Repository/Dataprovider.php b/src/App/Repository/DataproviderRepository.php
similarity index 88%
rename from application/classes/Ushahidi/Repository/Dataprovider.php
rename to src/App/Repository/DataproviderRepository.php
index a831c72060..d14cfdf225 100644
--- a/application/classes/Ushahidi/Repository/Dataprovider.php
+++ b/src/App/Repository/DataproviderRepository.php
@@ -1,4 +1,4 @@
-form_stage_repo = $form_stage_repo;
$this->form_repo = $form_repo;
-
}
- // Ushahidi_JsonTranscodeRepository
+ // JsonTranscodeRepository
protected function getJsonProperties()
{
return ['options', 'config'];
@@ -73,7 +77,7 @@ protected function getFormId($form_stage_id)
}
// Override selectQuery to fetch attribute 'key' too
- protected function selectQuery(Array $where = [], $form_id = null, $form_stage_id = null)
+ protected function selectQuery(array $where = [], $form_id = null, $form_stage_id = null)
{
$query = parent::selectQuery($where);
@@ -93,11 +97,11 @@ public function create(Entity $entity)
$uuid = Uuid::uuid4();
$record['key'] = $uuid->toString();
} catch (UnsatisfiedDependencyException $e) {
- Kohana::$log->add(Log::ERROR, $e->getMessage());
+ \Kohana::$log->add(Log::ERROR, $e->getMessage());
}
return $this->executeInsertAttribute($this->removeNullValues($record));
}
-
+
// Override SearchRepository
public function setSearchParams(SearchData $search)
{
@@ -113,7 +117,7 @@ public function setSearchParams(SearchData $search)
if (!empty($sorting['orderby'])) {
$this->search_query->order_by(
$this->getTable() . '.' . $sorting['orderby'],
- Arr::get($sorting, 'order')
+ \Arr::get($sorting, 'order')
);
}
@@ -149,19 +153,19 @@ protected function setSearchConditions(SearchData $search)
}
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'form_attributes';
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
return new FormAttribute($data);
}
- // Ushahidi_Repository
+ // OhanzeeRepository
public function getSearchFields()
{
return ['form_id', 'type', 'label', 'key', 'input'];
@@ -222,7 +226,7 @@ public function getByForm($form_id)
// FormAttributeRepository
public function getRequired($stage_id)
{
- $form_id = $this->getFormId($stage_id);
+ $form_id = $this->getFormId($stage_id);
$query = $this->selectQuery([
'form_attributes.form_stage_id' => $stage_id,
diff --git a/application/classes/Ushahidi/Repository/Form/Role.php b/src/App/Repository/Form/RoleRepository.php
similarity index 76%
rename from application/classes/Ushahidi/Repository/Form/Role.php
rename to src/App/Repository/Form/RoleRepository.php
index b06592509d..0cfae1abf1 100644
--- a/application/classes/Ushahidi/Repository/Form/Role.php
+++ b/src/App/Repository/Form/RoleRepository.php
@@ -1,4 +1,4 @@
-search_query;
@@ -52,7 +56,7 @@ protected function setSearchConditions(SearchData $search)
}
// FormRoleRepository
- public function updateCollection(Array $entities)
+ public function updateCollection(array $entities)
{
if (empty($entities)) {
return;
@@ -62,10 +66,10 @@ public function updateCollection(Array $entities)
// Assuming all entites have the same form id
$this->deleteAllForForm(current($entities)->form_id);
- $query = DB::insert($this->getTable())
+ $query = \DB::insert($this->getTable())
->columns(array_keys(current($entities)->asArray()));
- foreach($entities as $entity) {
+ foreach ($entities as $entity) {
$query->values($entity->asArray());
}
@@ -94,5 +98,4 @@ public function existsInFormRole($role_id, $form_id)
{
return (bool) $this->selectCount(compact('role_id', 'form_id'));
}
-
}
diff --git a/application/classes/Ushahidi/Repository/Form/Stage.php b/src/App/Repository/Form/StageRepository.php
similarity index 80%
rename from application/classes/Ushahidi/Repository/Form/Stage.php
rename to src/App/Repository/Form/StageRepository.php
index 86c0139032..088442b60e 100644
--- a/application/classes/Ushahidi/Repository/Form/Stage.php
+++ b/src/App/Repository/Form/StageRepository.php
@@ -1,4 +1,4 @@
-form_repo = $form_repo;
-
- }
+ $this->form_repo = $form_repo;
+ }
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'form_stages';
}
// Override selectQuery to fetch attribute 'key' too
- protected function selectQuery(Array $where = [], $form_id = null)
+ protected function selectQuery(array $where = [], $form_id = null)
{
$query = parent::selectQuery($where);
@@ -77,7 +81,7 @@ protected function selectQuery(Array $where = [], $form_id = null)
// CreateRepository
// ReadRepository
- public function getEntity(Array $data = null)
+ public function getEntity(array $data = null)
{
return new FormStage($data);
}
@@ -103,7 +107,7 @@ public function setSearchParams(SearchData $search)
if (!empty($sorting['orderby'])) {
$this->search_query->order_by(
$this->getTable() . '.' . $sorting['orderby'],
- Arr::get($sorting, 'order')
+ \Arr::get($sorting, 'order')
);
}
@@ -119,7 +123,7 @@ public function setSearchParams(SearchData $search)
$this->setSearchConditions($search);
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
@@ -136,7 +140,7 @@ protected function setSearchConditions(SearchData $search)
public function getFormByStageId($id)
{
- $query = DB::select('form_id')
+ $query = \DB::select('form_id')
->from('form_stages')
->where('id', '=', $id);
@@ -164,7 +168,7 @@ public function getHiddenStageIds($form_id)
{
$stages = [];
- $query = DB::select('id')
+ $query = \DB::select('id')
->from('form_stages')
->where('form_id', '=', $form_id)
@@ -172,9 +176,9 @@ public function getHiddenStageIds($form_id)
$results = $query->execute($this->db)->as_array();
- foreach($results as $stage) {
- array_push($stages, $stage['id']);
- }
+ foreach ($results as $stage) {
+ array_push($stages, $stage['id']);
+ }
return $stages;
}
diff --git a/application/classes/Ushahidi/Repository/Form.php b/src/App/Repository/FormRepository.php
similarity index 83%
rename from application/classes/Ushahidi/Repository/Form.php
rename to src/App/Repository/FormRepository.php
index c511bc4e5c..0377aa96e0 100644
--- a/application/classes/Ushahidi/Repository/Form.php
+++ b/src/App/Repository/FormRepository.php
@@ -1,4 +1,4 @@
-getRolesThatCanCreatePosts($data['id']);
@@ -51,7 +54,7 @@ public function getSearchFields()
return ['parent', 'q' /* LIKE name */];
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
@@ -86,10 +89,10 @@ public function update(Entity $entity)
// If orignal Form update Intercom if Name changed
if ($entity->id === 1) {
- foreach ($entity->getChanged() as $key => $val) {
- $user = service('session.user');
- $key === 'name' ? $this->emit($this->event, $user->email, ['primary_survey_name' => $val]) : null;
- }
+ foreach ($entity->getChanged() as $key => $val) {
+ $user = service('session.user');
+ $key === 'name' ? $this->emit($this->event, $user->email, ['primary_survey_name' => $val]) : null;
+ }
}
$tags = $entity->tags;
@@ -109,7 +112,7 @@ public function update(Entity $entity)
* @param Array $where
* @return int
*/
- public function getTotalCount(Array $where = [])
+ public function getTotalCount(array $where = [])
{
return $this->selectCount($where);
}
@@ -122,7 +125,7 @@ public function getTotalCount(Array $where = [])
*/
public function isAuthorHidden($form_id)
{
- $query = DB::select('hide_author')
+ $query = \DB::select('hide_author')
->from('forms')
->where('id', '=', $form_id);
@@ -138,8 +141,8 @@ public function isAuthorHidden($form_id)
*/
public function getRolesThatCanCreatePosts($form_id)
{
- $query = DB::select('forms.everyone_can_create', 'roles.name')
- ->distinct(TRUE)
+ $query = \DB::select('forms.everyone_can_create', 'roles.name')
+ ->distinct(true)
->from('forms')
->join('form_roles', 'LEFT')
->on('forms.id', '=', 'form_roles.form_id')
diff --git a/application/classes/Ushahidi/FormsTagsTrait.php b/src/App/Repository/FormsTagsTrait.php
similarity index 78%
rename from application/classes/Ushahidi/FormsTagsTrait.php
rename to src/App/Repository/FormsTagsTrait.php
index 20fdbc5272..20adb7f11b 100644
--- a/application/classes/Ushahidi/FormsTagsTrait.php
+++ b/src/App/Repository/FormsTagsTrait.php
@@ -1,6 +1,6 @@
-
@@ -9,43 +9,45 @@
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
-trait Ushahidi_FormsTagsTrait
+namespace Ushahidi\App\Repository;
+
+trait FormsTagsTrait
{
//returning forms for a specific Tag-id
private function getFormsForTag($id)
{
- $result = DB::select('form_id')
+ $result = \DB::select('form_id')
->from('forms_tags')
->where('tag_id', '=', $id)
->execute($this->db);
- return $result->as_array(NULL, 'form_id');
+ return $result->as_array(null, 'form_id');
}
//returning tags for a specific Form-id
private function getTagsForForm($id)
{
- $result = DB::select('tag_id')
+ $result = \DB::select('tag_id')
->from('forms_tags')
->where('form_id', '=', $id)
->execute($this->db);
- return $result->as_array(NULL, 'tag_id');
+ return $result->as_array(null, 'tag_id');
}
-
+
// updating/adding tags to a form
private function updateFormsTags($form_id, $tags)
{
if (!$tags) {
- DB::delete('forms_tags')
+ \DB::delete('forms_tags')
->where('form_id', '=', $form_id)
->execute($this->db);
- } else if ($tags) {
+ } elseif ($tags) {
$existing = $this->getTagsForForm($form_id);
- $insert = DB::insert('forms_tags', ['form_id', 'tag_id']);
+ $insert = \DB::insert('forms_tags', ['form_id', 'tag_id']);
$tag_ids = [];
- $new_tags = FALSE;
+ $new_tags = false;
foreach ($tags as $tag) {
if (!in_array($tag, $existing)) {
$insert->values([$form_id, $tag]);
- $new_tags = TRUE;
+ $new_tags = true;
}
$tag_ids[] = $tag;
}
@@ -53,7 +55,7 @@ private function updateFormsTags($form_id, $tags)
$insert->execute($this->db);
}
if (!empty($tag_ids)) {
- DB::delete('forms_tags')
+ \DB::delete('forms_tags')
->where('tag_id', 'NOT IN', $tag_ids)
->and_where('form_id', '=', $form_id)
->execute($this->db);
@@ -65,14 +67,14 @@ private function updateFormsTags($form_id, $tags)
private function updateTagForms($tag_id, $forms)
{
if (empty($forms)) {
- DB::delete('forms_tags')
+ \DB::delete('forms_tags')
->where('tag_id', '=', $tag_id)
->execute($this->db);
} else {
$existing = $this->getFormsForTag($tag_id);
- $insert = DB::insert('forms_tags', ['form_id', 'tag_id']);
+ $insert = \DB::insert('forms_tags', ['form_id', 'tag_id']);
$form_ids = [];
- $new_forms = FALSE;
+ $new_forms = false;
foreach ($forms as $form) {
if (isset($form['id'])) {
$id = $form['id'];
@@ -81,17 +83,17 @@ private function updateTagForms($tag_id, $forms)
}
if (!in_array($form, $existing)) {
$insert->values([$id, $tag_id]);
- $new_forms = TRUE;
+ $new_forms = true;
}
$form_ids[] = $id;
}
-
+
if ($new_forms) {
$insert->execute($this->db);
}
-
+
if (!empty($form_ids)) {
- DB::delete('forms_tags')
+ \DB::delete('forms_tags')
->where('form_id', 'NOT IN', $form_ids)
->and_where('tag_id', '=', $tag_id)
->execute($this->db);
@@ -101,7 +103,7 @@ private function updateTagForms($tag_id, $forms)
private function updateFormAttributes($id)
{
- $attr = DB::select('id', 'options')
+ $attr = \DB::select('id', 'options')
->from('form_attributes')
->where('input', '=', 'tags')
->execute($this->db)
@@ -112,7 +114,7 @@ private function updateFormAttributes($id)
$index = array_search($id, $value);
array_splice($value, $index, 1);
$value = json_encode($value);
- DB::update('form_attributes')
+ \DB::update('form_attributes')
->set(array('options' => $value))
->where('id', '=', $attr_id)
->execute($this->db);
diff --git a/src/App/Repository/JsonTranscodeRepository.php b/src/App/Repository/JsonTranscodeRepository.php
new file mode 100644
index 0000000000..19a6324644
--- /dev/null
+++ b/src/App/Repository/JsonTranscodeRepository.php
@@ -0,0 +1,72 @@
+
+ * @package Ushahidi\Application\Controllers
+ * @copyright 2013 Ushahidi
+ * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
+ */
+
+namespace Ushahidi\App\Repository;
+
+use Ushahidi\Core\Tool\JsonTranscode;
+
+trait JsonTranscodeRepository
+{
+
+ protected $json_transcoder;
+
+ /**
+ * Return an array of properties to be json encoded
+ * @return Array
+ */
+ abstract protected function getJsonProperties();
+
+ public function setTranscoder(JsonTranscode $transcoder)
+ {
+ $this->json_transcoder = $transcoder;
+ }
+
+ // Temporary override function for attribute addition
+ public function executeInsertAttribute(array $input)
+ {
+ // JSON Encode defined properties
+ $input = $this->json_transcoder->encode(
+ $input,
+ $this->getJsonProperties()
+ );
+
+ return parent::executeInsert($input);
+ }
+
+ // OhanzeeRepository
+ public function executeInsert(array $input)
+ {
+ // JSON Encode defined properties
+ // The use of array_filter causes issues with array items set as 0
+ // the items are removed. This code should ultimately be refactored.
+ $input = array_filter($this->json_transcoder->encode(
+ $input,
+ $this->getJsonProperties()
+ ));
+
+ return parent::executeInsert($input);
+ }
+
+ // OhanzeeRepository
+ public function executeUpdate(array $where, array $input)
+ {
+ // JSON Encode defined properties
+ $input = $this->json_transcoder->encode(
+ $input,
+ $this->getJsonProperties()
+ );
+
+ return parent::executeUpdate($where, $input);
+ }
+}
diff --git a/application/classes/Ushahidi/Repository/Layer.php b/src/App/Repository/LayerRepository.php
similarity index 80%
rename from application/classes/Ushahidi/Repository/Layer.php
rename to src/App/Repository/LayerRepository.php
index a46b7040a4..ee99d326ce 100644
--- a/application/classes/Ushahidi/Repository/Layer.php
+++ b/src/App/Repository/LayerRepository.php
@@ -1,4 +1,4 @@
-search_query;
diff --git a/application/classes/Ushahidi/Repository/Media.php b/src/App/Repository/MediaRepository.php
similarity index 71%
rename from application/classes/Ushahidi/Repository/Media.php
rename to src/App/Repository/MediaRepository.php
index d7e8ecf5a2..c206814066 100644
--- a/application/classes/Ushahidi/Repository/Media.php
+++ b/src/App/Repository/MediaRepository.php
@@ -1,4 +1,4 @@
-upload = $upload;
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'media';
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
return new Media($data);
}
@@ -51,7 +53,7 @@ public function getSearchFields()
return ['user', 'orphans'];
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
if ($search->user) {
@@ -62,7 +64,7 @@ protected function setSearchConditions(SearchData $search)
$this->search_query
->join('posts_media', 'left')
->on('posts_media.media_id', '=', 'media.id')
- ->where('posts_media.post_id', 'is', NULL);
+ ->where('posts_media.post_id', 'is', null);
}
}
}
diff --git a/application/classes/Ushahidi/Repository/Message.php b/src/App/Repository/MessageRepository.php
similarity index 81%
rename from application/classes/Ushahidi/Repository/Message.php
rename to src/App/Repository/MessageRepository.php
index e6dad04627..8aa6c2b8fe 100644
--- a/application/classes/Ushahidi/Repository/Message.php
+++ b/src/App/Repository/MessageRepository.php
@@ -1,4 +1,4 @@
-search_query
->join('contacts')
->on('contact_id', '=', 'contacts.id');
- if ($search->box === 'outbox')
- {
+ if ($search->box === 'outbox') {
// Outbox only shows outgoing messages
$query->where('direction', '=', 'outgoing');
- }
- elseif ($search->box === 'inbox')
- {
+ } elseif ($search->box === 'inbox') {
// Inbox only shows incoming messages
$query->where('direction', '=', 'incoming');
}
@@ -75,26 +74,20 @@ protected function setSearchConditions(SearchData $search)
// Get the requested status, which is secondary to box
$status = $search->status;
- if ($search->box === 'archived')
- {
+ if ($search->box === 'archived') {
// Archive only shows archived messages
$query->where('status', '=', 'archived');
- }
- else if ($status)
- {
+ } elseif ($status) {
if ($status !== 'all') {
// Search for a specific status
$query->where('status', '=', $status);
}
- }
- else
- {
+ } else {
// Other boxes do not display archived
$query->where('status', '!=', 'archived');
}
- if ($search->q)
- {
+ if ($search->q) {
$query->and_where_open();
$query->where('contacts.contact', 'LIKE', "%$search->q%");
$query->or_where('title', 'LIKE', "%$search->q%");
@@ -106,10 +99,8 @@ protected function setSearchConditions(SearchData $search)
'contact',
'parent',
'post',
- ] as $fk)
- {
- if ($search->$fk)
- {
+ ] as $fk) {
+ if ($search->$fk) {
$query->where("messages.{$fk}_id", '=', $search->$fk);
}
}
@@ -117,10 +108,8 @@ protected function setSearchConditions(SearchData $search)
foreach ([
'type',
'data_provider',
- ] as $key)
- {
- if ($search->$key)
- {
+ ] as $key) {
+ if ($search->$key) {
$query->where("messages.{$key}", '=', $search->$key);
}
}
@@ -170,14 +159,11 @@ public function update(Entity $entity)
// UpdateMessageRepository
public function checkStatus($status, $direction)
{
- if ($direction === \Message_Direction::INCOMING)
- {
-
+ if ($direction === \Message_Direction::INCOMING) {
return ($status == \Message_Status::RECEIVED);
}
- if ($direction === \Message_Direction::OUTGOING)
- {
+ if ($direction === \Message_Direction::OUTGOING) {
// Outgoing messages can only be: pending, cancelled, failed, unknown, sent
return in_array($status, [
\Message_Status::PENDING,
@@ -192,7 +178,7 @@ public function checkStatus($status, $direction)
public function getLastUID($data_provider_type)
{
$last_uid = null;
- $query = DB::select([DB::expr('ABS(' . $this->getTable() . '.' . 'data_provider_message_id' . ')'), 'uid'])
+ $query = \DB::select([\DB::expr('ABS(' . $this->getTable() . '.' . 'data_provider_message_id' . ')'), 'uid'])
->from($this->getTable())
->where('data_provider', '=', $data_provider_type)
->order_by(
@@ -220,6 +206,8 @@ public function parentExists($parent_id)
//MessageRepository
public function notificationMessageExists($post_id, $contact_id)
{
- return $this->selectCount(['notification_post_id' => $post_id, 'contact_id' => $contact_id, 'direction' => 'outgoing']) > 0;
+ return $this->selectCount(
+ ['notification_post_id' => $post_id, 'contact_id' => $contact_id, 'direction' => 'outgoing']
+ ) > 0;
}
}
diff --git a/application/classes/Ushahidi/Repository/Notification/Queue.php b/src/App/Repository/Notification/QueueRepository.php
similarity index 75%
rename from application/classes/Ushahidi/Repository/Notification/Queue.php
rename to src/App/Repository/Notification/QueueRepository.php
index 474664aea2..86098c3e71 100644
--- a/application/classes/Ushahidi/Repository/Notification/Queue.php
+++ b/src/App/Repository/Notification/QueueRepository.php
@@ -1,4 +1,4 @@
-search_query;
-
+
foreach ([
'post',
'set',
- ] as $fk)
- {
- if ($search->$fk)
- {
+ ] as $fk) {
+ if ($search->$fk) {
$query->where("notification_queue.{$fk}_id", '=', $search->$fk);
}
}
}
- public function getEntity(Array $data = null)
+ public function getEntity(array $data = null)
{
return new NotificationQueue($data);
}
diff --git a/application/classes/Ushahidi/Repository/Notification.php b/src/App/Repository/NotificationRepository.php
similarity index 83%
rename from application/classes/Ushahidi/Repository/Notification.php
rename to src/App/Repository/NotificationRepository.php
index c0d26ec47f..c554db471a 100644
--- a/application/classes/Ushahidi/Repository/Notification.php
+++ b/src/App/Repository/NotificationRepository.php
@@ -1,4 +1,4 @@
-search_query;
@@ -51,16 +53,14 @@ public function setSearchConditions(SearchData $search)
foreach ([
'user',
'set',
- ] as $fk)
- {
- if ($search->$fk)
- {
+ ] as $fk) {
+ if ($search->$fk) {
$query->where("notifications.{$fk}_id", '=', $search->$fk);
}
}
}
- public function getEntity(Array $data = null)
+ public function getEntity(array $data = null)
{
return new Notification($data);
}
diff --git a/application/classes/Ushahidi/Repository.php b/src/App/Repository/OhanzeeRepository.php
similarity index 89%
rename from application/classes/Ushahidi/Repository.php
rename to src/App/Repository/OhanzeeRepository.php
index 04646d3fdc..97ba2f5ee7 100644
--- a/application/classes/Ushahidi/Repository.php
+++ b/src/App/Repository/OhanzeeRepository.php
@@ -1,4 +1,4 @@
-search_query->order_by(
$this->getTable() . '.' . $sorting['orderby'],
- Arr::get($sorting, 'order')
+ \Arr::get($sorting, 'order')
);
}
@@ -118,7 +122,7 @@ public function getSearchResults()
{
$query = $this->getSearchQuery();
- $results = $query->distinct(TRUE)->execute($this->db);
+ $results = $query->distinct(true)->execute($this->db);
return $this->getCollection($results->as_array());
}
@@ -144,7 +148,7 @@ public function getSearchTotal()
* @param Array $data
* @return Array
*/
- protected function removeNullValues(Array $data)
+ protected function removeNullValues(array $data)
{
return array_filter($data, function ($val) {
return isset($val);
@@ -183,7 +187,7 @@ protected function getSearchQuery($countable = false)
* @param Array $where hash of conditions
* @return Array
*/
- protected function selectOne(Array $where = [])
+ protected function selectOne(array $where = [])
{
$result = $this->selectQuery($where)
->limit(1)
@@ -196,7 +200,7 @@ protected function selectOne(Array $where = [])
* @param Array $where hash of conditions
* @return Integer
*/
- protected function selectCount(Array $where = [])
+ protected function selectCount(array $where = [])
{
$result = $this->selectQuery($where)
->resetSelect()
@@ -210,11 +214,10 @@ protected function selectCount(Array $where = [])
* @param Array $where optional hash of conditions
* @return Database_Query_Builder_Select
*/
- protected function selectQuery(Array $where = [])
+ protected function selectQuery(array $where = [])
{
$query = DB::select($this->getTable() . '.*')->from($this->getTable());
- foreach ($where as $column => $value)
- {
+ foreach ($where as $column => $value) {
$predicate = is_array($value) ? 'IN' : '=';
$query->where($column, $predicate, $value);
}
@@ -226,7 +229,7 @@ protected function selectQuery(Array $where = [])
* @param Array $input hash of input
* @return Integer
*/
- protected function executeInsert(Array $input)
+ protected function executeInsert(array $input)
{
if (!$input) {
throw new RuntimeException(sprintf(
@@ -250,7 +253,7 @@ protected function executeInsert(Array $input)
* @param Array $input hash of input
* @return Integer
*/
- protected function executeUpdate(Array $where, Array $input)
+ protected function executeUpdate(array $where, array $input)
{
if (!$where) {
throw new RuntimeException(sprintf(
@@ -261,7 +264,7 @@ protected function executeUpdate(Array $where, Array $input)
// Prevent overwriting created timestamp
// Probably not needed if `created` is set immutable in Entity
- if(array_key_exists('created', $input)){
+ if (array_key_exists('created', $input)) {
unset($input['created']);
}
@@ -270,8 +273,7 @@ protected function executeUpdate(Array $where, Array $input)
}
$query = DB::update($this->getTable())->set($input);
- foreach ($where as $column => $value)
- {
+ foreach ($where as $column => $value) {
$query->where($column, '=', $value);
}
@@ -284,7 +286,7 @@ protected function executeUpdate(Array $where, Array $input)
* @param Array $where hash of conditions
* @return Integer
*/
- protected function executeDelete(Array $where)
+ protected function executeDelete(array $where)
{
if (!$where) {
throw new RuntimeException(sprintf(
@@ -294,8 +296,7 @@ protected function executeDelete(Array $where)
}
$query = DB::delete($this->getTable());
- foreach ($where as $column => $value)
- {
+ foreach ($where as $column => $value) {
$query->where($column, '=', $value);
}
diff --git a/application/classes/Ushahidi/Repository/Permission.php b/src/App/Repository/PermissionRepository.php
similarity index 72%
rename from application/classes/Ushahidi/Repository/Permission.php
rename to src/App/Repository/PermissionRepository.php
index 7758df6311..3fcb7c24c1 100644
--- a/application/classes/Ushahidi/Repository/Permission.php
+++ b/src/App/Repository/PermissionRepository.php
@@ -1,4 +1,4 @@
-search_query;
- if ($search->q)
- {
+ if ($search->q) {
$query->where('name', 'LIKE', "%" .$search->q ."%");
}
@@ -51,5 +52,4 @@ public function exists($permission)
{
return (bool) $this->selectCount(['name' => $permission]);
}
-
}
diff --git a/application/classes/Ushahidi/Repository/Post/Datetime.php b/src/App/Repository/Post/DatetimeRepository.php
similarity index 74%
rename from application/classes/Ushahidi/Repository/Post/Datetime.php
rename to src/App/Repository/Post/DatetimeRepository.php
index 95046266b4..1350fe3c06 100644
--- a/application/classes/Ushahidi/Repository/Post/Datetime.php
+++ b/src/App/Repository/Post/DatetimeRepository.php
@@ -1,4 +1,4 @@
-
+ * @package Ushahidi\Application
+ * @copyright 2014 Ushahidi
+ * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
+ */
+
+namespace Ushahidi\App\Repository\Post;
+
+use Ushahidi\Core\Entity\PostValue;
+use Ushahidi\Core\Entity\PostValueRepository as PostValueRepositoryContract;
+
+class DescriptionRepository extends TextRepository
+{
+ public function getAllForPost(
+ $post_id,
+ array $include_attributes = [],
+ array $exclude_stages = [],
+ $restricted = false
+ ) {
+ 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;
+ }
+}
diff --git a/src/App/Repository/Post/ExportRepository.php b/src/App/Repository/Post/ExportRepository.php
new file mode 100644
index 0000000000..4b16d0f60a
--- /dev/null
+++ b/src/App/Repository/Post/ExportRepository.php
@@ -0,0 +1,29 @@
+
+ * @package Ushahidi\Application
+ * @copyright 2016 Ushahidi
+ * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
+ */
+
+namespace Ushahidi\App\Repository\Post;
+
+use Ushahidi\Core\Entity\Post;
+use Ushahidi\Core\Entity\PostRepository as PostRepositoryContract;
+use Ushahidi\App\Repository\PostRepository;
+
+class ExportRepository extends PostRepository
+{
+ public function getFormAttributes($values)
+ {
+ $attributes = [];
+ foreach ($values as $key => $val) {
+ $attribute = $this->form_attribute_repo->getByKey($key);
+ $attributes[$key] = $attribute->label;
+ }
+ return $attributes;
+ }
+}
diff --git a/application/classes/Ushahidi/Repository/Post/Geometry.php b/src/App/Repository/Post/GeometryRepository.php
similarity index 69%
rename from application/classes/Ushahidi/Repository/Post/Geometry.php
rename to src/App/Repository/Post/GeometryRepository.php
index 13e2d8d099..fef6cc9a67 100644
--- a/application/classes/Ushahidi/Repository/Post/Geometry.php
+++ b/src/App/Repository/Post/GeometryRepository.php
@@ -1,4 +1,4 @@
-select(
$this->getTable().'.*',
// Fetch AsText(value) aliased to value
- [DB::expr('AsText(value)'), 'value']
+ [\DB::expr('AsText(value)'), 'value']
);
return $query;
@@ -38,7 +40,7 @@ protected function selectQuery(Array $where = [])
// Override createValue to save 'value' using GeomFromText
public function createValue($value, $form_attribute_id, $post_id)
{
- $value = DB::expr('GeomFromText(:text)')->param(':text', $value);
+ $value = \DB::expr('GeomFromText(:text)')->param(':text', $value);
return parent::createValue($value, $form_attribute_id, $post_id);
}
@@ -46,9 +48,8 @@ public function createValue($value, $form_attribute_id, $post_id)
// Override updateValue to save 'value' using GeomFromText
public function updateValue($id, $value)
{
- $value = DB::expr('GeomFromText(:text)')->param(':text', $value);
+ $value = \DB::expr('GeomFromText(:text)')->param(':text', $value);
return parent::updateValue($id, $value);
}
-
}
diff --git a/application/classes/Ushahidi/Repository/Post/Int.php b/src/App/Repository/Post/IntRepository.php
similarity index 62%
rename from application/classes/Ushahidi/Repository/Post/Int.php
rename to src/App/Repository/Post/IntRepository.php
index 6dec1712f2..2fa2c3d8ed 100644
--- a/application/classes/Ushahidi/Repository/Post/Int.php
+++ b/src/App/Repository/Post/IntRepository.php
@@ -1,4 +1,4 @@
-db = $db;
$this->decoder = $decoder;
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'post_point';
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
- try
- {
+ try {
$geometry = $this->decoder->geomFromText($data['value']);
- if ($geometry instanceof Point)
- {
+ if ($geometry instanceof Point) {
$data['value'] = ['lon' => $geometry->lon, 'lat' => $geometry->lat];
}
- }
- catch (InvalidText $e)
- {
+ } catch (InvalidText $e) {
$data['value'] = ['lon' => null, 'lat' => null];
}
@@ -51,7 +49,7 @@ public function getEntity(Array $data = null)
}
// Override selectQuery to fetch 'value' from db as text
- protected function selectQuery(Array $where = [])
+ protected function selectQuery(array $where = [])
{
$query = parent::selectQuery($where);
@@ -59,7 +57,7 @@ protected function selectQuery(Array $where = [])
$query->select(
$this->getTable().'.*',
// Fetch AsText(value) aliased to value
- [DB::expr('AsText(value)'), 'value']
+ [\DB::expr('AsText(value)'), 'value']
);
return $query;
@@ -67,14 +65,11 @@ protected function selectQuery(Array $where = [])
private function normalizeValue($value)
{
- if (is_array($value))
- {
+ if (is_array($value)) {
$value = array_map('floatval', $value);
- $value = DB::expr("GeomFromText('POINT(lon lat)')")->parameters($value);
- }
- else
- {
- $value = NULL;
+ $value = \DB::expr("GeomFromText('POINT(lon lat)')")->parameters($value);
+ } else {
+ $value = null;
}
return $value;
@@ -91,5 +86,4 @@ public function updateValue($id, $value)
{
return parent::updateValue($id, $this->normalizeValue($value));
}
-
}
diff --git a/application/classes/Ushahidi/Repository/Post/Relation.php b/src/App/Repository/Post/RelationRepository.php
similarity index 67%
rename from application/classes/Ushahidi/Repository/Post/Relation.php
rename to src/App/Repository/Post/RelationRepository.php
index eca915fdcd..d85fdfb766 100644
--- a/application/classes/Ushahidi/Repository/Post/Relation.php
+++ b/src/App/Repository/Post/RelationRepository.php
@@ -1,4 +1,4 @@
-
+ * @package Ushahidi\Application
+ * @copyright 2014 Ushahidi
+ * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
+ */
+
+namespace Ushahidi\App\Repository\Post;
+
+use Ushahidi\Core\Entity\PostValue;
+use Ushahidi\Core\Entity\PostValueRepository as PostValueRepositoryContract;
+
+class TitleRepository extends VarcharRepository
+{
+ public function getAllForPost(
+ $post_id,
+ array $include_attributes = [],
+ array $exclude_stages = [],
+ $restricted = false
+ ) {
+ return [];
+ }
+ public function createValue($value, $form_attribute_id, $post_id)
+ {
+ return 0;
+ }
+
+ public function updateValue($id, $value)
+ {
+ return 0;
+ }
+}
diff --git a/application/classes/Ushahidi/Repository/Post/ValueFactory.php b/src/App/Repository/Post/ValueFactory.php
similarity index 71%
rename from application/classes/Ushahidi/Repository/Post/ValueFactory.php
rename to src/App/Repository/Post/ValueFactory.php
index d344f60243..cb761e3ea5 100644
--- a/application/classes/Ushahidi/Repository/Post/ValueFactory.php
+++ b/src/App/Repository/Post/ValueFactory.php
@@ -1,4 +1,4 @@
-map);
}
- public function proxy(Array $include_types = [])
+ public function proxy(array $include_types = [])
{
- return new Ushahidi_Repository_Post_ValueProxy($this, $include_types);
+ return new ValueProxy($this, $include_types);
}
- public function each($callback, Array $include_types = [])
+ public function each($callback, array $include_types = [])
{
$map = $this->map;
- if ($include_types)
- {
- $map = array_intersect_key($this->map, array_fill_keys($include_types, TRUE));
+ if ($include_types) {
+ $map = array_intersect_key($this->map, array_fill_keys($include_types, true));
}
- foreach ($map as $type => $class)
- {
+ foreach ($map as $type => $class) {
$repo = $this->getRepo($type);
$callback($repo);
}
diff --git a/application/classes/Ushahidi/Repository/Post/ValueProxy.php b/src/App/Repository/Post/ValueProxy.php
similarity index 54%
rename from application/classes/Ushahidi/Repository/Post/ValueProxy.php
rename to src/App/Repository/Post/ValueProxy.php
index b564a70ca6..3272fe8c83 100644
--- a/application/classes/Ushahidi/Repository/Post/ValueProxy.php
+++ b/src/App/Repository/Post/ValueProxy.php
@@ -1,4 +1,4 @@
-factory = $factory;
$this->include_types = $include_types;
}
// ValuesForPostRepository
- public function getAllForPost($post_id, Array $include_attributes = [], Array $exclude_stages = [], $restricted = false)
- {
+ public function getAllForPost(
+ $post_id,
+ array $include_attributes = [],
+ array $exclude_stages = [],
+ $restricted = false
+ ) {
$results = [];
- $this->factory->each(function ($repo) use ($post_id, $include_attributes, &$results, $exclude_stages, $restricted) {
- $results = array_merge($results, $repo->getAllForPost($post_id, $include_attributes, $exclude_stages, $restricted));
- }, $this->include_types);
+ $this->factory->each(
+ function ($repo) use ($post_id, $include_attributes, &$results, $exclude_stages, $restricted) {
+ $results = array_merge(
+ $results,
+ $repo->getAllForPost($post_id, $include_attributes, $exclude_stages, $restricted)
+ );
+ },
+ $this->include_types
+ );
return $results;
}
diff --git a/application/classes/Ushahidi/Repository/Post/Value.php b/src/App/Repository/Post/ValueRepository.php
similarity index 79%
rename from application/classes/Ushahidi/Repository/Post/Value.php
rename to src/App/Repository/Post/ValueRepository.php
index b0e31bfacf..4707f78681 100644
--- a/application/classes/Ushahidi/Repository/Post/Value.php
+++ b/src/App/Repository/Post/ValueRepository.php
@@ -1,4 +1,4 @@
-selectQuery(compact('post_id'));
if ($include_attributes) {
@@ -108,19 +115,17 @@ public function createValue($value, $form_attribute_id, $post_id)
public function updateValue($id, $value)
{
$update = compact('value');
- if ($id && $update)
- {
+ if ($id && $update) {
$this->executeUpdate(compact('id'), $update);
}
}
// UpdatePostValueRepository
- public function deleteNotIn($post_id, Array $ids)
+ public function deleteNotIn($post_id, array $ids)
{
- DB::delete($this->getTable())
+ \DB::delete($this->getTable())
->where('post_id', '=', $post_id)
->where('id', 'NOT IN', $ids)
->execute($this->db);
}
-
}
diff --git a/application/classes/Ushahidi/Repository/Post/Varchar.php b/src/App/Repository/Post/VarcharRepository.php
similarity index 64%
rename from application/classes/Ushahidi/Repository/Post/Varchar.php
rename to src/App/Repository/Post/VarcharRepository.php
index b38828867c..4a4258ff8c 100644
--- a/application/classes/Ushahidi/Repository/Post/Varchar.php
+++ b/src/App/Repository/Post/VarcharRepository.php
@@ -1,4 +1,4 @@
-form_attribute_repo = $form_attribute_repo;
@@ -105,31 +109,27 @@ public function __construct(
$this->tag_repo = $tag_repo;
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'posts';
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
// Ensure we are dealing with a structured Post
$user = $this->getUser();
- if ($data['form_id'])
- {
-
+ if ($data['form_id']) {
if ($this->canUserReadPostsValues(new Post($data), $user, $this->form_repo)) {
$this->restricted = false;
}
// Get Hidden Stage Ids to be excluded from results
$this->exclude_stages = $this->form_stage_repo->getHiddenStageIds($data['form_id']);
-
}
- if (!empty($data['id']))
- {
+ if (!empty($data['id'])) {
$data += [
'values' => $this->getPostValues($data['id']),
'tags' => $this->getTagsForPost($data['id']),
@@ -140,12 +140,8 @@ public function getEntity(Array $data = null)
// NOTE: This and the restriction above belong somewhere else,
// ideally in their own step
//Check if author information should be returned
- if ($data['author_realname'] || $data['user_id'] || $data['author_email'])
- {
-
-
- if (!$this->canUserSeeAuthor(new Post($data), $this->form_repo, $user))
- {
+ if ($data['author_realname'] || $data['user_id'] || $data['author_email']) {
+ if (!$this->canUserSeeAuthor(new Post($data), $this->form_repo, $user)) {
unset($data['author_realname']);
unset($data['author_email']);
unset($data['user_id']);
@@ -155,14 +151,14 @@ public function getEntity(Array $data = null)
return new Post($data);
}
- // Ushahidi_JsonTranscodeRepository
+ // JsonTranscodeRepository
protected function getJsonProperties()
{
return ['published_to'];
}
// Override selectQuery to fetch 'value' from db as text
- protected function selectQuery(Array $where = [])
+ protected function selectQuery(array $where = [])
{
$query = parent::selectQuery($where);
@@ -190,7 +186,7 @@ protected function getPostValues($id)
if (empty($output[$value->key])) {
$output[$value->key] = [];
}
- if ($value->value !== NULL) {
+ if ($value->value !== null) {
$output[$value->key][] = $value->value;
}
}
@@ -212,10 +208,10 @@ protected function getCompletedStagesForPost($id)
$result = $query->execute($this->db);
- return $result->as_array(NULL, 'form_stage_id');
+ return $result->as_array(null, 'form_stage_id');
}
- // Ushahidi_Repository
+ // OhanzeeRepository
public function getSearchFields()
{
return [
@@ -235,29 +231,21 @@ public function getSearchFields()
];
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
- if ($search->include_types)
- {
- if (is_array($search->include_types))
- {
+ if ($search->include_types) {
+ if (is_array($search->include_types)) {
$this->include_value_types = $search->include_types;
- }
- else
- {
+ } else {
$this->include_value_types = explode(',', $search->include_types);
}
}
- if ($search->include_attributes)
- {
- if (is_array($search->include_attributes))
- {
+ if ($search->include_attributes) {
+ if (is_array($search->include_attributes)) {
$this->include_attributes = $search->include_attributes;
- }
- else
- {
+ } else {
$this->include_attributes = explode(',', $search->include_attributes);
}
}
@@ -277,24 +265,19 @@ protected function setSearchConditions(SearchData $search)
}
// End filter by status
- foreach (['type', 'locale', 'slug'] as $key)
- {
- if ($search->$key)
- {
+ foreach (['type', 'locale', 'slug'] as $key) {
+ if ($search->$key) {
$query->where("$table.$key", '=', $search->$key);
}
}
// If user = me, replace with current user id
- if ($search->user === 'me')
- {
+ if ($search->user === 'me') {
$search->user = $this->getUserId();
}
- foreach (['user', 'parent', 'form'] as $key)
- {
- if (!empty($search->$key))
- {
+ foreach (['user', 'parent', 'form'] as $key) {
+ if (!empty($search->$key)) {
// Make sure we have an array
if (!is_array($search->$key)) {
$search->$key = explode(',', $search->$key);
@@ -303,7 +286,7 @@ protected function setSearchConditions(SearchData $search)
// Special case: 'none' looks for null
if (in_array('none', $search->$key)) {
$query->and_where_open()
- ->where("$table.{$key}_id", 'IS', NULL)
+ ->where("$table.{$key}_id", 'IS', null)
->or_where("$table.{$key}_id", 'IN', $search->$key)
->and_where_close();
} else {
@@ -312,8 +295,7 @@ protected function setSearchConditions(SearchData $search)
}
}
- if ($search->q)
- {
+ if ($search->q) {
// search terms are all wrapped as a series of OR conditions
$query->and_where_open();
@@ -331,47 +313,40 @@ protected function setSearchConditions(SearchData $search)
}
- if ($search->id)
- {
+ if ($search->id) {
//searching for specific post id, used for single post in set searches
$query->where('id', '=', $search->id);
}
// date chcks
- if ($search->created_after)
- {
+ if ($search->created_after) {
$created_after = strtotime($search->created_after);
$query->where("$table.created", '>=', $created_after);
}
- if ($search->created_before)
- {
+ if ($search->created_before) {
$created_before = strtotime($search->created_before);
$query->where("$table.created", '<=', $created_before);
}
- if ($search->updated_after)
- {
+ if ($search->updated_after) {
$updated_after = strtotime($search->updated_after);
$query->where("$table.updated", '>=', $updated_after);
}
- if ($search->updated_before)
- {
+ if ($search->updated_before) {
$updated_before = strtotime($search->updated_before);
$query->where("$table.updated", '<=', $updated_before);
}
- if ($search->date_after)
- {
+ if ($search->date_after) {
$date_after = date_create($search->date_after, new DateTimeZone('UTC'));
// Convert to UTC (needed in case date came with a tz)
$date_after->setTimezone(new DateTimeZone('UTC'));
$query->where("$table.post_date", '>=', $date_after->format('Y-m-d H:i:s'));
}
- if ($search->date_before)
- {
+ if ($search->date_before) {
$date_before = date_create($search->date_before, new DateTimeZone('UTC'));
// Convert to UTC (needed in case date came with a tz)
$date_before->setTimezone(new DateTimeZone('UTC'));
@@ -383,7 +358,7 @@ protected function setSearchConditions(SearchData $search)
$bounding_box = null;
if ($search->bbox) {
$bounding_box = $this->createBoundingBoxFromCSV($search->bbox);
- } else if ($search->center_point && $search->within_km) {
+ } elseif ($search->center_point && $search->within_km) {
$bounding_box = $this->createBoundingBoxFromCenter(
$search->center_point, $search->within_km
);
@@ -405,22 +380,25 @@ protected function setSearchConditions(SearchData $search)
;
}
- $raw_union = '(select post_geometry.post_id from post_geometry union select post_point.post_id from post_point)';
- if($search->has_location === 'mapped') {
+ $raw_union = '(
+ select post_geometry.post_id from post_geometry
+ union
+ select post_point.post_id from post_point
+ )';
+
+ if ($search->has_location === 'mapped') {
$query->where("$table.id", 'IN',
DB::query(Database::SELECT, $raw_union)
);
- } else if($search->has_location === 'unmapped') {
+ } elseif ($search->has_location === 'unmapped') {
$query->where("$table.id", 'NOT IN',
DB::query(Database::SELECT, $raw_union)
);
}
// Filter by tag
- if (!empty($search->tags))
- {
- if (isset($search->tags['any']))
- {
+ if (!empty($search->tags)) {
+ if (isset($search->tags['any'])) {
$tags = $search->tags['any'];
if (!is_array($tags)) {
$tags = explode(',', $tags);
@@ -429,16 +407,13 @@ protected function setSearchConditions(SearchData $search)
$query
->join('posts_tags')->on('posts.id', '=', 'posts_tags.post_id')
->where('tag_id', 'IN', $tags);
- }
- elseif (isset($search->tags['all']))
- {
+ } elseif (isset($search->tags['all'])) {
$tags = $search->tags['all'];
if (!is_array($tags)) {
$tags = explode(',', $tags);
}
- foreach ($tags as $tag)
- {
+ foreach ($tags as $tag) {
$sub = DB::select('post_id')
->from('posts_tags')
->where('tag_id', '=', $tag);
@@ -446,9 +421,7 @@ protected function setSearchConditions(SearchData $search)
$query
->where('posts.id', 'IN', $sub);
}
- }
- else
- {
+ } else {
$tags = $search->tags;
if (!is_array($tags)) {
$tags = explode(',', $tags);
@@ -461,8 +434,7 @@ protected function setSearchConditions(SearchData $search)
}
// Filter by set
- if (!empty($search->set))
- {
+ if (!empty($search->set)) {
$set = $search->set;
if (!is_array($set)) {
$set = explode(',', $set);
@@ -474,10 +446,8 @@ protected function setSearchConditions(SearchData $search)
}
// Attributes
- if ($search->values)
- {
- foreach ($search->values as $key => $value)
- {
+ if ($search->values) {
+ foreach ($search->values as $key => $value) {
$attribute = $this->form_attribute_repo->getByKey($key);
$sub = $this->post_value_factory
@@ -530,12 +500,13 @@ public function getUnmappedTotal($total_posts)
{
$mapped = 0;
- $raw_sql = "select count(distinct post_id) as 'total' from (select post_geometry.post_id from post_geometry union select post_point.post_id from post_point) as sub;";
+ $raw_sql = "select count(distinct post_id) as 'total' from (select post_geometry.post_id from post_geometry
+ union
+ select post_point.post_id from post_point) as sub;";
if ($total_posts > 0) {
-
$results = DB::query(Database::SELECT, $raw_sql)->execute();
- foreach($results->as_array() as $result) {
+ foreach ($results->as_array() as $result) {
$mapped = array_key_exists('total', $result) ? (int) $result['total'] : 0;
}
}
@@ -568,23 +539,18 @@ public function getGroupedTotals(SearchData $search)
$this->setSearchConditions($search);
// Group by time-intervals
- if ($search->timeline)
- {
+ if ($search->timeline) {
// Default to posts created
$time_field = 'posts.created';
- if ($search->timeline_attribute === 'created' || $search->timeline_attribute == 'updated')
- {
+ if ($search->timeline_attribute === 'created' || $search->timeline_attribute == 'updated') {
// Assumed created / updated means the builtin posts created/updated times
$time_field = 'posts.' . $search->timeline_attribute;
- }
- elseif ($search->timeline_attribute)
- {
+ } elseif ($search->timeline_attribute) {
// Find the attribute
$key = $search->timeline_attribute;
$attribute = $this->form_attribute_repo->getByKey($key);
- if ($attribute)
- {
+ if ($attribute) {
// Get the post_TYPE table.
$sub = $this->post_value_factory
->getRepo($attribute->type)
@@ -603,21 +569,21 @@ public function getGroupedTotals(SearchData $search)
$this->search_query
->select([
- DB::expr('FLOOR('.$time_field.'/:interval)*:interval', [':interval' => (int)$search->getFilter('timeline_interval', 86400)]),
+ DB::expr(
+ 'FLOOR('.$time_field.'/:interval)*:interval',
+ [':interval' => (int)$search->getFilter('timeline_interval', 86400)]
+ ),
'time_label'
])
->group_by('time_label');
-
}
// Group by attribute
- if ($search->group_by === 'attribute' AND $search->group_by_attribute_key)
- {
+ if ($search->group_by === 'attribute' and $search->group_by_attribute_key) {
$key = $search->group_by_attribute_key;
$attribute = $this->form_attribute_repo->getByKey($key);
- if ($attribute)
- {
+ if ($attribute) {
$sub = $this->post_value_factory
->getRepo($attribute->type)
->getValueTable();
@@ -629,27 +595,21 @@ public function getGroupedTotals(SearchData $search)
->select(['Group_'.ucfirst($key).'.value', 'label'])
->group_by('label');
}
- }
- // Group by status
- elseif ($search->group_by === 'status')
- {
+ } // Group by status
+ elseif ($search->group_by === 'status') {
$this->search_query
->select(['posts.status', 'label'])
->group_by('label');
- }
- // Group by form
- elseif ($search->group_by === 'form')
- {
+ } // Group by form
+ elseif ($search->group_by === 'form') {
$this->search_query
->join('forms', 'LEFT')->on('posts.form_id', '=', 'forms.id')
// This should really use ANY_VALUE(forms.name) but that only exists in mysql5.7
->select([DB::expr('MAX(forms.name)'), 'label'])
->select(['forms.id', 'id'])
->group_by('forms.id');
- }
- // Group by tags
- elseif ($search->group_by === 'tags')
- {
+ } // Group by tags
+ elseif ($search->group_by === 'tags') {
/**
* The output query looks something like
* SELECT
@@ -658,7 +618,8 @@ public function getGroupedTotals(SearchData $search)
* FROM `posts`
* JOIN `posts_tags` ON (`posts`.`id` = `posts_tags`.`post_id`)
* JOIN `tags` ON (`posts_tags`.`tag_id` = `tags`.`id`)
- * JOIN `tags` as `parents` ON (`parents`.`id` = `tags`.`parent_id` OR `parents`.`id` = `posts_tags`.`tag_id`)
+ * JOIN `tags` as `parents`
+ * ON (`parents`.`id` = `tags`.`parent_id` OR `parents`.`id` = `posts_tags`.`tag_id`)
* WHERE `status` = 'published' AND `posts`.`type` = 'report'
* AND `parents`.`parent_id` IS NULL
* GROUP BY `parents`.`id`
@@ -670,7 +631,11 @@ public function getGroupedTotals(SearchData $search)
->join('tags')->on('posts_tags.tag_id', '=', 'tags.id')
->join(['tags', 'parents'])
// Slight hack to avoid kohana db forcing multiple ON clauses to use AND not OR.
- ->on(DB::expr("`parents`.`id` = `tags`.`parent_id` OR `parents`.`id` = `posts_tags`.`tag_id`"), '', DB::expr(""))
+ ->on(
+ DB::expr("`parents`.`id` = `tags`.`parent_id` OR `parents`.`id` = `posts_tags`.`tag_id`"),
+ '',
+ DB::expr("")
+ )
// This should really use ANY_VALUE(forms.name) but that only exists in mysql5.7
->select([DB::expr('MAX(parents.tag)'), 'label'])
->select(['parents.id', 'id'])
@@ -686,26 +651,23 @@ public function getGroupedTotals(SearchData $search)
// @todo try to ensure parent_id is always NULL and migrate 0 -> NULL
$this->search_query
->and_where_open()
- ->where('parents.parent_id', 'IS', NULL)
+ ->where('parents.parent_id', 'IS', null)
->or_where('parents.parent_id', '=', 0)
->and_where_close();
}
}
- }
- // If no group_by just count all posts
+ } // If no group_by just count all posts
else {
$this->search_query
->select([DB::expr('"all"'), 'label']);
}
// .. Add orderby time *after* order by groups
- if ($search->timeline)
- {
+ if ($search->timeline) {
// Order by label, then time
$this->search_query->order_by('label');
$this->search_query->order_by('time_label');
- }
- else {
+ } else {
// Order by count, then label
$this->search_query->order_by('total', 'DESC');
$this->search_query->order_by('label');
@@ -746,7 +708,7 @@ public function getByLocale($locale, $parent_id, $type)
* Return a Bounding Box given a CSV of west,north,east,south points
*
* @param string $csv 'west,north,east,south'
- * @return Util_BoundingBox
+ * @return BoundingBox
*/
private function createBoundingBoxFromCSV($csv)
{
@@ -783,7 +745,7 @@ private function createBoundingBoxFromCenter($center, $within_km = 0)
* @param string $bbox Bounding box
* @return Database_Query
*/
- private function getBoundingBoxSubquery(Util_BoundingBox $bounding_box)
+ private function getBoundingBoxSubquery(BoundingBox $bounding_box)
{
return DB::select('post_id')
->from('post_point')
@@ -807,7 +769,7 @@ private function getTagsForPost($id)
$result = DB::select('tag_id')->from('posts_tags')
->where('post_id', '=', $id)
->execute($this->db);
- return $result->as_array(NULL, 'tag_id');
+ return $result->as_array(null, 'tag_id');
}
/**
@@ -820,7 +782,7 @@ private function getSetsForPost($id)
$result = DB::select('set_id')->from('posts_sets')
->where('post_id', '=', $id)
->execute($this->db);
- return $result->as_array(NULL, 'set_id');
+ return $result->as_array(null, 'set_id');
}
// UpdatePostRepository
@@ -834,16 +796,14 @@ public function isSlugAvailable($slug)
public function doesTranslationExist($locale, $parent_id, $type)
{
// If this isn't a translation of an existing post, skip
- if ($type != 'translation')
- {
- return TRUE;
+ if ($type != 'translation') {
+ return true;
}
// Is locale the same as parent?
$parent = $this->get($parent_id);
- if ($parent->locale === $locale)
- {
- return FALSE;
+ if ($parent->locale === $locale) {
+ return false;
}
// Check for other translations
@@ -862,33 +822,37 @@ public function create(Entity $entity)
$post['created'] = time();
// Remove attribute values and tags
- unset($post['values'], $post['tags'], $post['completed_stages'], $post['sets'], $post['source'], $post['color']);
+ unset(
+ $post['values'],
+ $post['tags'],
+ $post['completed_stages'],
+ $post['sets'],
+ $post['source'],
+ $post['color']
+ );
// Set default value for post_date
if (empty($post['post_date'])) {
$post['post_date'] = date_create()->format("Y-m-d H:i:s");
// Convert post_date to mysql format
- } else {
+ } else {
$post['post_date'] = $post['post_date']->format("Y-m-d H:i:s");
}
// Create the post
$id = $this->executeInsert($this->removeNullValues($post));
- if ($entity->tags)
- {
+ if ($entity->tags) {
// Update post-tags
$this->updatePostTags($id, $entity->tags);
}
- if ($entity->values)
- {
+ if ($entity->values) {
// Update post-values
$this->updatePostValues($id, $entity->values);
}
- if ($entity->completed_stages)
- {
+ if ($entity->completed_stages) {
// Update post-stages
$this->updatePostStages($id, $entity->form_id, $entity->completed_stages);
}
@@ -908,29 +872,33 @@ public function update(Entity $entity)
$post['updated'] = time();
// Remove attribute values and tags
- unset($post['values'], $post['tags'], $post['completed_stages'], $post['sets'], $post['source'], $post['color']);
+ unset(
+ $post['values'],
+ $post['tags'],
+ $post['completed_stages'],
+ $post['sets'],
+ $post['source'],
+ $post['color']
+ );
// Convert post_date to mysql format
- if(!empty($post['post_date'])) {
+ if (!empty($post['post_date'])) {
$post['post_date'] = $post['post_date']->format("Y-m-d H:i:s");
}
$count = $this->executeUpdate(['id' => $entity->id], $post);
- if ($entity->hasChanged('tags'))
- {
+ if ($entity->hasChanged('tags')) {
// Update post-tags
$this->updatePostTags($entity->id, $entity->tags);
}
- if ($entity->hasChanged('values'))
- {
+ if ($entity->hasChanged('values')) {
// Update post-values
$this->updatePostValues($entity->id, $entity->values);
}
- if ($entity->hasChanged('completed_stages'))
- {
+ if ($entity->hasChanged('completed_stages')) {
// Update post-stages
$this->updatePostStages($entity->id, $entity->form_id, $entity->completed_stages);
}
@@ -942,8 +910,7 @@ protected function updatePostValues($post_id, $attributes)
{
$this->post_value_factory->proxy()->deleteAllForPost($post_id);
- foreach ($attributes as $key => $values)
- {
+ foreach ($attributes as $key => $values) {
$attribute = $this->form_attribute_repo->getByKey($key);
if (!$attribute->id) {
continue;
@@ -951,8 +918,7 @@ protected function updatePostValues($post_id, $attributes)
$repo = $this->post_value_factory->getRepo($attribute->type);
- foreach ($values as $val)
- {
+ foreach ($values as $val) {
$repo->createValue($val, $attribute->id, $post_id);
}
}
@@ -961,24 +927,20 @@ protected function updatePostValues($post_id, $attributes)
protected function updatePostTags($post_id, $tags)
{
// deletes all tags if $tags is empty
- if (empty($tags))
- {
+ if (empty($tags)) {
DB::delete('posts_tags')
->where('post_id', '=', $post_id)
->execute($this->db);
- }
- else
- {
+ } else {
// Load existing tags
$existing = $this->getTagsForPost($post_id);
$insert = DB::insert('posts_tags', ['post_id', 'tag_id']);
$tag_ids = [];
- $new_tags = FALSE;
+ $new_tags = false;
- foreach ($tags as $tag)
- {
+ foreach ($tags as $tag) {
if (is_array($tag)) {
$tag = $tag['id'];
}
@@ -986,31 +948,27 @@ protected function updatePostTags($post_id, $tags)
// Find the tag by id or name
// @todo this should happen before we even get here
$tag_entity = $this->tag_repo->getByTag($tag);
- if (! $tag_entity->id)
- {
+ if (! $tag_entity->id) {
$tag_entity = $this->tag_repo->get($tag);
}
// Does the post already have this tag?
- if (! in_array($tag_entity->id, $existing))
- {
+ if (! in_array($tag_entity->id, $existing)) {
// Add to insert query
$insert->values([$post_id, $tag_entity->id]);
- $new_tags = TRUE;
+ $new_tags = true;
}
$tag_ids[] = $tag_entity->id;
}
// Save
- if ($new_tags)
- {
+ if ($new_tags) {
$insert->execute($this->db);
}
// Remove any other tags
- if (! empty($tag_ids))
- {
+ if (! empty($tag_ids)) {
DB::delete('posts_tags')
->where('tag_id', 'NOT IN', $tag_ids)
->and_where('post_id', '=', $post_id)
@@ -1022,8 +980,7 @@ protected function updatePostTags($post_id, $tags)
protected function updatePostStages($post_id, $form_id, $completed_stages)
{
- if (! is_array($completed_stages))
- {
+ if (! is_array($completed_stages)) {
$completed_stages = [];
}
@@ -1035,8 +992,7 @@ protected function updatePostStages($post_id, $form_id, $completed_stages)
$insert = DB::insert('form_stages_posts', ['form_stage_id', 'post_id', 'completed']);
// Get all stages for form
$form_stages = $this->form_stage_repo->getByForm($form_id);
- foreach ($form_stages as $stage)
- {
+ foreach ($form_stages as $stage) {
$insert->values([
$stage->id,
$post_id,
@@ -1064,8 +1020,7 @@ public function getPostInSet($post_id, $set_id)
// PostRepository
public function doesPostRequireApproval($formId)
{
- if ($formId)
- {
+ if ($formId) {
$form = $this->form_repo->get($formId);
return $form->require_approval;
}
diff --git a/application/classes/Ushahidi/Repository/Role.php b/src/App/Repository/RoleRepository.php
similarity index 77%
rename from application/classes/Ushahidi/Repository/Role.php
rename to src/App/Repository/RoleRepository.php
index 130382987b..cf8f5c7f6f 100644
--- a/application/classes/Ushahidi/Repository/Role.php
+++ b/src/App/Repository/RoleRepository.php
@@ -1,4 +1,4 @@
-from('roles_permissions')
+ return \DB::select('permission')->from('roles_permissions')
->where('role', '=', $role)
->execute($this->db)
- ->as_array(NULL, 'permission');
+ ->as_array(null, 'permission');
}
protected function updatePermissions($role, $permissions)
{
$current_permissions = $this->getPermissions($role);
- $insert_query = DB::insert('roles_permissions', ['role', 'permission']);
+ $insert_query = \DB::insert('roles_permissions', ['role', 'permission']);
$new_permissions = array_diff($permissions, $current_permissions);
- foreach($new_permissions as $permission)
- {
+ foreach ($new_permissions as $permission) {
$insert_query->values([$role, $permission]);
}
@@ -52,18 +53,17 @@ protected function updatePermissions($role, $permissions)
$discarded_permissions = array_diff($current_permissions, $permissions);
if ($discarded_permissions) {
- DB::delete('roles_permissions')
+ \DB::delete('roles_permissions')
->where('permission', 'IN', $discarded_permissions)
->where('role', '=', $role)
->execute($this->db);
}
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
- if (!empty($data['id']))
- {
+ if (!empty($data['id'])) {
$data += [
'permissions' => $this->getPermissions($data['name'])
];
@@ -82,10 +82,9 @@ public function getSearchFields()
}
// RoleRepository
- public function doRolesExist(Array $roles = null)
+ public function doRolesExist(array $roles = null)
{
- if (!$roles)
- {
+ if (!$roles) {
// 0 === 0, all day every day
return true;
}
@@ -141,8 +140,7 @@ public function setSearchConditions(SearchData $search)
$query->where('name', '=', $search->name);
}
- if ($search->q)
- {
+ if ($search->q) {
$query->where('name', 'LIKE', "%" .$search->q. "%");
}
@@ -150,19 +148,23 @@ public function setSearchConditions(SearchData $search)
}
- // Ushahidi_Repository
+ // OhanzeeRepository
public function exists($role = '')
{
- if (!$role) { return false; }
+ if (!$role) {
+ return false;
+ }
return (bool) $this->selectCount(['name' => $role]);
}
-
- // Ushahidi_Repository
+
+ // OhanzeeRepository
public function idExists($role_id = null)
{
- if (!$role_id) { return false; }
+ if (!$role_id) {
+ return false;
+ }
return (bool) $this->selectCount(['id' => $role_id]);
- }
+ }
// RoleRepository
public function getByName($name)
diff --git a/application/classes/Ushahidi/Repository/Set.php b/src/App/Repository/SetRepository.php
similarity index 85%
rename from application/classes/Ushahidi/Repository/Set.php
rename to src/App/Repository/SetRepository.php
index bec990ad58..152b5e104a 100644
--- a/application/classes/Ushahidi/Repository/Set.php
+++ b/src/App/Repository/SetRepository.php
@@ -1,4 +1,4 @@
-savedSearch = $savedSearch;
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function getTable()
{
return 'sets';
}
- // Ushahidi_Repository
- public function getEntity(Array $data = null)
+ // OhanzeeRepository
+ public function getEntity(array $data = null)
{
return $this->savedSearch ? new SavedSearch($data) : new Set($data);
}
- // Ushahidi_JsonTranscodeRepository
+ // JsonTranscodeRepository
protected function getJsonProperties()
{
return ['filter', 'view_options', 'role'];
@@ -59,7 +61,7 @@ protected function getJsonProperties()
/**
* Override selectQuery to enforce filtering by search=0/1
*/
- protected function selectQuery(Array $where = [])
+ protected function selectQuery(array $where = [])
{
$query = parent::selectQuery($where);
@@ -74,7 +76,8 @@ protected function selectQuery(Array $where = [])
*/
// CreateRepository
- public function create(Entity $entity) {
+ public function create(Entity $entity)
+ {
// Get record and filter empty values
$record = array_filter($entity->asArray());
@@ -86,7 +89,6 @@ public function create(Entity $entity) {
// Finally, save the record to the DB
return $this->executeInsert($this->removeNullValues($record));
-
}
// UpdateRepository
@@ -141,7 +143,7 @@ public function setSearchParams(SearchData $search)
if (!empty($sorting['orderby'])) {
$this->search_query->order_by(
$this->getTable() . '.' . $sorting['orderby'],
- Arr::get($sorting, 'order')
+ \Arr::get($sorting, 'order')
);
}
@@ -157,33 +159,28 @@ public function setSearchParams(SearchData $search)
$this->setSearchConditions($search);
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
$sets_query = $this->search_query;
- if ($search->q)
- {
+ if ($search->q) {
$sets_query->where('name', 'LIKE', "%{$search->q}%");
}
- if ($search->featured !== null)
- {
+ if ($search->featured !== null) {
$sets_query->where('featured', '=', (int)$search->featured);
}
- if ($search->user_id)
- {
+ if ($search->user_id) {
$sets_query->where('user_id', '=', $search->user_id);
}
- if (isset($search->search))
- {
+ if (isset($search->search)) {
$sets_query->where('search', '=', (int)$search->search);
}
- if ($search->id)
- {
+ if ($search->id) {
$sets_query->where('id', '=', $search->id);
}
}
@@ -191,7 +188,7 @@ protected function setSearchConditions(SearchData $search)
// SetRepository
public function deleteSetPost($set_id, $post_id)
{
- DB::delete('posts_sets')
+ \DB::delete('posts_sets')
->where('post_id', '=', $post_id)
->where('set_id', '=', $set_id)
->execute($this->db);
@@ -200,7 +197,7 @@ public function deleteSetPost($set_id, $post_id)
// SetRepository
public function setPostExists($set_id, $post_id)
{
- $result = DB::select('posts_sets.*')
+ $result = \DB::select('posts_sets.*')
->from('posts_sets')
->where('post_id', '=', $post_id)
->where('set_id', '=', $set_id)
@@ -218,7 +215,7 @@ public function addPostToSet($set_id, $post_id)
$post_id = (int)$post_id;
$set_id = (int)$set_id;
- DB::insert('posts_sets')
+ \DB::insert('posts_sets')
->columns(['post_id', 'set_id'])
->values(array_values(compact('post_id', 'set_id')))
->execute($this->db);
diff --git a/application/classes/Ushahidi/Repository/Tag.php b/src/App/Repository/TagRepository.php
similarity index 77%
rename from application/classes/Ushahidi/Repository/Tag.php
rename to src/App/Repository/TagRepository.php
index 76421eb19e..f105bcd3c6 100644
--- a/application/classes/Ushahidi/Repository/Tag.php
+++ b/src/App/Repository/TagRepository.php
@@ -1,4 +1,4 @@
-getFormsForTag($data['id']);
- if(empty($data['parent_id'])) {
-
- $data['children'] =
- DB::select('id')
- ->from('tags')
- ->where('parent_id','=',$data['id'])
- ->execute($this->db)
- ->as_array();
+ if (empty($data['parent_id'])) {
+ $data['children'] =
+ \DB::select('id')
+ ->from('tags')
+ ->where('parent_id', '=', $data['id'])
+ ->execute($this->db)
+ ->as_array();
+ }
}
- }
return new Tag($data);
}
- // Ushahidi_JsonTranscodeRepository
+ // JsonTranscodeRepository
protected function getJsonProperties()
{
return ['role'];
@@ -69,12 +69,11 @@ public function getSearchFields()
return ['tag', 'type', 'parent_id', 'q', 'level', 'formId' /* LIKE tag */];
}
- // Ushahidi_Repository
+ // OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
- foreach (['tag', 'type', 'parent_id'] as $key)
- {
+ foreach (['tag', 'type', 'parent_id'] as $key) {
if ($search->$key) {
$query->where($key, '=', $search->$key);
}
@@ -83,16 +82,16 @@ protected function setSearchConditions(SearchData $search)
// Tag text searching
$query->where('tag', 'LIKE', "%{$search->q}%");
}
- if($search->level) {
+ if ($search->level) {
//searching for top-level-tags
- if($search->level === 'parent') {
+ if ($search->level === 'parent') {
$query->where('parent_id', '=', null);
}
}
- if($search->formId){
+ if ($search->formId) {
$query->join('forms_tags')
->on('tags.id', '=', 'forms_tags.tag_id')
- ->where('form_id','=', $search->formId);
+ ->where('form_id', '=', $search->formId);
}
}
@@ -100,7 +99,7 @@ protected function setSearchConditions(SearchData $search)
public function getSearchResults()
{
$query = $this->getSearchQuery();
- $results = $query->distinct(TRUE)->execute($this->db);
+ $results = $query->distinct(true)->execute($this->db);
return $this->getCollection($results->as_array());
}
@@ -114,7 +113,7 @@ public function create(Entity $entity)
$id = $this->executeInsert($this->removeNullValues($record));
- if($entity->forms) {
+ if ($entity->forms) {
//updating forms_tags-table
$this->updateTagForms($id, $entity->forms);
}
@@ -129,8 +128,7 @@ public function update(Entity $entity)
$count = $this->executeUpdate(['id' => $entity->id], $tag);
// updating forms_tags-table
- if($entity->hasChanged('forms'))
- {
+ if ($entity->hasChanged('forms')) {
$this->updateTagForms($entity->id, $entity->forms);
}
@@ -149,7 +147,7 @@ public function doesTagExist($tag_or_id)
{
$query = $this->selectQuery()
->resetSelect()
- ->select([DB::expr('COUNT(*)'), 'total'])
+ ->select([\DB::expr('COUNT(*)'), 'total'])
->where('id', '=', $tag_or_id)
->or_where('tag', '=', $tag_or_id)
->execute($this->db);
diff --git a/application/classes/Ushahidi/Repository/User.php b/src/App/Repository/UserRepository.php
similarity index 83%
rename from application/classes/Ushahidi/Repository/User.php
rename to src/App/Repository/UserRepository.php
index a8e77c2e10..129ea027f5 100644
--- a/application/classes/Ushahidi/Repository/User.php
+++ b/src/App/Repository/UserRepository.php
@@ -1,4 +1,4 @@
-search_query;
- if ($search->q)
- {
+ if ($search->q) {
$query->and_where_open();
$query->where('email', 'LIKE', "%" . $search->q . "%");
$query->or_where('realname', 'LIKE', "%" . $search->q . "%");
@@ -112,8 +113,7 @@ public function setSearchConditions(SearchData $search)
if ($search->role) {
$role = $search->role;
- if (!is_array($search->role))
- {
+ if (!is_array($search->role)) {
$role = explode(',', $search->role);
}
@@ -150,10 +150,11 @@ public function register(Entity $entity)
}
// ResetPasswordRepository
- public function getResetToken(Entity $entity) {
+ public function getResetToken(Entity $entity)
+ {
// Todo: replace with something more robust.
// This is predictable if we don't have the openssl mod
- $token = Security::token(TRUE);
+ $token = Security::token(true);
$input = [
'reset_token' => $token,
@@ -162,7 +163,7 @@ public function getResetToken(Entity $entity) {
];
// Save the token
- $query = DB::insert('user_reset_tokens')
+ $query = \DB::insert('user_reset_tokens')
->columns(array_keys($input))
->values(array_values($input))
->execute($this->db);
@@ -171,8 +172,9 @@ public function getResetToken(Entity $entity) {
}
// ResetPasswordRepository
- public function isValidResetToken($token) {
- $result = DB::select([DB::expr('COUNT(*)'), 'total'])
+ public function isValidResetToken($token)
+ {
+ $result = \DB::select([\DB::expr('COUNT(*)'), 'total'])
->from('user_reset_tokens')
->where('reset_token', '=', $token)
->where('created', '>', time() - 1800) // Expire tokens after less than 30 mins
@@ -184,8 +186,9 @@ public function isValidResetToken($token) {
}
// ResetPasswordRepository
- public function setPassword($token, $password) {
- $sub = DB::select('user_id')
+ public function setPassword($token, $password)
+ {
+ $sub = \DB::select('user_id')
->from('user_reset_tokens')
->where('reset_token', '=', $token);
@@ -195,8 +198,9 @@ public function setPassword($token, $password) {
}
// ResetPasswordRepository
- public function deleteResetToken($token) {
- $result = DB::delete('user_reset_tokens')
+ public function deleteResetToken($token)
+ {
+ $result = \DB::delete('user_reset_tokens')
->where('reset_token', '=', $token)
->execute($this->db);
}
@@ -206,13 +210,14 @@ public function deleteResetToken($token) {
* @param Array $where
* @return int
*/
- public function getTotalCount(Array $where = [])
+ public function getTotalCount(array $where = [])
{
return $this->selectCount($where);
}
// DeleteRepository
- public function delete(Entity $entity) {
+ public function delete(Entity $entity)
+ {
$this->updateIntercomUserCount(-1);
return parent::delete($entity);
}
diff --git a/application/classes/Ushahidi/Repository/Webhook/Job.php b/src/App/Repository/Webhook/JobRepository.php
similarity index 76%
rename from application/classes/Ushahidi/Repository/Webhook/Job.php
rename to src/App/Repository/Webhook/JobRepository.php
index 6ad2e7878a..4e3e07cd7f 100644
--- a/application/classes/Ushahidi/Repository/Webhook/Job.php
+++ b/src/App/Repository/Webhook/JobRepository.php
@@ -1,4 +1,4 @@
-search_query;
@@ -29,16 +32,14 @@ public function setSearchConditions(SearchData $search)
foreach ([
'post',
'webhook',
- ] as $fk)
- {
- if ($search->$fk)
- {
+ ] as $fk) {
+ if ($search->$fk) {
$query->where("webhook_job.{$fk}_id", '=', $search->$fk);
}
}
}
- public function getEntity(Array $data = null)
+ public function getEntity(array $data = null)
{
return new WebhookJob($data);
}
diff --git a/application/classes/Ushahidi/Repository/Webhook.php b/src/App/Repository/WebhookRepository.php
similarity index 82%
rename from application/classes/Ushahidi/Repository/Webhook.php
rename to src/App/Repository/WebhookRepository.php
index 58c623012a..e7ede41a7a 100644
--- a/application/classes/Ushahidi/Repository/Webhook.php
+++ b/src/App/Repository/WebhookRepository.php
@@ -1,4 +1,4 @@
-search_query;
@@ -49,21 +51,19 @@ public function setSearchConditions(SearchData $search)
foreach ([
'user'
- ] as $fk)
- {
- if ($search->$fk)
- {
+ ] as $fk) {
+ if ($search->$fk) {
$query->where("webhooks.{$fk}_id", '=', $search->$fk);
}
}
}
- public function getEntity(Array $data = null)
+ public function getEntity(array $data = null)
{
return new Webhook($data);
}
- public function getByEventType($event_type= null)
+ public function getByEventType($event_type = null)
{
return $this->getEntity($this->selectOne(compact('event_type')));
}
diff --git a/application/classes/Ushahidi/Transformer/CSVPostTransformer.php b/src/App/Transformer/CSVPostTransformer.php
similarity index 82%
rename from application/classes/Ushahidi/Transformer/CSVPostTransformer.php
rename to src/App/Transformer/CSVPostTransformer.php
index 57351e7c51..1d42c27d4d 100644
--- a/application/classes/Ushahidi/Transformer/CSVPostTransformer.php
+++ b/src/App/Transformer/CSVPostTransformer.php
@@ -1,4 +1,4 @@
-map = $map;
}
// MappingTransformer
- public function setFixedValues(Array $fixedValues)
+ public function setFixedValues(array $fixedValues)
{
$this->fixedValues = $fixedValues;
}
// Transformer
- public function interact(Array $record)
+ public function interact(array $record)
{
$record = array_values($record);
$columns = $this->map;
// Don't import columns marked as NULL
foreach ($columns as $index => $column) {
- if ($column === NULL) {
+ if ($column === null) {
unset($columns[$index]);
unset($record[$index]);
}
@@ -54,8 +56,7 @@ public function interact(Array $record)
$record = array_combine($columns, $record);
// Trim and remove empty values
- foreach ($record as $key => $val)
- {
+ foreach ($record as $key => $val) {
$record[$key] = trim($val);
if (empty($record[$key])) {
@@ -71,8 +72,7 @@ public function interact(Array $record)
$post_fields = array_intersect_key($record, $post_entity->asArray());
// Remove post fields from the record and leave form values
- foreach ($post_fields as $key => $val)
- {
+ foreach ($post_fields as $key => $val) {
unset($record[$key]);
}
@@ -104,20 +104,17 @@ public function interact(Array $record)
*/
private function mergeMultiValueFields(&$record)
{
- foreach ($record as $column => $val)
- {
+ foreach ($record as $column => $val) {
$keys = explode('.', $column);
// Get column name
$column_name = array_shift($keys);
// Assign sub-key to multi-value column
- if (! empty($keys))
- {
+ if (! empty($keys)) {
unset($record[$column]);
- foreach ($keys as $key)
- {
+ foreach ($keys as $key) {
$record[$column_name][$key] = $val;
}
}
diff --git a/application/classes/Ushahidi/Transformer/MappingTransformer.php b/src/App/Transformer/MappingTransformer.php
similarity index 72%
rename from application/classes/Ushahidi/Transformer/MappingTransformer.php
rename to src/App/Transformer/MappingTransformer.php
index 478ac730ff..bc1dc9730a 100644
--- a/application/classes/Ushahidi/Transformer/MappingTransformer.php
+++ b/src/App/Transformer/MappingTransformer.php
@@ -1,4 +1,4 @@
-map = new MappingStep($map);
}
protected $fixedValues;
// MappingTransformer
- public function setFixedValues(Array $fixedValues)
+ public function setFixedValues(array $fixedValues)
{
$this->fixedValues = $fixedValues;
}
// Tranformer
- public function interact(Array $data)
+ public function interact(array $data)
{
$this->map->process($data);
diff --git a/application/classes/Util/BoundingBox.php b/src/App/Util/BoundingBox.php
similarity index 92%
rename from application/classes/Util/BoundingBox.php
rename to src/App/Util/BoundingBox.php
index 76608e09aa..a653155583 100644
--- a/application/classes/Util/BoundingBox.php
+++ b/src/App/Util/BoundingBox.php
@@ -1,4 +1,5 @@
- $this->north,
@@ -80,7 +86,7 @@ public function expandByKilometers($km = 0)
* @param float $angle bearing in degrees, with 0 being North
* @return Array an array in [, ] format
*/
- protected function newPointByVector($lat ,$lon, $km, $angle)
+ protected function newPointByVector($lat, $lon, $km, $angle)
{
// convert units to radians
$lat = deg2rad($lat);
@@ -90,7 +96,7 @@ protected function newPointByVector($lat ,$lon, $km, $angle)
$earth_radius_km = 6371;
$d = $km / $earth_radius_km;
- $mod = function($y, $x) {
+ $mod = function ($y, $x) {
return $y - $x * floor($y / $x);
};
@@ -100,7 +106,7 @@ protected function newPointByVector($lat ,$lon, $km, $angle)
if (cos($new_lat) === 0) {
$new_lon = $lon; // endpoint a pole
- } else {
+ } else {
$new_lon = $mod(
$lon - asin(sin($true_course) * sin($d) / cos($new_lat)) + M_PI,
2 * M_PI
@@ -108,7 +114,7 @@ protected function newPointByVector($lat ,$lon, $km, $angle)
}
return [rad2deg($new_lat), rad2deg($new_lon)];
- }
+ }
public function toGeometry()
{
@@ -133,7 +139,7 @@ public function toWKT()
));
}
- public function as_array()
+ public function asArray()
{
return array($this->west, $this->north, $this->east, $this->south);
}
diff --git a/application/classes/Util/Tile.php b/src/App/Util/Tile.php
similarity index 91%
rename from application/classes/Util/Tile.php
rename to src/App/Util/Tile.php
index b623e0a3cb..7167d70b5c 100644
--- a/application/classes/Util/Tile.php
+++ b/src/App/Util/Tile.php
@@ -1,4 +1,4 @@
-max_bytes = $max_bytes;
}
-
+
protected function getRules()
{
return [
diff --git a/application/classes/Ushahidi/Validator/CSV/Update.php b/src/App/Validator/CSV/Update.php
similarity index 84%
rename from application/classes/Ushahidi/Validator/CSV/Update.php
rename to src/App/Validator/CSV/Update.php
index 0cb7be33ad..1541722ab8 100644
--- a/application/classes/Ushahidi/Validator/CSV/Update.php
+++ b/src/App/Validator/CSV/Update.php
@@ -1,4 +1,4 @@
-form_repo = $form_repo;
}
-
+
protected function getRules()
{
return [
diff --git a/application/classes/Ushahidi/Validator/Config/Update.php b/src/App/Validator/Config/Update.php
similarity index 92%
rename from application/classes/Ushahidi/Validator/Config/Update.php
rename to src/App/Validator/Config/Update.php
index 6a69566df7..5fd767fd21 100644
--- a/application/classes/Ushahidi/Validator/Config/Update.php
+++ b/src/App/Validator/Config/Update.php
@@ -1,4 +1,4 @@
-validation_engine->getFullData('id');
- switch($config_group) {
+ switch ($config_group) {
case 'site':
$rules = [
'name' => [
@@ -58,7 +60,7 @@ protected function getRules()
['digit', [':value']]
],
'clustering' => [
- ['in_array', [':value', [0, 1, false, true], TRUE]]
+ ['in_array', [':value', [0, 1, false, true], true]]
],
'default_view' => [
['is_array', [':value']]
diff --git a/application/classes/Ushahidi/Validator/Contact/Create.php b/src/App/Validator/Contact/Create.php
similarity index 75%
rename from application/classes/Ushahidi/Validator/Contact/Create.php
rename to src/App/Validator/Contact/Create.php
index 5921cd8da0..e08d3a9a47 100644
--- a/application/classes/Ushahidi/Validator/Contact/Create.php
+++ b/src/App/Validator/Contact/Create.php
@@ -1,4 +1,4 @@
-error('contact', 'invalid_email', [$contact]);
- }
-
- else if ( isset($data['type']) AND
- $data['type'] == Contact::PHONE )
- {
+ } elseif (isset($data['type']) and
+ $data['type'] == Contact::PHONE ) {
// Allow for alphanumeric sender
$number = preg_replace('/[^a-zA-Z0-9 ]/', '', $contact);
- if (strlen($number) == 0)
- {
+ if (strlen($number) == 0) {
$validation->error('contact', 'invalid_phone', [$contact]);
}
}
diff --git a/application/classes/Ushahidi/Validator/Contact/Update.php b/src/App/Validator/Contact/Update.php
similarity index 77%
rename from application/classes/Ushahidi/Validator/Contact/Update.php
rename to src/App/Validator/Contact/Update.php
index 3391516df1..560bfab293 100644
--- a/application/classes/Ushahidi/Validator/Contact/Update.php
+++ b/src/App/Validator/Contact/Update.php
@@ -1,4 +1,4 @@
- [
['max_length', [':value', 255]],
- [[$this, 'valid_contact'], [':value', ':data', ':validation']],
+ [[$this, 'validContact'], [':value', ':data', ':validation']],
]
];
}
@@ -56,26 +58,21 @@ protected function getRules()
* @param [type] [varname] [description]
* @return void
*/
- public function valid_contact($contact, $data, $validation)
+ public function validContact($contact, $data, $validation)
{
// Valid Email?
- if ( isset($data['type']) AND
- $data['type'] == Contact::EMAIL AND
- ! Valid::email($contact) )
- {
+ if (isset($data['type']) and
+ $data['type'] == Contact::EMAIL and
+ ! \Valid::email($contact) ) {
return $validation->error('contact', 'invalid_email', [$contact]);
- }
-
- // Valid Phone?
+ } // Valid Phone?
// @todo Look at using libphonenumber to validate international numbers
- else if ( isset($data['type']) AND
- $data['type'] == Contact::PHONE )
- {
+ elseif (isset($data['type']) and
+ $data['type'] == Contact::PHONE ) {
// Remove all non-digit characters from the number
$number = preg_replace('/\D+/', '', $contact);
- if (strlen($number) == 0)
- {
+ if (strlen($number) == 0) {
$validation->error('contact', 'invalid_phone', [$contact]);
}
}
diff --git a/application/classes/Ushahidi/Validator/Form/Attribute/Create.php b/src/App/Validator/Form/Attribute/Create.php
similarity index 79%
rename from application/classes/Ushahidi/Validator/Form/Attribute/Create.php
rename to src/App/Validator/Form/Attribute/Create.php
index c26e805a22..75f101a6c0 100644
--- a/application/classes/Ushahidi/Validator/Form/Attribute/Create.php
+++ b/src/App/Validator/Form/Attribute/Create.php
@@ -1,4 +1,4 @@
- [
['max_length', [':value', 150]],
- ['alpha_dash', [':value', TRUE]],
+ ['alpha_dash', [':value', true]],
[[$this->repo, 'isKeyAvailable'], [':value']]
],
'label' => [
@@ -95,7 +97,7 @@ protected function getRules()
];
}
- public function formStageBelongsToForm($value)
+ public function formStageBelongsToForm($value)
{
// don't check against nonexistant data
if (!$value || !isset($this->valid['form_id'])) {
diff --git a/application/classes/Ushahidi/Validator/Form/Create.php b/src/App/Validator/Form/Create.php
similarity index 78%
rename from application/classes/Ushahidi/Validator/Form/Create.php
rename to src/App/Validator/Form/Create.php
index 52de48a9aa..276f4640eb 100644
--- a/application/classes/Ushahidi/Validator/Form/Create.php
+++ b/src/App/Validator/Form/Create.php
@@ -1,4 +1,4 @@
- [['not_empty'],
[[$this, 'checkPostTypeLimit'], [':validation']],
- ]]);
+ ]]);
}
}
diff --git a/application/classes/Ushahidi/Validator/Form/Role/Create.php b/src/App/Validator/Form/Role/Create.php
similarity index 70%
rename from application/classes/Ushahidi/Validator/Form/Role/Create.php
rename to src/App/Validator/Form/Role/Create.php
index 783b6f2481..190fa801be 100644
--- a/application/classes/Ushahidi/Validator/Form/Role/Create.php
+++ b/src/App/Validator/Form/Role/Create.php
@@ -1,4 +1,4 @@
-load('features.limits');
- if ($config['forms'] !== TRUE) {
-
+ if ($config['forms'] !== true) {
$total_forms = $this->repo->getTotalCount();
if ($total_forms >= $config['forms']) {
$validation->error('name', 'postTypeLimitReached');
}
- }
- }
+ }
+ }
}
diff --git a/application/classes/Ushahidi/Validator/Layer/Create.php b/src/App/Validator/Layer/Create.php
similarity index 74%
rename from application/classes/Ushahidi/Validator/Layer/Create.php
rename to src/App/Validator/Layer/Create.php
index 2a5209e4da..cd53b51663 100644
--- a/application/classes/Ushahidi/Validator/Layer/Create.php
+++ b/src/App/Validator/Layer/Create.php
@@ -1,4 +1,4 @@
- [
- [function($validation, $data) {
+ [function ($validation, $data) {
// At least 1 of data_url and media_id must be defined..
- if (empty($data['data_url']) AND empty($data['media_id']))
- {
+ if (empty($data['data_url']) and empty($data['media_id'])) {
$validation->error('data_url', 'dataUrlOrMediaRequired');
}
// .. but both can't be defined at the same time
- if (! empty($data['data_url']) AND ! empty($data['media_id']))
- {
+ if (! empty($data['data_url']) and ! empty($data['media_id'])) {
$validation->error('data_url', 'dataUrlMediaConflict');
}
}, [':validation', ':data']]
diff --git a/application/classes/Ushahidi/Validator/Layer/Update.php b/src/App/Validator/Layer/Update.php
similarity index 82%
rename from application/classes/Ushahidi/Validator/Layer/Update.php
rename to src/App/Validator/Layer/Update.php
index 1954eb7c36..da30410837 100644
--- a/application/classes/Ushahidi/Validator/Layer/Update.php
+++ b/src/App/Validator/Layer/Update.php
@@ -1,4 +1,4 @@
- [
- ['in_array', [':value', [0, 1, false, true], TRUE]],
+ ['in_array', [':value', [0, 1, false, true], true]],
],
'visible_by_default' => [
- ['in_array', [':value', [0, 1, false, true], TRUE]],
+ ['in_array', [':value', [0, 1, false, true], true]],
],
'media_id' => [
[[$this->media_repo, 'exists'], [':value']],
diff --git a/application/classes/Ushahidi/Validator/Media/Create.php b/src/App/Validator/Media/Create.php
similarity index 83%
rename from application/classes/Ushahidi/Validator/Media/Create.php
rename to src/App/Validator/Media/Create.php
index 081023d2c2..4d9952cef5 100644
--- a/application/classes/Ushahidi/Validator/Media/Create.php
+++ b/src/App/Validator/Media/Create.php
@@ -1,4 +1,4 @@
- $this->max_bytes)
- {
+ if ($value <= 0 || $value > $this->max_bytes) {
$size_in_mb = ($this->max_bytes / 1024) / 1024;
- $validation->error('o_size','size_error', [$size_in_mb]);
+ $validation->error('o_size', 'size_error', [$size_in_mb]);
}
}
@@ -69,7 +70,7 @@ public function validateMime($validation, $mime)
if (!$mime) {
$validation->error('mime', 'mime_not_empty');
- } else if (!in_array($mime, $allowed_mime_types)) {
+ } elseif (!in_array($mime, $allowed_mime_types)) {
$validation->error('mime', 'mime_type_not_allowed');
}
}
diff --git a/application/classes/Ushahidi/Validator/Media/Delete.php b/src/App/Validator/Media/Delete.php
similarity index 80%
rename from application/classes/Ushahidi/Validator/Media/Delete.php
rename to src/App/Validator/Media/Delete.php
index 8665193c47..283bebebef 100644
--- a/application/classes/Ushahidi/Validator/Media/Delete.php
+++ b/src/App/Validator/Media/Delete.php
@@ -1,4 +1,4 @@
-
+ * @package Ushahidi\Application
+ * @copyright 2014 Ushahidi
+ * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
+ */
+
+namespace Ushahidi\App\Validator\Media;
+
+use Ushahidi\Core\Entity;
+use Ushahidi\Core\Tool\Validator;
+
+class Update extends Create
+{
+ protected function getRules()
+ {
+ return [
+ 'user_id' => [
+ ['digit'],
+ ],
+ 'caption' => [
+ // alphas, numbers, punctuation, and spaces
+ ['regex', [':value', '/^[\pL\pN\pP ]++$/uD']],
+ ]
+ ];
+ }
+}
diff --git a/application/classes/Ushahidi/Validator/Message/Create.php b/src/App/Validator/Message/Create.php
similarity index 93%
rename from application/classes/Ushahidi/Validator/Message/Create.php
rename to src/App/Validator/Message/Create.php
index 66ae3a57b7..ced25c69c0 100644
--- a/application/classes/Ushahidi/Validator/Message/Create.php
+++ b/src/App/Validator/Message/Create.php
@@ -1,4 +1,4 @@
-user_repo = $user_repo;
$this->collection_repo = $collection_repo;
$this->savedsearch_repo = $savedsearch_repo;
diff --git a/application/classes/Ushahidi/Validator/Permission/Create.php b/src/App/Validator/Permission/Create.php
similarity index 72%
rename from application/classes/Ushahidi/Validator/Permission/Create.php
rename to src/App/Validator/Permission/Create.php
index 8291ef0886..172418918b 100644
--- a/application/classes/Ushahidi/Validator/Permission/Create.php
+++ b/src/App/Validator/Permission/Create.php
@@ -1,4 +1,4 @@
-repo = $repo;
$this->attribute_repo = $attribute_repo;
$this->stage_repo = $stage_repo;
@@ -102,12 +107,12 @@ protected function getRules()
'slug' => [
['min_length', [':value', 2]],
['max_length', [':value', 150]],
- ['alpha_dash', [':value', TRUE]],
+ ['alpha_dash', [':value', true]],
[[$this->repo, 'isSlugAvailable'], [':value']],
],
'locale' => [
['max_length', [':value', 5]],
- ['alpha_dash', [':value', TRUE]],
+ ['alpha_dash', [':value', true]],
// @todo check locale is valid
// @todo if the translation exists and we're performing an Update,
// passing locale should not throw an error
@@ -165,11 +170,11 @@ protected function getRules()
];
}
- public function checkPublishedLimit (Validation $validation, $status)
+ public function checkPublishedLimit(Validation $validation, $status)
{
$config = \Kohana::$config->load('features.limits');
- if ($config['posts'] !== TRUE && $status == 'published') {
+ if ($config['posts'] !== true && $status == 'published') {
$total_published = $this->repo->getPublishedTotal();
if ($total_published >= $config['posts']) {
@@ -178,7 +183,7 @@ public function checkPublishedLimit (Validation $validation, $status)
}
}
- public function checkApprovalRequired (Validation $validation, $status, $fullData)
+ public function checkApprovalRequired(Validation $validation, $status, $fullData)
{
// Status hasn't changed, moving on
if (!$status) {
@@ -214,14 +219,12 @@ public function checkTags(Validation $validation, $tags)
return;
}
- foreach ($tags as $key => $tag)
- {
+ foreach ($tags as $key => $tag) {
if (is_array($tag)) {
$tag = $tag['id'];
}
- if (! $this->tag_repo->doesTagExist($tag))
- {
+ if (! $this->tag_repo->doesTagExist($tag)) {
$validation->error('tags', 'tagDoesNotExist', [$tag]);
}
}
@@ -229,26 +232,22 @@ public function checkTags(Validation $validation, $tags)
public function checkValues(Validation $validation, $attributes, $fullData)
{
- if (!$attributes)
- {
+ if (!$attributes) {
return;
}
$post_id = ! empty($fullData['id']) ? $fullData['id'] : 0;
- foreach ($attributes as $key => $values)
- {
+ foreach ($attributes as $key => $values) {
// Check attribute exists
$attribute = $this->attribute_repo->getByKey($key, $fullData['form_id'], true);
- if (! $attribute->id)
- {
+ if (! $attribute->id) {
$validation->error('values', 'attributeDoesNotExist', [$key]);
return;
}
// Are there multiple values? Are they greater than cardinality limit?
- if (count($values) > $attribute->cardinality AND $attribute->cardinality != 0)
- {
+ if (count($values) > $attribute->cardinality and $attribute->cardinality != 0) {
$validation->error('values', 'tooManyValues', [
$attribute->label,
$attribute->cardinality
@@ -256,17 +255,13 @@ public function checkValues(Validation $validation, $attributes, $fullData)
}
// Run checks on individual values type specific validation
- if ($validator = $this->post_value_validator_factory->getValidator($attribute->type))
- {
+ if ($validator = $this->post_value_validator_factory->getValidator($attribute->type)) {
// Pass attribute config to the validator
$validator->setConfig($attribute->config);
- if (!is_array($values))
- {
+ if (!is_array($values)) {
$validation->error('values', 'notAnArray', [$attribute->label]);
- }
- elseif ($error = $validator->check($values))
- {
+ } elseif ($error = $validator->check($values)) {
$validation->error('values', $error, [$attribute->label, $values]);
}
}
@@ -282,16 +277,13 @@ public function checkValues(Validation $validation, $attributes, $fullData)
*/
public function checkStageInForm(Validation $validation, $completed_stages, $fullData)
{
- if (!$completed_stages)
- {
+ if (!$completed_stages) {
return;
}
- foreach ($completed_stages as $stage_id)
- {
+ foreach ($completed_stages as $stage_id) {
// Check stage exists in form
- if (! $this->stage_repo->existsInForm($stage_id, $fullData['form_id']))
- {
+ if (! $this->stage_repo->existsInForm($stage_id, $fullData['form_id'])) {
$validation->error('completed_stages', 'stageDoesNotExist', [$stage_id]);
return;
}
@@ -310,15 +302,12 @@ public function checkRequiredStages(Validation $validation, $completed_stages, $
$completed_stages = $completed_stages ? $completed_stages : [];
// If post is being published
- if ($fullData['status'] === 'published')
- {
+ if ($fullData['status'] === 'published') {
// Load the required stages
$required_stages = $this->stage_repo->getRequired($fullData['form_id']);
- foreach ($required_stages as $stage)
- {
+ foreach ($required_stages as $stage) {
// Check the required stages have been completed
- if (! in_array($stage->id, $completed_stages))
- {
+ if (! in_array($stage->id, $completed_stages)) {
// If its not completed, add a validation error
$validation->error('completed_stages', 'stageRequired', [$stage->label]);
}
@@ -335,23 +324,19 @@ public function checkRequiredStages(Validation $validation, $completed_stages, $
*/
public function checkRequiredAttributes(Validation $validation, $attributes, $fullData)
{
- if (empty($fullData['completed_stages']))
- {
+ if (empty($fullData['completed_stages'])) {
return;
}
// If a stage is being marked completed
// Check if the required attribute have been completed
- foreach ($fullData['completed_stages'] as $stage_id)
- {
+ foreach ($fullData['completed_stages'] as $stage_id) {
// Load the required attributes
$required_attributes = $this->attribute_repo->getRequired($stage_id);
// Check each attribute has been completed
- foreach ($required_attributes as $attr)
- {
- if (!array_key_exists($attr->key, $attributes))
- {
+ foreach ($required_attributes as $attr) {
+ if (!array_key_exists($attr->key, $attributes)) {
$stage = $this->stage_repo->get($stage_id);
// If a required attribute isn't completed, throw an error
$validation->error('values', 'attributeRequired', [$attr->label, $stage->label]);
@@ -368,7 +353,7 @@ public function checkRequiredAttributes(Validation $validation, $attributes, $fu
*/
public function onlyAuthorOrUserSet($user_id, $fullData)
{
- return (empty($user_id) OR (empty($fullData['author_email']) AND empty($fullData['author_realname'])) );
+ return (empty($user_id) or (empty($fullData['author_email']) and empty($fullData['author_realname'])) );
}
public function validDate($str)
@@ -376,6 +361,6 @@ public function validDate($str)
if ($str instanceof \DateTimeInterface) {
return true;
}
- return (strtotime($str) !== FALSE);
+ return (strtotime($str) !== false);
}
}
diff --git a/application/classes/Ushahidi/Validator/Post/Datetime.php b/src/App/Validator/Post/Datetime.php
similarity index 65%
rename from application/classes/Ushahidi/Validator/Post/Datetime.php
rename to src/App/Validator/Post/Datetime.php
index dd8204b82c..a5ff8ac6d7 100644
--- a/application/classes/Ushahidi/Validator/Post/Datetime.php
+++ b/src/App/Validator/Post/Datetime.php
@@ -1,4 +1,4 @@
- [
+ 'values' => [
[[$this, 'checkValues'], [':validation', ':value', ':fulldata']]
],
- 'completed_stages' => [
+ 'completed_stages' => [
[[$this, 'checkStageInForm'], [':validation', ':value', ':fulldata']]
- ]
- ]);
- }
+ ]
+ ]);
+ }
}
diff --git a/application/classes/Ushahidi/Validator/Post/Int.php b/src/App/Validator/Post/Int.php
similarity index 66%
rename from application/classes/Ushahidi/Validator/Post/Int.php
rename to src/App/Validator/Post/Int.php
index 208ecbbd77..fb686faf1a 100644
--- a/application/classes/Ushahidi/Validator/Post/Int.php
+++ b/src/App/Validator/Post/Int.php
@@ -1,4 +1,4 @@
-map[$type]) ? $this->map[$type]() : FALSE;
+ return isset($this->map[$type]) ? $this->map[$type]() : false;
}
-}
\ No newline at end of file
+}
diff --git a/application/classes/Ushahidi/Validator/Post/ValueValidator.php b/src/App/Validator/Post/ValueValidator.php
similarity index 74%
rename from application/classes/Ushahidi/Validator/Post/ValueValidator.php
rename to src/App/Validator/Post/ValueValidator.php
index ef15278818..65202076a5 100644
--- a/application/classes/Ushahidi/Validator/Post/ValueValidator.php
+++ b/src/App/Validator/Post/ValueValidator.php
@@ -1,4 +1,4 @@
-config = $config;
}
- public function check(Array $values)
+ public function check(array $values)
{
foreach ($values as $value) {
if ($error = $this->validate($value)) {
diff --git a/application/classes/Ushahidi/Validator/Post/Varchar.php b/src/App/Validator/Post/Varchar.php
similarity index 67%
rename from application/classes/Ushahidi/Validator/Post/Varchar.php
rename to src/App/Validator/Post/Varchar.php
index 1ee138839b..2408584dea 100644
--- a/application/classes/Ushahidi/Validator/Post/Varchar.php
+++ b/src/App/Validator/Post/Varchar.php
@@ -1,4 +1,4 @@
-
+ * @package Ushahidi\Application
+ * @copyright 2016 Ushahidi
+ * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
+ */
+
+namespace Ushahidi\App\Validator\Post;
+
+class Video extends 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);
+ }
+}
diff --git a/application/classes/Ushahidi/Validator/Role/Create.php b/src/App/Validator/Role/Create.php
similarity index 73%
rename from application/classes/Ushahidi/Validator/Role/Create.php
rename to src/App/Validator/Role/Create.php
index 2ce1ef073e..a09cfc1e94 100644
--- a/application/classes/Ushahidi/Validator/Role/Create.php
+++ b/src/App/Validator/Role/Create.php
@@ -1,4 +1,4 @@
-permission_repo->exists($permission)) {
$validation->error('permissions', 'permissionDoesNotExist', [$permission]);
return;
diff --git a/application/classes/Ushahidi/Validator/SavedSearch/Create.php b/src/App/Validator/SavedSearch/Create.php
similarity index 71%
rename from application/classes/Ushahidi/Validator/SavedSearch/Create.php
rename to src/App/Validator/SavedSearch/Create.php
index ea3321de58..4b680ef177 100644
--- a/application/classes/Ushahidi/Validator/SavedSearch/Create.php
+++ b/src/App/Validator/SavedSearch/Create.php
@@ -1,4 +1,4 @@
- [
+ 'name' => [
['not_empty'],
],
'filter' => [
diff --git a/application/classes/Ushahidi/Validator/SavedSearch/Update.php b/src/App/Validator/SavedSearch/Update.php
similarity index 74%
rename from application/classes/Ushahidi/Validator/SavedSearch/Update.php
rename to src/App/Validator/SavedSearch/Update.php
index eea95af7f1..9ca8ecdb1b 100644
--- a/application/classes/Ushahidi/Validator/SavedSearch/Update.php
+++ b/src/App/Validator/SavedSearch/Update.php
@@ -1,4 +1,4 @@
- [['not_empty']],
]);
}
diff --git a/application/classes/Ushahidi/Validator/Set/Post/Create.php b/src/App/Validator/Set/Post/Create.php
similarity index 84%
rename from application/classes/Ushahidi/Validator/Set/Post/Create.php
rename to src/App/Validator/Set/Post/Create.php
index 8b27857261..3563284dfd 100644
--- a/application/classes/Ushahidi/Validator/Set/Post/Create.php
+++ b/src/App/Validator/Set/Post/Create.php
@@ -1,4 +1,4 @@
- [
['not_empty'],
['max_length', [':value', 150]],
- ['email', [':value', TRUE]],
+ ['email', [':value', true]],
[[$this->repo, 'isUniqueEmail'], [':value']],
],
'password' => [
diff --git a/application/classes/Ushahidi/Validator/User/Update.php b/src/App/Validator/User/Update.php
similarity index 83%
rename from application/classes/Ushahidi/Validator/User/Update.php
rename to src/App/Validator/User/Update.php
index a6da91b2f6..55c43f2a12 100644
--- a/application/classes/Ushahidi/Validator/User/Update.php
+++ b/src/App/Validator/User/Update.php
@@ -1,4 +1,4 @@
- [
- ['email', [':value', TRUE]],
+ ['email', [':value', true]],
['max_length', [':value', 150]],
[[$this->repo, 'isUniqueEmail'], [':value']],
],
@@ -53,12 +55,11 @@ protected function getRules()
];
}
- public function checkAdminRoleLimit (Validation $validation, $role)
+ public function checkAdminRoleLimit(\Validation $validation, $role)
{
$config = \Kohana::$config->load('features.limits');
- if ($config['admin_users'] !== TRUE && $role == 'admin') {
-
+ if ($config['admin_users'] !== true && $role == 'admin') {
$total = $this->repo->getTotalCount(['role' => 'admin']);
if ($total >= $config['admin_users']) {
@@ -66,5 +67,4 @@ public function checkAdminRoleLimit (Validation $validation, $role)
}
}
}
-
}
diff --git a/application/classes/Ushahidi/Validator/Webhook/Create.php b/src/App/Validator/Webhook/Create.php
similarity index 65%
rename from application/classes/Ushahidi/Validator/Webhook/Create.php
rename to src/App/Validator/Webhook/Create.php
index 77f974c2ad..d906bffc40 100644
--- a/application/classes/Ushahidi/Validator/Webhook/Create.php
+++ b/src/App/Validator/Webhook/Create.php
@@ -1,4 +1,4 @@
-getOption('provider'))
- {
+ if ($provider = $input->getOption('provider')) {
$providers = [$this->repo->get($provider)];
- }
- else
- {
+ } else {
$providers = $this->repo->all(!$input->getOption('all'));
}
return $providers;
@@ -52,11 +52,10 @@ protected function get_providers(InputInterface $input, OutputInterface $output
protected function executeList(InputInterface $input, OutputInterface $output)
{
- $providers = $this->get_providers($input, $output);
+ $providers = $this->getProviders($input, $output);
$list = [];
- foreach ($providers as $id => $provider)
- {
+ foreach ($providers as $id => $provider) {
$list[] = [
'Name' => $provider->name,
'Version' => $provider->version,
@@ -68,13 +67,12 @@ protected function executeList(InputInterface $input, OutputInterface $output)
protected function executeIncoming(InputInterface $input, OutputInterface $output)
{
- $providers = $this->get_providers($input, $output);
+ $providers = $this->getProviders($input, $output);
$limit = $input->getOption('limit');
$totals = [];
- foreach ($providers as $provider)
- {
+ foreach ($providers as $provider) {
$totals[] = [
'Provider' => $provider->name,
'Total' => \DataProvider::factory($provider->id)->fetch($limit),
@@ -86,7 +84,7 @@ protected function executeIncoming(InputInterface $input, OutputInterface $outpu
protected function executeOutgoing(InputInterface $input, OutputInterface $output)
{
- $providers = $this->get_providers($input, $output);
+ $providers = $this->getProviders($input, $output);
$limit = $input->getOption('limit');
// Hack: always include email no matter what!
@@ -95,8 +93,7 @@ protected function executeOutgoing(InputInterface $input, OutputInterface $outpu
}
$totals = [];
- foreach ($providers as $id => $provider)
- {
+ foreach ($providers as $id => $provider) {
$totals[] = [
'Provider' => $provider->name,
'Total' => \DataProvider::process_pending_messages($limit, $id)
diff --git a/application/classes/Ushahidi/Console/Notification.php b/src/Console/Command/Notification.php
similarity index 89%
rename from application/classes/Ushahidi/Console/Notification.php
rename to src/Console/Command/Notification.php
index b3f167fef2..4fc45691f9 100644
--- a/application/classes/Ushahidi/Console/Notification.php
+++ b/src/Console/Command/Notification.php
@@ -1,4 +1,4 @@
-load('site.client_url');
// Get contacts (max $limit at a time) and generate messages.
- while (TRUE) {
+ while (true) {
$contacts = $this->contactRepository
->getNotificationContacts($notification->set_id, $limit, $offset);
@@ -140,8 +142,12 @@ private function generateMessages($notification)
$state = [
'contact_id' => $contact->id,
'notification_post_id' => $post->id,
- 'title' => strtr(Kohana::message('notifications', $messageType . '.title', "New post: :title"), $subs),
- 'message' => strtr(Kohana::message('notifications', $messageType . '.message', "New post: :title"), $subs),
+ 'title' => strtr(Kohana::message(
+ 'notifications', $messageType . '.title', "New post: :title"
+ ), $subs),
+ 'message' => strtr(Kohana::message(
+ 'notifications', $messageType . '.message', "New post: :title"
+ ), $subs),
'type' => $messageType,
'data_provider' => $data_provider,
];
@@ -172,6 +178,7 @@ private function generateMessages($notification)
private function mapContactToMessageType($contactType)
{
- return isset($this->contactToMessageTypeMap[$contactType]) ? $this->contactToMessageTypeMap[$contactType] : $contactType;
+ return isset($this->contactToMessageTypeMap[$contactType])
+ ? $this->contactToMessageTypeMap[$contactType] : $contactType;
}
}
diff --git a/application/classes/Ushahidi/Console/SavedSearch.php b/src/Console/Command/SavedSearch.php
similarity index 95%
rename from application/classes/Ushahidi/Console/SavedSearch.php
rename to src/Console/Command/SavedSearch.php
index ba5f875c87..446c04c1d0 100644
--- a/application/classes/Ushahidi/Console/SavedSearch.php
+++ b/src/Console/Command/SavedSearch.php
@@ -1,4 +1,4 @@
-set('app.console', $di->lazyNew('Ushahidi\Console\Application'));
+
+// Any command can be registered with the console app.
+$di->params['Ushahidi\Console\Application']['injectCommands'] = [];
+
+// Set up Import command
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\Import');
+$di->setter['Ushahidi\Console\Command\Import']['setReaderMap'] = [];
+$di->setter['Ushahidi\Console\Command\Import']['setReaderMap']['csv'] = $di->lazyGet('filereader.csv');
+$di->setter['Ushahidi\Console\Command\Import']['setTransformer'] = $di->lazyGet('transformer.mapping');
+$di->setter['Ushahidi\Console\Command\Import']['setImportUsecase'] = $di->lazy(function () use ($di) {
+ return service('factory.usecase')
+ ->get('posts', 'import')
+ // Override authorizer for console
+ ->setAuthorizer($di->get('authorizer.console'));
+});
+
+// User command
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\User');
+$di->setter['Ushahidi\Console\Command\User']['setRepo'] = $di->lazyGet('repository.user');
+$di->setter['Ushahidi\Console\Command\User']['setValidator'] = $di->lazyNew('Ushahidi_Validator_User_Create');
+
+// Config commands
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\ConfigGet');
+$di->setter['Ushahidi\Console\Command\ConfigGet']['setUsecase'] = $di->lazy(function () use ($di) {
+ return service('factory.usecase')
+ ->get('config', 'read')
+ // Override authorizer for console
+ ->setAuthorizer($di->get('authorizer.console'))
+ // Override formatter for console
+ ->setFormatter($di->get('formatter.entity.console'));
+});
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\ConfigSet');
+$di->setter['Ushahidi\Console\Command\ConfigSet']['setUsecase'] = $di->lazy(function () use ($di) {
+ return service('factory.usecase')
+ ->get('config', 'update')
+ // Override authorizer for console
+ ->setAuthorizer($di->get('authorizer.console'))
+ // Override formatter for console
+ ->setFormatter($di->get('formatter.entity.console'));
+});
+
+$di->set('authorizer.console', $di->lazyNew('Ushahidi\Console\Authorizer\ConsoleAuthorizer'));
+
+// Console commands (oauth is disabled, pending T305)
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\Dataprovider');
+$di->setter['Ushahidi\Console\Command\Dataprovider']['setRepo'] = $di->lazyGet('repository.dataprovider');
+
+// Notification Collection command
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\Notification');
+$di->setter['Ushahidi\Console\Command\Notification']['setDatabase'] = $di->lazyGet('kohana.db');
+$di->setter['Ushahidi\Console\Command\Notification']['setPostRepo'] = $di->lazyGet('repository.post');
+$di->setter['Ushahidi\Console\Command\Notification']['setMessageRepo'] = $di->lazyGet('repository.message');
+$di->setter['Ushahidi\Console\Command\Notification']['setContactRepo'] = $di->lazyGet('repository.contact');
+$di->setter['Ushahidi\Console\Command\Notification']['setNotificationQueueRepo'] =
+ $di->lazyGet('repository.notification.queue');
+
+// Notification SavedSearch command
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\SavedSearch');
+$di->setter['Ushahidi\Console\Command\SavedSearch']['setSetRepo'] = $di->lazyGet('repository.savedsearch');
+$di->setter['Ushahidi\Console\Command\SavedSearch']['setPostRepo'] = $di->lazyGet('repository.post');
+$di->setter['Ushahidi\Console\Command\SavedSearch']['setMessageRepo'] = $di->lazyGet('repository.message');
+$di->setter['Ushahidi\Console\Command\SavedSearch']['setContactRepo'] = $di->lazyGet('repository.contact');
+$di->setter['Ushahidi\Console\Command\SavedSearch']['setDataFactory'] = $di->lazyGet('factory.data');
+
+// Webhook command
+$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\Webhook');
+$di->setter['Ushahidi\Console\Command\Webhook']['setDatabase'] = $di->lazyGet('kohana.db');
+$di->setter['Ushahidi\Console\Command\Webhook']['setPostRepo'] = $di->lazyGet('repository.post');
+$di->setter['Ushahidi\Console\Command\Webhook']['setWebhookRepo'] = $di->lazyGet('repository.webhook');
+$di->setter['Ushahidi\Console\Command\Webhook']['setWebhookJobRepo'] = $di->lazyGet('repository.webhook.job');
diff --git a/src/Core/Traits/FormatterAuthorizerMetadata.php b/src/Core/Traits/FormatterAuthorizerMetadata.php
index 8b626fece5..0fbb9ac837 100644
--- a/src/Core/Traits/FormatterAuthorizerMetadata.php
+++ b/src/Core/Traits/FormatterAuthorizerMetadata.php
@@ -35,13 +35,10 @@ protected function getAllowedPrivs(Entity $entity)
return $this->auth->getAllowedPrivs($entity);
}
- // @todo method name does not PSR because it is used in Kohana
- // @codingStandardsIgnoreStart
- protected function add_metadata(Array $data, Entity $entity)
+ protected function addMetadata(array $data, Entity $entity)
{
return $data + [
'allowed_privileges' => $this->getAllowedPrivs($entity),
];
}
- // @codingStandardsIgnoreEnd
}
diff --git a/src/Init.php b/src/Init.php
index ff49124efe..564d319e01 100644
--- a/src/Init.php
+++ b/src/Init.php
@@ -69,49 +69,6 @@ function feature($name)
// Disable auto resolution (as recommended in AuraDI docs)
$di->setAutoResolve(false);
-// Console application is used for command line tools.
-$di->set('app.console', $di->lazyNew('Ushahidi\Console\Application'));
-
-// Any command can be registered with the console app.
-$di->params['Ushahidi\Console\Application']['injectCommands'] = [];
-
-// Set up Import command
-$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\Import');
-$di->setter['Ushahidi\Console\Command\Import']['setReaderMap'] = [];
-$di->setter['Ushahidi\Console\Command\Import']['setReaderMap']['csv'] = $di->lazyGet('filereader.csv');
-$di->setter['Ushahidi\Console\Command\Import']['setTransformer'] = $di->lazyGet('transformer.mapping');
-$di->setter['Ushahidi\Console\Command\Import']['setImportUsecase'] = $di->lazy(function () use ($di) {
- return service('factory.usecase')
- ->get('posts', 'import')
- // Override authorizer for console
- ->setAuthorizer($di->get('authorizer.console'));
-});
-
-// User command
-$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\User');
-$di->setter['Ushahidi\Console\Command\User']['setRepo'] = $di->lazyGet('repository.user');
-$di->setter['Ushahidi\Console\Command\User']['setValidator'] = $di->lazyNew('Ushahidi_Validator_User_Create');
-
-// Config commands
-$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\ConfigGet');
-$di->setter['Ushahidi\Console\Command\ConfigGet']['setUsecase'] = $di->lazy(function () use ($di) {
- return service('factory.usecase')
- ->get('config', 'read')
- // Override authorizer for console
- ->setAuthorizer($di->get('authorizer.console'))
- // Override formatter for console
- ->setFormatter($di->get('formatter.entity.console'));
-});
-$di->setter['Ushahidi\Console\Application']['injectCommands'][] = $di->lazyNew('Ushahidi\Console\Command\ConfigSet');
-$di->setter['Ushahidi\Console\Command\ConfigSet']['setUsecase'] = $di->lazy(function () use ($di) {
- return service('factory.usecase')
- ->get('config', 'update')
- // Override authorizer for console
- ->setAuthorizer($di->get('authorizer.console'))
- // Override formatter for console
- ->setFormatter($di->get('formatter.entity.console'));
-});
-
// Validators are used to parse **and** verify input data used for write operations.
$di->set('factory.validator', $di->lazyNew('Ushahidi\Factory\ValidatorFactory'));
@@ -399,6 +356,5 @@ function feature($name)
'form_repo' => $di->lazyGet('repository.form'),
];
-$di->set('authorizer.console', $di->lazyNew('Ushahidi\Console\Authorizer\ConsoleAuthorizer'));
-
require __DIR__ . '/App/Init.php';
+require __DIR__ . '/Console/Init.php';
diff --git a/application/classes/Unittest/Database/Operation/MySQL55Truncate.php b/tests/Support/MySQL55Truncate.php
similarity index 62%
rename from application/classes/Unittest/Database/Operation/MySQL55Truncate.php
rename to tests/Support/MySQL55Truncate.php
index 8894958efd..7500aabd0e 100644
--- a/application/classes/Unittest/Database/Operation/MySQL55Truncate.php
+++ b/tests/Support/MySQL55Truncate.php
@@ -6,14 +6,18 @@
* @package DbUnit
*/
-class Unittest_Database_Operation_MySQL55Truncate extends PHPUnit_Extensions_Database_Operation_Truncate {
+namespace Tests\Support;
- public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
- {
+class MySQL55Truncate extends \PHPUnit_Extensions_Database_Operation_Truncate
+{
+
+ public function execute(
+ \PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection,
+ \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
+ ) {
$connection->getConnection()->query("SET @FAKE_PREV_foreign_key_checks = @@foreign_key_checks");
$connection->getConnection()->query("SET foreign_key_checks = 0");
parent::execute($connection, $dataSet);
$connection->getConnection()->query("SET foreign_key_checks = @FAKE_PREV_foreign_key_checks");
}
-
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 89a058d121..c590fcecfc 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -1,5 +1,7 @@
tokenUserMap[$tokenId], [$scope]);
$accessToken->setIdentifier($tokenId);
- $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
+ $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('P1D')));
$accessToken->setClient($client);
$token = $accessToken->convertToJwt($key);
diff --git a/tests/unit/Ushahidi/PostValueRepositoryTest.php b/tests/unit/Ushahidi/PostValueRepositoryTest.php
index df70ea80a8..87d88256d3 100644
--- a/tests/unit/Ushahidi/PostValueRepositoryTest.php
+++ b/tests/unit/Ushahidi/PostValueRepositoryTest.php
@@ -1,7 +1,7 @@
* @package Ushahidi\Application\Tests
@@ -24,7 +24,7 @@ public function setUp()
{
parent::setUp();
- $this->repository = $this->getMockBuilder(\Ushahidi_Repository_Post_Value::class)
+ $this->repository = $this->getMockBuilder(\Ushahidi\App\Repository\Post\ValueRepository::class)
->setMethods(['selectOne', 'selectQuery', 'getTable'])
->disableOriginalConstructor()
->getMock();
diff --git a/tests/unit/Util/BoundingBoxTest.php b/tests/unit/Util/BoundingBoxTest.php
index 89357c78c0..75eb3517e9 100644
--- a/tests/unit/Util/BoundingBoxTest.php
+++ b/tests/unit/Util/BoundingBoxTest.php
@@ -11,7 +11,7 @@
namespace Tests\Unit\Util;
-use Util_BoundingBox;
+use Ushahidi\App\Util\BoundingBox;
/**
* @backupGlobals disabled
@@ -27,10 +27,10 @@ class BoundingBoxTest extends \PHPUnit\Framework\TestCase
*/
public function testToWKT()
{
- $bb = new Util_BoundingBox(-180, -90, 180, 90);
+ $bb = new BoundingBox(-180, -90, 180, 90);
$this->assertEquals('POLYGON((-180 -90,180 -90,180 90,-180 90,-180 -90))', $bb->toWKT());
- $bb = new Util_BoundingBox(-1, -1, 1, 1);
+ $bb = new BoundingBox(-1, -1, 1, 1);
$this->assertEquals('POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))', $bb->toWKT());
}
@@ -41,11 +41,11 @@ public function testToWKT()
*/
public function testAsArray()
{
- $bb = new Util_BoundingBox(-180, -90, 180, 90);
- $this->assertEquals(array(-180, -90, 180, 90), $bb->as_array());
+ $bb = new BoundingBox(-180, -90, 180, 90);
+ $this->assertEquals(array(-180, -90, 180, 90), $bb->asArray());
- $bb = new Util_BoundingBox(-1, -1, 1, 1);
- $this->assertEquals(array(-1, -1, 1, 1), $bb->as_array());
+ $bb = new BoundingBox(-1, -1, 1, 1);
+ $this->assertEquals(array(-1, -1, 1, 1), $bb->asArray());
}
/**
@@ -55,11 +55,11 @@ public function testAsArray()
*/
public function testToGeometry()
{
- $bb = new Util_BoundingBox(-180, -90, 180, 90);
+ $bb = new BoundingBox(-180, -90, 180, 90);
$geom = $bb->toGeometry();
$this->assertEquals('POLYGON((-180 -90,180 -90,180 90,-180 90,-180 -90))', $geom->toWKT());
- $bb = new Util_BoundingBox(-1, -1, 1, 1);
+ $bb = new BoundingBox(-1, -1, 1, 1);
$geom = $bb->toGeometry();
$this->assertEquals('POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))', $geom->toWKT());
}
diff --git a/tests/unit/Util/TileTest.php b/tests/unit/Util/TileTest.php
index cd4047a139..c6deea07a4 100644
--- a/tests/unit/Util/TileTest.php
+++ b/tests/unit/Util/TileTest.php
@@ -11,7 +11,7 @@
namespace Tests\Unit\Util;
-use Util_Tile;
+use Ushahidi\App\Util\Tile;
/**
* @backupGlobals disabled
@@ -27,10 +27,10 @@ class TileTest extends \PHPUnit\Framework\TestCase
*/
public function testNumTiles()
{
- $this->assertEquals(1, Util_Tile::numTiles(0));
- $this->assertEquals(2, Util_Tile::numTiles(1));
- $this->assertEquals(4, Util_Tile::numTiles(2));
- $this->assertEquals(256, Util_Tile::numTiles(8));
+ $this->assertEquals(1, Tile::numTiles(0));
+ $this->assertEquals(2, Tile::numTiles(1));
+ $this->assertEquals(4, Tile::numTiles(2));
+ $this->assertEquals(256, Tile::numTiles(8));
}
/**
@@ -40,25 +40,25 @@ public function testNumTiles()
*/
public function testTileToBoundingBox()
{
- $bb = Util_Tile::tileToBoundingBox(0, 0, 0);
+ $bb = Tile::tileToBoundingBox(0, 0, 0);
$this->assertAttributeEquals(85.051100, 'north', $bb, '', 0.0002);
$this->assertAttributeEquals(-85.051100, 'south', $bb, '', 0.0002);
$this->assertAttributeEquals(-180, 'west', $bb, '', 0.0002);
$this->assertAttributeEquals(180, 'east', $bb, '', 0.0002);
- $bb = Util_Tile::tileToBoundingBox(1, 1, 1);
+ $bb = Tile::tileToBoundingBox(1, 1, 1);
$this->assertAttributeEquals(0, 'north', $bb, '', 0.0002);
$this->assertAttributeEquals(-85.051100, 'south', $bb, '', 0.0002);
$this->assertAttributeEquals(0, 'west', $bb, '', 0.0002);
$this->assertAttributeEquals(180, 'east', $bb, '', 0.0002);
- $bb = Util_Tile::tileToBoundingBox(2, 2, 1);
+ $bb = Tile::tileToBoundingBox(2, 2, 1);
$this->assertAttributeEquals(66.5131, 'north', $bb, '', 0.0002);
$this->assertAttributeEquals(0, 'south', $bb, '', 0.0002);
$this->assertAttributeEquals(0, 'west', $bb, '', 0.0002);
$this->assertAttributeEquals(90, 'east', $bb, '', 0.0002);
- $bb = Util_Tile::tileToBoundingBox(8, 13, 14);
+ $bb = Tile::tileToBoundingBox(8, 13, 14);
$this->assertAttributeEquals(83.026183, 'north', $bb, '', 0.0002);
$this->assertAttributeEquals(82.853346, 'south', $bb, '', 0.0002);
$this->assertAttributeEquals(-161.718750, 'west', $bb, '', 0.0002);
@@ -72,10 +72,10 @@ public function testTileToBoundingBox()
*/
public function testTileToLon()
{
- $this->assertEquals(-180, Util_Tile::tileToLon(0, 0), '', 0.0002);
- $this->assertEquals(0, Util_Tile::tileToLon(1, 1), '', 0.0002);
- $this->assertEquals(0, Util_Tile::tileToLon(2, 2), '', 0.0002);
- $this->assertEquals(-163.125000, Util_Tile::tileToLon(12, 8), '', 0.0002);
+ $this->assertEquals(-180, Tile::tileToLon(0, 0), '', 0.0002);
+ $this->assertEquals(0, Tile::tileToLon(1, 1), '', 0.0002);
+ $this->assertEquals(0, Tile::tileToLon(2, 2), '', 0.0002);
+ $this->assertEquals(-163.125000, Tile::tileToLon(12, 8), '', 0.0002);
}
/**
@@ -85,9 +85,9 @@ public function testTileToLon()
*/
public function testTileToLat()
{
- $this->assertEquals(85.05112, Util_Tile::tileToLat(0, 0), '', 0.0002);
- $this->assertEquals(0, Util_Tile::tileToLat(1, 1), '', 0.0002);
- $this->assertEquals(0, Util_Tile::tileToLat(2, 2), '', 0.0002);
- $this->assertEquals(83.026183, Util_Tile::tileToLat(14, 8), '', 0.0002);
+ $this->assertEquals(85.05112, Tile::tileToLat(0, 0), '', 0.0002);
+ $this->assertEquals(0, Tile::tileToLat(1, 1), '', 0.0002);
+ $this->assertEquals(0, Tile::tileToLat(2, 2), '', 0.0002);
+ $this->assertEquals(83.026183, Tile::tileToLat(14, 8), '', 0.0002);
}
}