Jump to content

New optional parameter on item contentCount

Featured Replies

Posted

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.

Are there sub-categories?

contentCount will include items within sub-categories, but the category view only shows direct child items.

  • Author
3 hours ago, HeadStand said:

Are there sub-categories?

No, only this main for a test. But I really got 4 records in there, not shown due to my setting.

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

  • Author
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.

  • Author

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... :)

17 hours ago, Martin A. said:

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

^This

I'm glad this helped you @Adriano Faria

Archived

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

Recently Browsing 0

  • No registered users viewing this page.