Part 1 of “Integrating nicely into Community Framework” primarily focused on minor user experience improvements. Part 2 will explain how to integrate into some of the completely new features of Community Framework 2.1.
com.woltlab.wcf.page object type
If you read the Notices spotlight, you may have seen that the administrator is able to select the pages the notice should appear on. As not every page may be suited for such purposes you have to define pages that are available to select. You accomplish this task by adding a new object type for every page:
…
<type>
<!-- a unique name for this object type -->
<name>com.woltlab.wbb.ThreadPage</name>
<!-- it’s a com.woltlab.wcf.page object -->
<definitionname>com.woltlab.wcf.page</definitionname>
<!-- the fully qualified class name of the page -->
<classname><![CDATA[wbb\page\ThreadPage]]></classname>
<!-- optional: The category of this page, the page will appear in “Other Pages” if you omit this -->
<categoryname>com.woltlab.wbb</categoryname>
</type>
…
Display More
This feature is not forward compatible: The installation will fail in Community Framework 2.0, due to the missing object type definition!
Condition object types
This partly goes in tandem with the previous improvement: Several new features (automated user group assignments, ads, notices) support “conditions”, such as the current page viewed or the amount of points the user has. We recommend adding sensible new conditions to these, in order integrate more nicely with the overall workflow. An example could be a condition for the notice system that allows the administrator to filter by the amount of files uploaded into the filebase. This allows him to show a short explanation only to those users that don’t have any files yet.
As the condition system is very powerful one could fill an entire post with an explanation. We recommend taking a look at the Commit that introduced the automated user group assignments system. You can use the Plugin development forum in case any questions arise, we provided you a brand new WCF 2.1.x label! It goes without saying that this is not limited to questions related to conditions, feel free to ask anything you have on your mind Building the example given above should be rather easy, though. Most work is done automatically, all you need to do is to add an object type (and some language items):
…
<type>
<name>com.woltlab.filebase.user.files</name>
<!-- it is a condition for the notice system -->
<definitionname>com.woltlab.wcf.condition.notice</definitionname>
<!-- UserIntegerPropertyCondition allows you to compare against a property of the user object -->
<classname><![CDATA[wcf\system\condition\UserIntegerPropertyCondition]]></classname>
<!-- we’re filtering by the user -->
<conditionobject>com.woltlab.wcf.user</conditionobject>
<!-- this is basically the category -->
<conditiongroup>contents</conditiongroup>
<!-- compare against the filebaseFiles property -->
<propertyname>filebaseFiles</propertyname>
<!-- selecting a negative amount of files will not work, setting it to a minimum of "0" prevents users from doing stupid things -->
<minvalue>0</minvalue>
</type>
…
Display More
This feature is not forward compatible: The installation will fail in Community Framework 2.0, due to the missing object type definition!
Statistics
We recommend reading the end user spotlight for this feature first. Integrating into the statistics only requires a small effort, but provides the administrator a much more complete overview on his community. You only need an object type, some language items and a PHP class:
…
<type>
<name>com.woltlab.wcf.user</name>
<definitionname>com.woltlab.wcf.statDailyHandler</definitionname>
<!-- the name of the class reading the daily items -->
<classname><![CDATA[wcf\system\stat\UserStatDailyHandler]]></classname>
<categoryname>com.woltlab.wcf.general</categoryname>
</type>
…
<?php
namespace wcf\system\stat;
/**
* Stat handler implementation for user stats.
*
* @author Marcel Werk
* @copyright 2001-2014 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.stat
* @category Community Framework
*/
class UserStatDailyHandler extends AbstractStatDailyHandler {
/**
* @see \wcf\system\stat\IStatDailyHandler::getData()
*/
// $date is the unix timestamp that represents the start of the day
public function getData($date) {
return array(
// counter should be the number of “items” created on the given day
'counter' => $this->getCounter($date, 'wcf'.WCF_N.'_user', 'registrationDate'),
// total is the amount of “items” created up to the *end* of the given day
'total' => $this->getTotal($date, 'wcf'.WCF_N.'_user', 'registrationDate')
);
}
}
Display More
The most common case is counting the related items, we provided the getCounter() and getTotal() functions for this case. But the statistics system is not limited to this use case! You can create statistics for everything that can be expressed with numbers.
This feature is not forward compatible: The installation will fail in Community Framework 2.0, due to the missing object type definition!