Created
December 13, 2012 16:56
-
-
Save tubalmartin/4277904 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php if (!defined('BASEPATH')) exit('No direct access allowed.'); | |
class Profiles extends Auth_Controller | |
{ | |
protected $_view_path = 'profiles/'; | |
public function __construct() | |
{ | |
parent::__construct(); | |
// Only public methods matter | |
$this->ACL = array( | |
'bloggers' => array('allow' => array('password','blogger')), | |
'brands' => array('allow' => array('password','brand')), | |
'admins' => array('allow' => '*') | |
); | |
} | |
// SHARED EXCEPTIONS | |
// ------------------------------------------------------------------------- | |
public function password() | |
{ | |
$data['min_password_length'] = $this->config->item('min_password_length', 'ion_auth'); | |
$this->layout->show('private/'.UG_SNAME.'/profile/change_password', $data); | |
} | |
// ROLE BASED ROUTING | |
// ------------------------------------------------------------------------- | |
public function blogger() | |
{ | |
// Flexible arguments | |
$args = func_get_args(); | |
// Action & Default action | |
$action = isset_or($args[0], 'view'); | |
// If unknown action, show a 404 | |
get_or_404(in_array($action, array('edit', 'validate', 'update', 'view'))); | |
// Method name prefix | |
$func_prefix = '_blogger_'.$action; | |
switch($action) | |
{ | |
// User Profile | |
case 'edit': | |
case 'validate': | |
$what = isset_or($args[1], 'personal'); | |
$func = $func_prefix.'_'.$what.'_info'; | |
break; | |
// Social profile / stats | |
case 'update': | |
// todo | |
break; | |
case 'view': | |
// todo | |
} | |
// If method does not exist, show a 404 | |
get_or_404(method_exists($this, $func)); | |
// Call method with all arguments: it's up to each method to retrieve them | |
$this->$func($args); | |
} | |
public function brand() | |
{ | |
// Flexible arguments | |
$args = func_get_args(); | |
// Action & Default action | |
$action = isset_or($args[0], 'view'); | |
// If unknown action, show a 404 | |
get_or_404(in_array($action, array('edit', 'validate', 'view'))); | |
// Method name prefix | |
$func_prefix = '_brand_'.$action; | |
switch($action) | |
{ | |
// User Profile | |
case 'edit': | |
case 'validate': | |
$what = isset_or($args[1], 'company'); | |
$func = $func_prefix.'_'.$what.'_info'; | |
break; | |
// Profile view | |
case 'view': | |
// todo | |
} | |
// If method does not exist, show a 404 | |
get_or_404(method_exists($this, $func)); | |
// Call method with all arguments: it's up to each method to retrieve them | |
$this->$func($args); | |
} | |
public function admin() | |
{ | |
// Flexible arguments | |
$args = func_get_args(); | |
// Action & Default action | |
$action = isset_or($args[0], 'edit'); | |
// If unknown action, show a 404 | |
get_or_404(in_array($action, array('edit', 'validate'))); | |
// Method name prefix | |
$func_prefix = '_admin_'.$action; | |
switch($action) | |
{ | |
// Admin Profile | |
case 'edit': | |
case 'validate': | |
$what = isset_or($args[1], 'personal'); | |
$func = $func_prefix.'_'.$what.'_info'; | |
} | |
// If method does not exist, show a 404 | |
get_or_404(method_exists($this, $func)); | |
// Call method with all arguments: it's up to each method to retrieve them | |
$this->$func($args); | |
} | |
// BLOGGERS | |
// ------------------------------------------------------------------------- | |
// DISPLAY | |
private function _blogger_edit_personal_info() | |
{ | |
$data['profile'] = $this->blogger->get_profile(); | |
$data['countries'] = $this->common->get_countries_dropdown(); | |
$this->layout->show('private/blogger/profile/personal_info', $data); | |
} | |
private function _blogger_edit_blog_info() | |
{ | |
$data['profile'] = $this->blogger->get_profile(); | |
$data['languages'] = $this->common->get_languages_dropdown(); | |
$data['blog_categories'] = $this->common->get_blog_categories(); | |
$data['selected_blog_categories'] = array( | |
$data['profile']->blog_category_id1, | |
$data['profile']->blog_category_id2, | |
$data['profile']->blog_category_id3 | |
); | |
$this->layout->show('private/blogger/profile/blog_info', $data); | |
} | |
private function _blogger_edit_social_info() | |
{ | |
$data['profile'] = $this->blogger->get_profile(); | |
$this->layout->show('private/blogger/profile/social_info', $data); | |
} | |
// VALIDATE | |
private function _blogger_validate_personal_info() | |
{ | |
if ($this->blogger->validate_personal_info()) | |
{ | |
// Save/Update data in model | |
if ($this->blogger->save_personal_info()) | |
{ | |
message(_l('data_save_success', _l('personal_info'))); | |
redirect('profiles/blogger/edit/personal'); | |
} | |
} | |
// Show validation errors (do NOT redirect!) | |
$this->_blogger_edit_personal_info(); | |
} | |
private function _blogger_validate_blog_info() | |
{ | |
if ($this->blogger->validate_blog_info()) | |
{ | |
// Save/Update data in model | |
if ($this->blogger->save_blog_info()) | |
{ | |
message(_l('data_save_success', _l('blog_info'))); | |
redirect('profiles/blogger/edit/blog'); | |
} | |
} | |
// Show validation errors (do NOT redirect!) | |
$this->_blogger_edit_blog_info(); | |
} | |
// BRANDS | |
// ------------------------------------------------------------------------- | |
// DISPLAY | |
private function _brand_edit_company_info() | |
{ | |
$data['profile'] = $this->brand->get_profile(); | |
$this->layout->show('private/brand/profile/company_info', $data); | |
} | |
private function _brand_edit_contact_info() | |
{ | |
$data['profile'] = $this->brand->get_profile(); | |
$data['countries'] = $this->common->get_countries_dropdown(); | |
$this->layout->show('private/brand/profile/contact_info', $data); | |
} | |
// VALIDATE | |
private function _brand_validate_company_info() | |
{ | |
if ($this->brand->validate_company_info()) | |
{ | |
// Save/Update data in model | |
if ($this->brand->save_company_info()) | |
{ | |
message(_l('data_save_success', _l('company_info'))); | |
redirect('profiles/brand/edit/company'); | |
} | |
} | |
// Show validation errors | |
$this->_brand_edit_company_info(); | |
} | |
private function _brand_validate_contact_info() | |
{ | |
if ($this->brand->validate_contact_info()) | |
{ | |
// Save/Update data in model | |
if ($this->brand->save_contact_info()) | |
{ | |
message(_l('data_save_success', _l('contact_info'))); | |
redirect('profiles/brand/edit/contact'); | |
} | |
} | |
// Show validation errors | |
$this->_brand_edit_contact_info(); | |
} | |
// ADMIN | |
// ------------------------------------------------------------------------- | |
// DISPLAY | |
private function _admin_edit_personal_info() | |
{ | |
$data['profile'] = $this->admin->get_profile(); | |
$this->layout->show('private/admin/profile/personal_info', $data); | |
} | |
// VALIDATE | |
private function _admin_validate_personal_info() | |
{ | |
if ($this->admin->validate_personal_info()) | |
{ | |
// Save/Update data in model | |
if ($this->admin->save_personal_info()) | |
{ | |
message(_l('data_save_success', _l('personal_info'))); | |
redirect('profiles/admin/edit/personal'); | |
} | |
} | |
// Show validation errors (do NOT redirect!) | |
$this->_admin_edit_personal_info(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment