/** * save notifications * * @param int $id * @param UserTable $user */ private function saveNotifications( $id, $user ) { global $_CB_framework; $row = new NotificationTable(); $isModerator = CBGroupJive::isModerator( $user->get( 'id' ) ); $group = CBGroupJive::getGroup( $id ); $row->load( array( 'user_id' => (int) $user->get( 'id' ), 'group' => (int) $group->get( 'id' ) ) ); $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ); if ( ! CBGroupJive::canAccessGroup( $group, $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( ! $this->params->get( 'notifications', 1 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to notifications in this group.' ), 'error' ); } elseif ( $row->get( 'id' ) && ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to edit this users notifications.' ), 'error' ); } elseif ( ! $isModerator ) { if ( ! CBGroupJive::canCreateGroupContent( $user, $group ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to notifications in this group.' ), 'error' ); } } $row->set( 'user_id', $row->get( 'user_id', (int) $user->get( 'id' ) ) ); $row->set( 'group', $row->get( 'group', (int) $group->get( 'id' ) ) ); foreach ( $this->getInput()->subTree( 'params' ) as $k => $v ) { if ( is_array( $v ) || is_object( $v ) ) { continue; } $k = Get::clean( $k, GetterInterface::COMMAND ); if ( $k ) { if ( is_numeric( $v ) ) { $v = (int) $this->input( 'post/params.' . $k, null, GetterInterface::INT ); } else { $v = $this->input( 'post/params.' . $k, null, GetterInterface::STRING ); } $row->params()->set( $k, $v ); } } $row->set( 'params', $row->params()->asJson() ); if ( $row->getError() || ( ! $row->check() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_NOTIFICATIONS_FAILED_TO_SAVE', 'Notifications failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupNotifications( $id, $user ); return; } if ( $row->getError() || ( ! $row->store() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_NOTIFICATIONS_FAILED_TO_SAVE', 'Notifications failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupNotifications( $id, $user ); return; } cbRedirect( $returnUrl, CBTxt::T( 'Notifications saved successfully!' ) ); }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdateUser', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreateUser', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } // Promote to group owner if status is changed to owner: if ( $this->get( 'status' ) == 4 ) { $group = CBGroupJive::getGroup( $this->get( 'group' ) ); if ( $group->get( 'id' ) && ( $group->get( 'user_id' ) != $this->get( 'user_id' ) ) ) { $group->set( 'user_id', (int) $this->get( 'user_id' ) ); $group->store(); } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdateUser', array( $this, $old ) ); } else { static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' ); $params = $_PLUGINS->getPluginParams( $plugin ); } // Set the default notifications: $notification = new NotificationTable(); $notification->load( array( 'user_id' => (int) $this->get( 'user_id' ), 'group' => (int) $this->get( 'group' ) ) ); $notification->set( 'user_id', (int) $this->get( 'user_id' ) ); $notification->set( 'group', (int) $this->get( 'group' ) ); $notifications = $notification->params(); $notifications->set( 'user_join', $params->get( 'notifications_default_user_join', 0 ) ); $notifications->set( 'user_leave', $params->get( 'notifications_default_user_leave', 0 ) ); $notifications->set( 'user_approve', $params->get( 'notifications_default_user_approve', 0 ) ); $notifications->set( 'user_cancel', $params->get( 'notifications_default_user_cancel', 0 ) ); $notifications->set( 'invite_accept', $params->get( 'notifications_default_invite_accept', 0 ) ); $notifications->set( 'invite_reject', $params->get( 'notifications_default_invite_reject', 0 ) ); $_PLUGINS->trigger( 'gj_onAfterCreateUser', array( $this, &$notifications ) ); $notification->set( 'params', $notifications->asJson() ); $notification->store(); } return true; }