Beispiel #1
0
	/**
	 * @param TabTable[] $tabs
	 * @param UserTable  $user
	 * @param string     $reason
	 */
	public function tabsFetch( &$tabs, &$user, $reason )
	{
		static $rows								=	array();

		$checkUser									=	( $user && ( $user instanceof UserTable ) && ( ! $user->getError() ) );

		if ( ( ! Application::Cms()->getClientId() ) && ( ! cbprivacyClass::checkUserModerator() ) && ( $reason == 'profile' ) && $checkUser && ( Application::MyUser()->getUserId() != $user->get( 'id' ) ) ) {
			if ( $tabs ) foreach ( $tabs as $tabId => $tab ) {
				if ( isset( $tabs[$tabId] ) && ( ! cbprivacyClass::checkTabDisplayAccess( $tab, $user ) ) ) {
					unset( $tabs[$tabId] );
				}
			}
		} elseif ( ( $reason == 'editsave' ) && $checkUser && $user->get( 'id' ) ) {
			if ( $tabs ) foreach ( $tabs as $tab ) {
				if ( $tab instanceof TabTable ) {
					$userId							=	(int) $user->get( 'id' );
					$tabId							=	(int) $tab->get( 'tabid' );
					$value							=	implode( '|*|', cbprivacyClass::validatePrivacy( $this->input( 'privacy_tab_' . $tabId, '0', GetterInterface::RAW ) ) );

					if ( $value != '' ) {
						if ( ! ( $tab->params instanceof ParamsInterface ) ) {
							$tab->params			=	new Registry( $tab->params );
						}

						if ( ! isset( $rows[$userId][$tabId] ) ) {
							$row					=	new cbprivacyPrivacyTable();

							$row->load( array( 'user_id' => (int) $userId, 'type' => 'profile', 'subtype' => 'tab', 'item' => (int) $tabId ) );

							$rows[$userId][$tabId]	=	$row;
						}

						/** @var cbprivacyPrivacyTable $privacy */
						$privacy					=	$rows[$userId][$tabId];
						$rule						=	$privacy->get( 'rule', $tab->params->get( 'cbprivacy_display', '0' ) );

						if ( ( ! $privacy->get( 'id' ) ) || ( $rule != $value ) ) {
							if ( ! $privacy->get( 'id' ) ) {
								$privacy->set( 'user_id', (int) $user->get( 'id' ) );
								$privacy->set( 'type', 'profile' );
								$privacy->set( 'subtype', 'tab' );
								$privacy->set( 'item', (int) $tabId );
							}

							$privacy->set( 'rule', $value );

							$privacy->store();
						}
					}
				}
			}
		} elseif ( ( ! Application::Cms()->getClientId() ) && ( ! cbprivacyClass::checkUserModerator() ) && ( $reason == 'edit' ) && $checkUser && $user->get( 'id' ) ) {
			if ( $tabs ) foreach ( $tabs as $tabId => $tab ) {
				if ( isset( $tabs[$tabId] ) && ( ! cbprivacyClass::checkTabEditAccess( $tab ) ) ) {
					unset( $tabs[$tabId] );
				}
			}
		}
	}