예제 #1
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		$groups				=	( is_string( $this->get( 'groups' ) ) ? explode( '|*|', $this->get( 'groups' ) ) : $this->get( 'groups' ) );
		$users				=	( is_string( $this->get( 'users' ) ) ? json_decode( $this->get( 'users' ), true ) : $this->get( 'users' ) );

		foreach ( $users as $user ) {
			$userId			=	( isset( $user['user_id'] ) ? (int) $user['user_id'] : 0 );

			if ( ! $userId ) {
				continue;
			}

			foreach ( $groups as $group ) {
				$groupId	=	(int) $group;

				if ( ! $groupId ) {
					continue;
				}

				$row		=	new UserTable();

				$row->load( array( 'user_id' => $userId, 'group' => $groupId ) );

				$row->set( 'user_id', $userId );
				$row->set( 'group', $groupId );
				$row->set( 'status', ( isset( $user['user_id'] ) ? (int) $user['status'] : 1 ) );

				if ( $row->check() ) {
					$row->store();
				}
			}
		}

		if ( Application::Cms()->getClientId() ) {
			cbRedirect( 'index.php?option=com_comprofiler&view=showusers', CBTxt::T( 'Users successfully added to CB GroupJive groups!' ) );
		}

		return true;
	}
예제 #2
0
	/**
	 * add or remove forum category moderators
	 *
	 * @param \CB\Plugin\GroupJive\Table\UserTable $row
	 */
	public function storeModerator( $row )
	{
		if ( ( ! $this->_forumModel ) || CBGroupJive::isModerator( $row->get( 'user_id' ) ) ) {
			return;
		}

		$category		=	$this->_forumModel->getCategory( (int) $row->group()->params()->get( 'forum_id' ) );

		if ( ! $category->get( 'id' ) ) {
			return;
		}

		$moderators		=	$category->moderators();

		if ( $row->get( 'status' ) >= 2 ) {
			if ( ! in_array( $row->get( 'user_id' ), $moderators ) ) {
				$category->moderators( $row->get( 'user_id' ) );
			}
		} else {
			if ( in_array( $row->get( 'user_id' ), $moderators ) ) {
				$category->moderators( null, $row->get( 'user_id' ) );
			}
		}
	}
예제 #3
0
	/**
	 * @return bool
	 */
	public function accept()
	{
		if ( $this->accepted() ) {
			return true;
		}

		$row	=	new UserTable();

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

		if ( ! $row->get( 'id' ) ) {
			$row->set( 'user_id', (int) $this->get( 'user_id' ) );
			$row->set( 'group', (int) $this->get( 'group' ) );
			$row->set( 'status', 1 );

			if ( ! $row->store() ) {
				$this->setError( $row->getError() );

				return false;
			}
		}

		$this->set( 'accepted', Application::Database()->getUtcDateTime() );

		if ( ! $this->store() ) {
			return false;
		}

		return true;
	}
예제 #4
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_CB_framework, $_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_onBeforeUpdateGroup', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onBeforeCreateGroup', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! CBGroupJive::uploadImage( 'canvas', $this ) ) {
			return false;
		}

		if ( ! CBGroupJive::uploadImage( 'logo', $this ) ) {
			return false;
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		// If the new owner doesn't match the previous then demote (frontend) or delete (backend) the previous:
		if ( $old->get( 'id' ) ) {
			if ( $old->get( 'user_id' ) != $this->get( 'user_id' ) ) {
				$previousUser	=	new UserTable();

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

				if ( $previousUser->get( 'id' ) ) {
					if ( Application::Cms()->getClientId() ) {
						if ( ! $previousUser->delete() ) {
							$this->setError( $previousUser->getError() );

							return false;
						}
					} else {
						$previousUser->set( 'status', 1 );

						if ( ! $previousUser->store() ) {
							$this->setError( $previousUser->getError() );

							return false;
						}
					}
				}
			}
		}

		$user				=	new UserTable();

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

		// If the owner doesn't exist or isn't marked owner then create them or promote them to owner:
		if ( ( ! $user->get( 'id' ) ) || ( $user->get( 'status' ) != 4 ) ) {
			$user->set( 'user_id', (int) $this->get( 'user_id' ) );
			$user->set( 'group', (int) $this->get( 'id' ) );
			$user->set( 'status', 4 );

			if ( $user->getError() || ( ! $user->store() ) ) {
				$this->setError( $user->getError() );

				return false;
			}
		}

		// If the category is changed be sure to move the canvas and logo as needed:
		if ( $old->get( 'id' ) && ( $this->get( 'canvas' ) || $this->get( 'logo' ) ) && ( $old->get( 'category' ) != $this->get( 'category' ) ) ) {
			$basePath		=	$_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive';
			$oldPath		=	$basePath . '/' . (int) $old->get( 'category' ) . '/' . (int) $this->get( 'id' );
			$newPath		=	$basePath . '/' . (int) $this->get( 'category' ) . '/' . (int) $this->get( 'id' );

			if ( is_dir( $oldPath ) ) {
				CBGroupJive::createDirectory( $basePath, $this->get( 'category' ), $this->get( 'id' ) );
				CBGroupJive::copyDirectory( $oldPath, $newPath, true );
			}
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'gj_onAfterUpdateGroup', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onAfterCreateGroup', array( $this ) );
		}

		return true;
	}