예제 #1
0
	/**
	 * @param string         $source
	 * @param null|UserTable $user
	 * @return Tags|null
	 */
	public function tags( $source = 'stream', $user = null )
	{
		$params				=	$this->params()->subTree( 'tags' );

		if ( ! $params->get( 'display', 1 ) ) {
			return null;
		}

		/** @var Tags[] $cache */
		static $cache		=	array();

		if ( $this->get( 'item' ) && $params->get( 'source', 1 ) ) {
			$id				=	$this->get( 'type' ) . $this->get( 'subtype' ) . $this->get( 'item' ) . $this->get( 'parent' );
		} else {
			$id				=	$this->get( 'id' );
		}

		$id					=	md5( $id . $source . ( $user ? $user->get( 'id' ) : null ) . Application::MyUser()->getUserId() );

		if ( ! isset( $cache[$id] ) ) {
			$stream			=	new Tags( $source, $user );

			if ( $this->get( 'item' ) && $params->get( 'source', 1 ) ) {
				$stream->set( 'type', $this->get( 'type' ) );
				$stream->set( 'subtype', $this->get( 'subtype' ) );
				$stream->set( 'item', $this->get( 'item' ) );
				$stream->set( 'parent', $this->get( 'parent' ) );
			} else {
				$stream->set( 'type', 'activity' );
				$stream->set( 'item', (int) $this->get( 'id' ) );
			}

			$object			=	array(	'source'	=>	'activity',
										'id'		=>	(int) $this->get( 'id' ),
										'user_id'	=>	(int) $this->get( 'user_id' ),
										'type'		=>	$this->get( 'type' ),
										'subtype'	=>	$this->get( 'subtype' ),
										'item'		=>	$this->get( 'item' ),
										'parent'	=>	$this->get( 'parent' )
									);

			$stream->set( 'object', $object );

			$cache[$id]		=	$stream;
		}

		return $cache[$id];
	}
	/**
	 * Displays tags stream
	 *
	 * @param int       $id
	 * @param Tags      $stream
	 * @param int       $output
	 * @param bool      $data
	 * @param UserTable $user
	 * @param UserTable $viewer
	 */
	private function showTags( $id, $stream, $output, $data, $user, $viewer )
	{
		CBActivity::getTemplate( 'tags', false, false );

		if ( $id ) {
			$stream->set( 'id', $id );

			$rows			=	$stream->data();
		} else {
			if ( $data ) {
				$count		=	$stream->data( true );

				if ( ! $count ) {
					$rows	=	array();
				} else {
					$rows	=	$stream->data();
				}
			} else {
				$rows		=	array();
			}
		}

		if ( $rows ) {
			CBActivity::preFetchUsers( $rows );
		}

		echo HTML_cbactivityTags::showTags( $rows, $stream, $output, $user, $viewer, $this );
	}