/**
	 * set group user status
	 *
	 * @param int       $status
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function statusUser( $status, $id, $user )
	{
		global $_CB_framework;

		$row						=	new \CB\Plugin\GroupJive\Table\UserTable();

		$row->load( (int) $id );

		$returnUrl					=	$_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->group()->get( 'id' ) ) );

		if ( $row->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( $row->get( 'user_id' ) == $row->group()->get( 'user_id' ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'You can not promote or demote the group owner.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( $user->get( 'id' ) == $row->get( 'user_id' ) ) {
					cbRedirect( $returnUrl, CBTxt::T( 'You can not promote or demote your self.' ), 'error' );
				} elseif ( $user->get( 'id' ) != $row->group()->get( 'user_id' ) ) {
					$userStatus		=	CBGroupJive::getGroupStatus( $user, $row->group() );

					if ( ( $row->get( 'status' ) > $userStatus ) || ( ( $userStatus <= 1 ) && in_array( $status, array( -1, 1 ) ) ) || ( ( $userStatus <= 2 ) && ( $status == 2 ) ) || in_array( $status, array( 0, 3, 4 ) ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to promote or demote this user.' ), 'error' );
					}
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'User does not exist.' ), 'error' );
		}

		$currentStatus				=	(int) $row->get( 'status' );

		$row->set( 'status', (int) $status );

		if ( $row->getError() || ( ! $row->store() ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_USER_STATUS_FAILED_TO_SAVE', 'User status failed to saved. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		if ( $status && ( $currentStatus == 0 ) ) {
			if ( $row->get( 'user_id' ) != $user->get( 'id' ) ) {
				CBGroupJive::sendNotification( 4, $user, (int) $row->get( 'user_id' ), CBTxt::T( 'Group join request accepted' ), CBTxt::T( 'Your join request to group [group] has been accepted!' ), $row->group() );
			}

			CBGroupJive::sendNotifications( 'user_join', CBTxt::T( 'User joined a mutual group' ), CBTxt::T( '[user] has joined the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), null, array( $user->get( 'id' ) ) );
		}

		cbRedirect( $returnUrl, CBTxt::T( 'User status saved successfully!' ) );
	}
示例#2
0
	/**
	 * Auto accepts invites on registration
	 *
	 * @param  UserTable $user
	 */
	public function acceptInvites( $user )
	{
		global $_CB_database;

		if ( $this->params->get( 'groups_invites_accept', 1 ) ) {
			$query					=	'SELECT *'
									.	"\n FROM " . $_CB_database->NameQuote( '#__groupjive_invites' )
									.	"\n WHERE " . $_CB_database->NameQuote( 'accepted' ) . ' = ' . $_CB_database->Quote( '0000-00-00 00:00:00' )
									.	"\n AND ( ( " . $_CB_database->NameQuote( 'email' ) . ' = ' . $_CB_database->Quote( $user->get( 'email' ) )
									.	' AND ' . $_CB_database->NameQuote( 'email' ) . ' != "" )'
									.	' OR ( ' . $_CB_database->NameQuote( 'user' ) . ' = ' . (int) $user->get( 'id' )
									.	' AND ' . $_CB_database->NameQuote( 'user' ) . ' > 0 ) )';
			$_CB_database->setQuery( $query );
			$invites				=	$_CB_database->loadObjectList( null, '\CB\Plugin\GroupJive\Table\InviteTable', array( $_CB_database ) );

			$notified				=	array();

			/** @var InviteTable[] $invites */
			foreach ( $invites as $invite ) {
				if ( $invite->accept() && ( ! in_array( $invite->get( 'user_id' ), $notified ) ) ) {
					CBGroupJive::sendNotifications( 'invite_accept', CBTxt::T( 'Group invite accepted' ), CBTxt::T( 'Your group [group] invite to [user] has been accepted!' ), $invite->group(), $user, (int) $invite->get( 'user_id' ), $notified );

					$notified[]		=	$invite->get( 'user_id' );
				}
			}
		}
	}
	/**
	 * unattend event
	 *
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function unattendEvent( $id, $user )
	{
		global $_CB_framework;

		$event				=	CBGroupJiveEvents::getEvent( (int) $id );
		$returnUrl			=	$_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $event->get( 'group' ) ) );

		if ( $event->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $event->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( ( $event->get( 'published' ) != 1 ) && ( CBGroupJive::getGroupStatus( $user, $event->group() ) < 2 ) ) {
					cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to this event.' ), 'error' );
				} elseif ( CBGroupJive::getGroupStatus( $user, $event->group() ) < 1 ) {
					cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to unattend this event.' ), 'error' );
				} elseif ( $event->status() == 1 ) {
					cbRedirect( $returnUrl, CBTxt::T( 'You can not unattend an expired event.' ), 'error' );
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'Event does not exist.' ), 'error' );
		}

		$row				=	new AttendanceTable();

		$row->load( array( 'user_id' => (int) $user->get( 'id' ), 'event' => (int) $event->get( 'id' ) ) );

		if ( ! $row->get( 'id' ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'You can not unattend an event you are not attending.' ), 'error' );
		}

		if ( ! $row->canDelete() ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_FAILED_TO_UNATTEND', 'Event failed to unattend. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		if ( ! $row->delete() ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_FAILED_TO_UNATTEND', 'Event failed to unattend. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		$extras				=	array(	'event_title'	=>	htmlspecialchars( $event->get( 'title' ) ),
										'event'			=>	'<a href="' . $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $event->get( 'group' ), 'tab' => 'grouptabevents' ) ) . '">' . htmlspecialchars( CBTxt::T( $event->get( 'title' ) ) ) . '</a>' );

		CBGroupJive::sendNotifications( 'event_unattend', CBTxt::T( 'User unattended your group event' ), CBTxt::T( '[user] will no longer be attending your event [event] in the group [group]!' ), $event->group(), $user, (int) $event->get( 'user_id' ), array(), 1, $extras );

		cbRedirect( $returnUrl, CBTxt::T( 'Event unattended successfully!' ) );
	}
	/**
	 * set wall publish state status
	 *
	 * @param int       $state
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function stateWall( $state, $id, $user )
	{
		global $_CB_framework;

		$row				=	CBGroupJiveWall::getPost( (int) $id );
		$returnUrl			=	$_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ) ) );

		if ( $row->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) {
					if ( ( $user->get( 'id' ) == $row->get( 'user_id' ) ) && ( $row->get( 'published' ) == -1 ) && ( $row->group()->params()->get( 'wall', 1 ) == 2 ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'Your post is awaiting approval.' ), 'error' );
					} elseif ( ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to publish or unpublish this post.' ), 'error' );
					}
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'Post does not exist.' ), 'error' );
		}

		$currentState		=	(int) $row->get( 'published' );

		$row->set( 'published', (int) $state );

		if ( $row->getError() || ( ! $row->store() ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_POST_STATE_FAILED_TO_SAVE', 'Post state failed to saved. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		if ( $state && ( $currentState == -1 ) ) {
			if ( $row->get( 'user_id' ) != $user->get( 'id' ) ) {
				CBGroupJive::sendNotification( 4, $user, (int) $row->get( 'user_id' ), CBTxt::T( 'Wall post request accepted' ), CBTxt::T( 'Your wall post request in the group [group] has been accepted!' ), $row->group() );
			}

			if ( $row->reply()->get( 'id' ) ) {
				CBGroupJive::sendNotifications( 'wall_reply', CBTxt::T( 'New group post reply' ), CBTxt::T( '[user] has posted a reply on the wall in the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), (int) $row->reply()->get( 'user_id' ), array( $user->get( 'id' ) ) );
			} else {
				CBGroupJive::sendNotifications( 'wall_new', CBTxt::T( 'New group post' ), CBTxt::T( '[user] has posted on the wall in the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), null, array( $user->get( 'id' ) ) );
			}
		}

		cbRedirect( $returnUrl, CBTxt::T( 'Post state saved successfully!' ) );
	}
	/**
	 * set file publish state status
	 *
	 * @param int       $state
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function stateFile( $state, $id, $user )
	{
		global $_CB_framework;

		$row				=	CBGroupJiveFile::getFile( (int) $id );
		$returnUrl			=	$_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ) ) );

		if ( $row->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) {
					if ( ( $user->get( 'id' ) == $row->get( 'user_id' ) ) && ( $row->get( 'published' ) == -1 ) && ( $row->group()->params()->get( 'file', 1 ) == 2 ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'Your file is awaiting approval.' ), 'error' );
					} elseif ( ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to publish or unpublish this file.' ), 'error' );
					}
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'File does not exist.' ), 'error' );
		}

		$currentState		=	(int) $row->get( 'published' );

		$row->set( 'published', (int) $state );

		if ( $row->getError() || ( ! $row->store() ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_FILE_STATE_FAILED_TO_SAVE', 'File state failed to saved. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		if ( $state && ( $currentState == -1 ) ) {
			$extras			=	array(	'file_title'	=>	htmlspecialchars( ( $row->get( 'title' ) ? $row->get( 'title' ) : $row->name() ) ),
										'file'			=>	'<a href="' . $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ), 'tab' => 'grouptabfile' ) ) . '">' . htmlspecialchars( ( $row->get( 'title' ) ? $row->get( 'title' ) : $row->name() ) ) . '</a>' );

			if ( $row->get( 'user_id' ) != $user->get( 'id' ) ) {
				CBGroupJive::sendNotification( 4, $user, (int) $row->get( 'user_id' ), CBTxt::T( 'File upload request accepted' ), CBTxt::T( 'Your file [file] upload request in the group [group] has been accepted!' ), $row->group(), $extras );
			}

			CBGroupJive::sendNotifications( 'file_new', CBTxt::T( 'New group file' ), CBTxt::T( '[user] has uploaded the file [file] in the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), null, array( $user->get( 'id' ) ), 1, $extras );
		}

		cbRedirect( $returnUrl, CBTxt::T( 'File state saved successfully!' ) );
	}