Jump to content
WebFlake
  • 0

Display stats


UncleBear

Question

So i got a question. I am trying to code a Welcome tab for quests instead for them to scroll down and check out general stats id like to display it inside of the welcome tab. So basically i took the code from gstats template 

{lang="total_topics"}

This displays the language all fine but when i want it to display the stat number using

{number="$stats['total_topics']"}

it comes up with just a plain 0 but instead it should be like 20 or something.

 

Any ideas what i'm missing?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
22 minutes ago, UncleBear said:

{{if !member.member_id}} // only shows to Guest members
  <div class="guestHeader">Welcome</div>
    <ul>
      <li>{lang="total_topics"} {number="$stats['total_topics']"} </li>
    </ul>
{{endif}}

Below code does not do its job properly. And this is located in Globaltemplate


{number="$stats['total_topics']"}

The reason its not going to work is that $stats is a variable for

$stats['total_topics']	= \IPS\Db::i()->select( "COUNT(*)", 'forums_topics', array( 'approved = ?', 1 ) )->first();

Meaning the \IPS+DB::i means with IPS Database INSERT (i()) and SELECT "count everything" from forums_topic show it as an array first

So your just saying $stats it doesn't know what your reffering too.

The last line i posted is the way that $stats will work as it does the query.

VAEfvMI.png

Liked what i posted remember to feed me a cookie ->
Or you can add a cookie to myCookieJar

Link to comment
Share on other sites

  • 0
On 12/25/2017 at 2:27 PM, UncleBear said:

So i got a question. I am trying to code a Welcome tab for quests instead for them to scroll down and check out general stats id like to display it inside of the welcome tab. So basically i took the code from gstats template 


{lang="total_topics"}

This displays the language all fine but when i want it to display the stat number using


{number="$stats['total_topics']"}

it comes up with just a plain 0 but instead it should be like 20 or something.

 

Any ideas what i'm missing?

Not completely sure about this as I've never tried creating my own statistics. However, here's the code from the native Forum Statistics that you should be using to create your welcome message. The PHP file is located at /applications/forums/widgets/forumStatistics.php if you need to replicate it etc.

<?php
/**
 * @brief		forumStatistics Widget
 * @author		<a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
 * @copyright	(c) Invision Power Services, Inc.
 * @license		https://www.invisioncommunity.com/legal/standards/
 * @package		Invision Community
 * @subpackage	Forums
 * @since		27 Mar 2014
 */

namespace IPS\forums\widgets;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * forumStatistics Widget
 */
class _forumStatistics extends \IPS\Widget\StaticCache
{
	/**
	 * @brief	Widget Key
	 */
	public $key = 'forumStatistics';
	
	/**
	 * @brief	App
	 */
	public $app = 'forums';
		
	/**
	 * @brief	Plugin
	 */
	public $plugin = '';

	/**
	 * Render a widget
	 *
	 * @return	string
	 */
	public function render()
	{
		$stats = array();
		
		$stats['total_posts']	= \IPS\Db::i()->select( "COUNT(*)", 'forums_posts', array( 'queued = ?', 0 ) )->first();
		
		if ( \IPS\Settings::i()->archive_on )
		{
			$stats['total_posts'] += \IPS\forums\Topic\ArchivedPost::db()->select( 'COUNT(*)', 'forums_archive_posts', array( 'archive_queued = ?', 0 ) )->first();
		}
		
		$stats['total_topics']	= \IPS\Db::i()->select( "COUNT(*)", 'forums_topics', array( 'approved = ?', 1 ) )->first();
		
		return $this->output( $stats );
	}
}

Hope this helps, if at all! :)

Link to comment
Share on other sites

  • 0
{{if !member.member_id}} // only shows to Guest members
  <div class="guestHeader">Welcome</div>
    <ul>
      <li>{lang="total_topics"} {number="$stats['total_topics']"} </li>
    </ul>
{{endif}}

Below code does not do its job properly. And this is located in Globaltemplate

{number="$stats['total_topics']"}
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...