Jump to content

New optional parameter on item contentCount


Adriano Faria

Recommended Posts

Can you please add a new optional parameter on item contentCount? I have a setting in one my resources that exclude records on category view based in some columns. So it works fine on category view:

Capturar1.png

But it keeps showing the counter on sidebar categories:

Capturar.png

I thought on a new array parameter where you can inform your columns.

That would help a lot and would avoid hooks in IPS\Content\Item::contentCount() or is there anything easier out there that I'm missing?

Tks.

Link to comment
Share on other sites

2 minutes ago, Martin A. said:

You can just add contentCount() to your own item class and count it the way you want.

True. I see an example in Gallery:

	/**
	 * Total item count (including children)
	 *
	 * @param	\IPS\Node\Model	$container			The container
	 * @param	bool			$includeItems		If TRUE, items will be included (this should usually be true)
	 * @param	bool			$includeComments	If TRUE, comments will be included
	 * @param	bool			$includeReviews		If TRUE, reviews will be included
	 * @param	int				$depth				Used to keep track of current depth to avoid going too deep
	 * @return	int|NULL|string	When depth exceeds 10, will return "NULL" and initial call will return something like "100+"
	 * @note	This method may return something like "100+" if it has lots of children to avoid exahusting memory. It is intended only for display use
	 * @note	This method includes counts of hidden and unapproved content items as well
	 */
	public static function contentCount( \IPS\Node\Model $container, $includeItems=TRUE, $includeComments=FALSE, $includeReviews=FALSE, $depth=0 )
	{
		if( !$container->nonpublic_albums )
		{
			return parent::contentCount( $container, $includeItems, $includeComments, $includeReviews, $depth );
		}

		$count = static::getItemsWithPermission( array( array( 'gallery_images.image_category_id=?', $container->_id ) ), NULL, 1, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );

		$_key = md5( get_class( $container ) . $container->_id );
		static::$itemCounts[ $_key ][ $container->_id ] = $count;

		return parent::contentCount( $container, $includeItems, $includeComments, $includeReviews, $depth );
	}

Tks.

Link to comment
Share on other sites

Working for me:

	/**
	 * Total item count (including children)
	 *
	 * @param	\IPS\Node\Model	$container			The container
	 * @param	bool			$includeItems		If TRUE, items will be included (this should usually be true)
	 * @param	bool			$includeComments	If TRUE, comments will be included
	 * @param	bool			$includeReviews		If TRUE, reviews will be included
	 * @param	int				$depth				Used to keep track of current depth to avoid going too deep
	 * @return	int|NULL|string	When depth exceeds 10, will return "NULL" and initial call will return something like "100+"
	 * @note	This method may return something like "100+" if it has lots of children to avoid exahusting memory. It is intended only for display use
	 * @note	This method includes counts of hidden and unapproved content items as well
	 */
	public static function contentCount( \IPS\Node\Model $container, $includeItems=TRUE, $includeComments=FALSE, $includeReviews=FALSE, $depth=0 )
	{
		if( \IPS\Settings::i()->cl_show_cat_expired AND \IPS\Settings::i()->cl_show_cat_completed )
		{
			return parent::contentCount( $container, $includeItems, $includeComments, $includeReviews, $depth );
		}

		$where = array();

		if( !\IPS\Settings::i()->cl_show_cat_expired )
		{
			$where[] = 'classifieds_adverts.cl_a_advert_expired=0';
		}
		else
		{
			$where[] = 'classifieds_adverts.cl_a_advert_expired=1';
		}

		if( !\IPS\Settings::i()->cl_show_cat_completed )
		{
			$where[] = 'classifieds_adverts.cl_a_completed=0';
		}
		else
		{
			$where[] = 'classifieds_adverts.cl_a_completed=1';	
		}

		$count = static::getItemsWithPermission( array( implode( ' and ', $where ) ), NULL, NULL, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );

		$_key = md5( get_class( $container ) . $container->_id );
		static::$itemCounts[ $_key ][ $container->_id ] = $count;

		return parent::contentCount( $container, $includeItems, $includeComments, $includeReviews, $depth );
	}

Maybe help someone someday... :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...