Skip to content

Commit

Permalink
Merge pull request #89 from ushahidi/person-status-dev
Browse files Browse the repository at this point in the history
Person status dev
  • Loading branch information
David Kobia committed Oct 31, 2013
2 parents ac67c69 + a735f47 commit fdbb390
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 101 deletions.
12 changes: 10 additions & 2 deletions application/classes/Controller/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function action_ajax_list()
->on('c.id', '=', 'cp.contact_id')
->join(array('people', 'p'), 'INNER')
->on('cp.person_id', '=', 'p.id')
->where('p.user_id', '=', $this->user->id);
->join(array('messages', 'm'), 'INNER')
->on('pings.message_id', '=', 'm.id')
->where('p.user_id', '=', $this->user->id)
->where('m.user_id', '=', $this->user->id); // Ensure one can only view pings they sent

// Pongs
$pongs = DB::select('cp.person_id', 'p.name', 'p.status', 'pongs.type', 'c.contact', array('pongs.created', 'created_on'), array(DB::expr('"pong"'), 'action'), array(DB::expr('0'), 'message_id'))
Expand All @@ -52,7 +55,12 @@ public function action_ajax_list()
->on('c.id', '=', 'cp.contact_id')
->join(array('people', 'p'), 'INNER')
->on('cp.person_id', '=', 'p.id')
->where('p.user_id', '=', $this->user->id);
->join(array('pings', 'pi'), 'INNER')
->on('pongs.ping_id', '=', 'pi.id')
->join(array('messages', 'm'), 'INNER')
->on('pi.message_id', '=', 'm.id')
->where('p.user_id', '=', $this->user->id)
->where('m.user_id', '=', $this->user->id); // Ensure one can only view pongs received by their contacts

// Paging
$offset = $limit = '';
Expand Down
2 changes: 1 addition & 1 deletion application/classes/Controller/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function action_ajax_calculate()

$types = $this->request->post('type');
$recipients = $this->request->post('recipients');
if (is_array($recipients) )
if ( is_array($recipients) )
{
foreach ($types as $type)
{
Expand Down
101 changes: 83 additions & 18 deletions application/classes/Controller/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ public function action_view()
->bind('pings', $pings)
->bind('pongs', $pongs)
->bind('groups', $groups)
->bind('children', $children);
->bind('children', $children)
->bind('status', $status)
->bind('my_status', $my_status);

$this->template->footer->js = View::factory('pages/people/js/view')
->bind('person', $person);
Expand All @@ -233,27 +235,90 @@ public function action_view()
HTTP::redirect('dashboard');
}

$pings = ORM::factory('Ping')
->select('contacts.contact')
->join('contacts', 'INNER')->on('contacts.id', '=', 'ping.contact_id')
->join('contacts_people', 'INNER')->on('contacts.id', '=', 'contacts_people.contact_id')
->where('contacts_people.person_id', '=', $person->id)
->order_by('created', 'DESC')
->limit(10)
->find_all();
$groups = $person->groups->find_all();

$pongs = ORM::factory('Pong')
->select('contacts.contact')
->join('contacts', 'INNER')->on('contacts.id', '=', 'pong.contact_id')
->join('contacts_people', 'INNER')->on('contacts.id', '=', 'contacts_people.contact_id')
->where('contacts_people.person_id', '=', $person->id)
// Is the status update by me?
$status = $person->person_statuses
->order_by('created', 'DESC')
->limit(10)
->find_all();
->find();
$my_status = FALSE;

//++TODO: Simpler Joins?
// First lets find out if the status was updated by a 'pong'
// back to one of my people
if (ORM::factory('Pong')
->join(array('pings', 'pi'), 'INNER')
->on('pong.ping_id', '=', 'pi.id')
->join(array('messages', 'm'), 'INNER')
->on('pi.message_id', '=', 'm.id')
->where('m.user_id', '=', $this->user->id)
->where('pong.id', '=', $status->pong_id)
->find()
->loaded())
{
$my_status = TRUE;
}
else
{
// Well lets find out if it was me that manually updated
// this users status
if ($status->user_id == $this->user->id)
{
$my_status = TRUE;
}
}
}

$groups = $person->groups->find_all();
/**
* View Person Status
*
* @return void
*/
public function action_status()
{
$this->template->content = View::factory('pages/people/status')
->bind('person', $person)
->bind('post', $post)
->bind('errors', $errors)
->bind('done', $done);

$person_id = $this->request->param('id', 0);

$person = ORM::factory('Person')
->where('id', '=', $person_id)
->where('parent_id', '=', 0)
->where('user_id', '=', $this->user->id)
->find();

if ( ! $person->loaded() )
{
HTTP::redirect('dashboard');
}

if ( ! empty($_POST) )
{
$post = $_POST;
$status = ORM::factory('Person_Status');

$children = $person->children->find_all();
try
{
PingApp_Status::update($this->user, $person, $post['status'], $post['note']);

// Redirect to prevent repost
HTTP::redirect('people/view/'.$person->id);
}
catch (ORM_Validation_Exception $e)
{
$errors = Arr::flatten($e->errors('models'));
}
}
else
{
$post = array(
'status' => $person->status,
'note' => ''
);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion application/classes/Controller/Pings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function action_ajax_list()
->on('cp.person_id', '=', 'p.id')
->join(array('messages', 'm'), 'INNER')
->on('ping.message_id', '=', 'm.id')
->where('p.user_id', '=', $this->user->id);
->where('p.user_id', '=', $this->user->id)
->where('m.user_id', '=', $this->user->id); // Ensure I can only view pings I sent

if ( isset( $_GET['person_id'] ) AND $_GET['person_id'] != 0 )
{
Expand Down
7 changes: 6 additions & 1 deletion application/classes/Controller/Pongs.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public function action_ajax_list()
->on('c.id', '=', 'cp.contact_id')
->join(array('people', 'p'), 'INNER')
->on('cp.person_id', '=', 'p.id')
->where('p.user_id', '=', $this->user->id);
->join(array('pings', 'pi'), 'INNER')
->on('pong.ping_id', '=', 'pi.id')
->join(array('messages', 'm'), 'INNER')
->on('pi.message_id', '=', 'm.id')
->where('p.user_id', '=', $this->user->id)
->where('m.user_id', '=', $this->user->id); // Ensure one can only view pongs received by their contacts

if ( isset( $_GET['person_id'] ) AND $_GET['person_id'] != 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion application/classes/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function rules()
/**
* Filters
*
* @return array Rules
* @return array Filters
*/
public function filters()
{
Expand Down
23 changes: 23 additions & 0 deletions application/classes/Model/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Model_Person extends ORM {
'model' => 'Person',
'foreign_key' => 'parent_id',
),
'person_statuses' => array(),
);

/**
Expand All @@ -38,6 +39,11 @@ class Model_Person extends ORM {
protected $_created_column = array('column' => 'created', 'format' => 'Y-m-d H:i:s');
protected $_updated_column = array('column' => 'updated', 'format' => 'Y-m-d H:i:s');

/**
* Rules
*
* @return array Rules
*/
public function rules()
{
return array(
Expand All @@ -51,4 +57,21 @@ public function rules()
),
);
}

/**
* Filters
*
* @return array Filters
*/
public function filters()
{
return array(
'name' => array(
array('trim'),
),
'status' => array(
array('trim'),
),
);
}
}
41 changes: 41 additions & 0 deletions application/classes/Model/Person/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,50 @@ class Model_Person_Status extends ORM {
*/
protected $_belongs_to = array(
'person' => array(),
'pong' => array(),
'user' => array()
);

// Insert/Update Timestamps
protected $_created_column = array('column' => 'created', 'format' => 'Y-m-d H:i:s');
protected $_updated_column = array('column' => 'updated', 'format' => 'Y-m-d H:i:s');

/**
* Rules
*
* @return array Rules
*/
public function rules()
{
return array(
'person_id' => array(
array('not_empty'),
array('numeric'),
),
'note' => array(
array('max_length', array(':value', 255)),
),
'status' => array(
array('not_empty'),
array('in_array', array(':value', array('ok', 'notok', 'unknown')) ),
),
);
}

/**
* Filters
*
* @return array Filters
*/
public function filters()
{
return array(
'note' => array(
array('trim'),
),
'status' => array(
array('trim'),
),
);
}
}
1 change: 1 addition & 0 deletions application/classes/Model/Pong.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Model_Pong extends ORM {
protected $_belongs_to = array(
'contact' => array(),
'ping' => array(),
'person_statuses' => array(),
);

// Insert/Update Timestamps
Expand Down
2 changes: 1 addition & 1 deletion application/classes/PingApp/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function process($overview, $message)
->save();

// Lets parse the message for OK/NOT OKAY indicators
PingApp_Parse::status($contact, $pong, $message);
PingApp_Status::parse($contact, $pong, $message);

return TRUE;
}
Expand Down
72 changes: 0 additions & 72 deletions application/classes/PingApp/Parse.php

This file was deleted.

2 changes: 1 addition & 1 deletion application/classes/PingApp/SMS/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function receive($from = NULL, $message = NULL)
->save();

// Lets parse the message for OK/NOT OKAY indicators
PingApp_Parse::status($contact, $pong, $message);
PingApp_Status::parse($contact, $pong, $message);
}
else
{
Expand Down
Loading

0 comments on commit fdbb390

Please sign in to comment.