-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ushahidi/groups-dev
Groups Setup
- Loading branch information
Showing
15 changed files
with
459 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php defined('SYSPATH') OR die('No direct access allowed.'); | ||
|
||
/** | ||
* Groups Controller | ||
* | ||
* @author Ushahidi Team <[email protected]> | ||
* @package Ushahidi\Application\Controllers | ||
* @copyright Ushahidi - http://www.ushahidi.com | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License Version 3 (GPLv3) | ||
*/ | ||
class Controller_Groups extends Controller_PingApp { | ||
|
||
/** | ||
* List all Groups | ||
* | ||
* @return void | ||
*/ | ||
public function action_index() | ||
{ | ||
$this->template->content = View::factory('pages/groups/list') | ||
->bind('groups', $groups); | ||
|
||
$groups = $this->user->groups | ||
->select(array(DB::expr('COUNT(gp.person_id)'), 'people')) | ||
->join(array('groups_people', 'gp'), 'LEFT') | ||
->on('gp.group_id', '=', 'group.id') | ||
->join(array('people', 'p'), 'LEFT') | ||
->on('p.id', '=', 'gp.person_id') | ||
->group_by('group.id') | ||
->order_by('name', 'ASC') | ||
->find_all(); | ||
} | ||
|
||
/** | ||
* Add/Edit Group | ||
* | ||
* @return void | ||
*/ | ||
public function action_edit() | ||
{ | ||
$this->template->content = View::factory('pages/groups/edit') | ||
->bind('group', $group) | ||
->bind('post', $post) | ||
->bind('errors', $errors) | ||
->bind('done', $done); | ||
|
||
$group_id = $this->request->param('id', 0); | ||
$group = ORM::factory('Group') | ||
->where('id', '=', $group_id) | ||
->where('user_id', '=', $this->user->id) | ||
->find(); | ||
|
||
if ( ! empty($_POST) ) | ||
{ | ||
$post = $_POST; | ||
|
||
try | ||
{ | ||
// Save Group | ||
$group->values($post, array( | ||
'name', | ||
)); | ||
$group->check(); | ||
$group->user_id = $this->user->id; | ||
$group->save(); | ||
|
||
// Redirect to prevent repost | ||
HTTP::redirect('groups/edit/'.$group->id.'?done'); | ||
} | ||
catch (ORM_Validation_Exception $e) | ||
{ | ||
$errors = Arr::flatten($e->errors('models')); | ||
} | ||
} | ||
else | ||
{ | ||
if ( $group->loaded() ) | ||
{ | ||
$post = $group->as_array(); | ||
} | ||
|
||
$done = (isset($_GET['done'])) ? TRUE : FALSE; | ||
} | ||
} | ||
|
||
/** | ||
* Delete A Group | ||
* | ||
* @return void | ||
*/ | ||
public function action_delete() | ||
{ | ||
$group_id = $this->request->param('id', 0); | ||
|
||
$group = ORM::factory('Group') | ||
->where('id', '=', $group_id) | ||
->where('user_id', '=', $this->user->id) | ||
->find(); | ||
|
||
if ( $group->loaded() ) | ||
{ | ||
$group->delete(); | ||
HTTP::redirect('groups'); | ||
} | ||
else | ||
{ | ||
HTTP::redirect('groups'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
return array( | ||
|
||
'driver' => 'ORM', | ||
'hash_method' => 'sha256', | ||
'hash_key' => 'somereallylongkey', | ||
'lifetime' => 1209600, | ||
'session_type' => Session::$default, | ||
'session_key' => 'auth_user', | ||
|
||
// Username/password combinations for the Auth File driver | ||
'users' => array( | ||
// 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02', | ||
'admin' => '' | ||
), | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php defined('SYSPATH') or die('No direct access allowed.'); | ||
|
||
/** | ||
* Database Config | ||
* | ||
* @author Ushahidi Team <[email protected]> | ||
* @package Ushahidi\Application | ||
* @copyright Ushahidi - http://www.ushahidi.com | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License Version 3 (GPLv3) | ||
*/ | ||
|
||
return array | ||
( | ||
'default' => array | ||
( | ||
'type' => 'MySQL', | ||
'connection' => array( | ||
'hostname' => 'localhost', | ||
'database' => 'pingapp_test', | ||
'username' => 'root', | ||
'password' => '', | ||
'persistent' => FALSE, | ||
), | ||
'table_prefix' => '', | ||
'charset' => 'utf8', | ||
'caching' => TRUE, | ||
'profiling' => TRUE, | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php defined('SYSPATH') OR die('No direct script access.'); | ||
|
||
class Migration_1_20131001183143 extends Minion_Migration_Base { | ||
|
||
/** | ||
* Run queries needed to apply this migration | ||
* | ||
* @param Kohana_Database $db Database connection | ||
*/ | ||
public function up(Kohana_Database $db) | ||
{ | ||
/** | ||
* Groups_People Table | ||
*/ | ||
$db->query(NULL, "DROP TABLE IF EXISTS `groups_people`;"); | ||
$db->query(NULL, "CREATE TABLE `groups_people` ( | ||
`group_id` int(11) unsigned NOT NULL DEFAULT '0', | ||
`person_id` int(11) unsigned NOT NULL, | ||
PRIMARY KEY (`group_id`,`person_id`), | ||
CONSTRAINT `fk_groups_people_group_id` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE, | ||
CONSTRAINT `fk_groups_people_person_id` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ON DELETE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); | ||
|
||
// Drop group_id column from people | ||
$db->query(NULL, "ALTER TABLE `people` DROP `group_id`;"); | ||
|
||
} | ||
|
||
/** | ||
* Run queries needed to remove this migration | ||
* | ||
* @param Kohana_Database $db Database connection | ||
*/ | ||
public function down(Kohana_Database $db) | ||
{ | ||
$db->query(NULL, "ALTER TABLE `people` ADD `group_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' AFTER `user_id`;"); | ||
$db->query(NULL, "ALTER TABLE `people` ADD INDEX `idx_group_id` (`group_id`);"); | ||
|
||
$db->query(NULL, "DROP TABLE IF EXISTS `groups_people`;"); | ||
} | ||
|
||
} |
Oops, something went wrong.