/**
	 * 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!' ) );
	}
Beispiel #2
0
	/**
	 * @param null|int $id
	 * @return bool
	 */
	public function delete( $id = null )
	{
		global $_PLUGINS;

		$_PLUGINS->trigger( 'gj_onBeforeDeleteUser', array( &$this ) );

		if ( ! parent::delete( $id ) ) {
			return false;
		}

		static $params			=	null;

		if ( ! $params ) {
			$plugin				=	$_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' );
			$params				=	$_PLUGINS->getPluginParams( $plugin );
		}

		if ( ( ! CBGroupJive::isModerator( $this->get( 'user_id' ) ) ) && $params->get( 'groups_delete', 1 ) ) {
			// Delete this users group invites (to and from):
			$query				=	'SELECT *'
								.	"\n FROM " . $this->getDbo()->NameQuote( '#__groupjive_invites' )
								.	"\n WHERE " . $this->getDbo()->NameQuote( 'group' ) . " = " . (int) $this->get( 'group' )
								.	"\n AND ( " . $this->getDbo()->NameQuote( 'user_id' ) . " = " . (int) $this->get( 'user_id' )
								.	"\n OR " . $this->getDbo()->NameQuote( 'user' ) . " = " . (int) $this->get( 'user_id' ) . " )";
			$this->getDbo()->setQuery( $query );
			$invites			=	$this->getDbo()->loadObjectList( null, '\CB\Plugin\GroupJive\Table\InviteTable', array( $this->getDbo() ) );

			/** @var InviteTable[] $invites */
			foreach ( $invites as $invite ) {
				$invite->delete();
			}

			// Delete this users group notifications:
			$notification		=	new NotificationTable();

			$notification->load( array( 'user_id' => (int) $this->get( 'user_id' ), 'group' => (int) $this->get( 'group' ) ) );

			if ( $notification->get( 'id' ) ) {
				$notification->delete();
			}
		}

		$_PLUGINS->trigger( 'gj_onAfterDeleteUser', array( $this ) );

		return true;
	}