Skip to content

Commit

Permalink
moving social settings page to use newly abstracted logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jondavidjohn committed Sep 12, 2012
1 parent 3db26b7 commit b46bd3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
27 changes: 8 additions & 19 deletions lib/social/service/facebook.php
Expand Up @@ -594,31 +594,20 @@ public static function social_settings_save($controller) {
define('IS_PROFILE_PAGE', true);
}

$enabled_pages = $controller->request()->post('social_enabled_pages');
$enabled_child_ids = $controller->request()->post('social_enabled_child_accounts');
if (!is_array($enabled_pages)) {
$enabled_pages = array();
$enabled_child_ids = array();
}
$service = $controller->social()->service('facebook');
if ($service !== false) {
$fb_accounts = $service->accounts();
foreach ($fb_accounts as $account) {
// reset pages for account
$fb_accounts[$account->id()]->pages(array(), $is_profile);
if (count($enabled_pages) && isset($enabled_pages[$account->id()])) {
// fetch available pages for account
$pages = $service->get_pages($account, $is_profile);
foreach ($enabled_pages[$account->id()] as $enabled_page_id) {
if (isset($pages[$enabled_page_id])) {
$fb_accounts[$account->id()]->page($pages[$enabled_page_id], $is_profile);
}
}
foreach ($service->accounts() as $account) {
$updated_accounts = array();
foreach ($service->accounts() as $account) {
$account->update_enabled_child_accounts($enabled_child_ids);
$updated_accounts[$account->id()] = $account->as_object();
}

}
foreach ($fb_accounts as $account_id => $account) {
$fb_accounts[$account_id] = $account->as_object();
$service->accounts($updated_accounts)->save($is_profile);
}
$service->accounts($fb_accounts)->save($is_profile);
}
}

Expand Down
3 changes: 1 addition & 2 deletions social.php
Expand Up @@ -739,9 +739,8 @@ public function personal_options_update($user_id) {
$is_profile = true;
$enabled_child_accounts = is_array($_POST['social_enabled_child_accounts']) ? $_POST['social_enabled_child_accounts'] : array();
foreach ($this->services() as $key => $service) {
$accounts = $service->accounts();
$updated_accounts = array();
foreach ($accounts as $account) {
foreach ($service->accounts() as $account) {
$account->update_enabled_child_accounts($enabled_account_ids);
$updated_accounts[$account->id()] = $account->as_object();
}
Expand Down

0 comments on commit b46bd3b

Please sign in to comment.