Soweit ich das verstanden habe, überlegt man sich zuerst die Klasse.
Dann erstellt man Tests dafür und erst dann entwickelt man die Klassen.
Ist es soweit richtig?
Ist so ein Skript überhaupt testbar:
Dann erstellt man Tests dafür und erst dann entwickelt man die Klassen.
Ist es soweit richtig?
Ist so ein Skript überhaupt testbar:
PHP-Code:
<?php
/******************************************************************************\
|* ##producttitle## ##version##
|* Author: ##author##
|* Copyright ##year## by Daniel Fatkic aka ragtek
|* Visit http://ragtek.org/blog for more information
|*
******************************************************************************/
require_once DIR . '/ragtek/library/ragtekDAO.php';
require_once DIR . '/ragtek/library/ragtek_Profileblock.php';
class invitedDAO extends ragtekDAO
{
protected $fromUser;
protected $showAvatar;
public function __construct(vB_Registry $registry, $userid, $usecache = false, $showAvatar = true) {
$this->fromUser = $userid;
$this->showAvatar = $showAvatar;
$this->condition = " where referrerid = " . $this->fromUser;
if ($usecache)
{
$this->initialCache();
}
parent::__constuct($registry);
}
// activate the cachefunction
protected function initialCache()
{
$this->cacheEvents = array(
'ragtekNewuser',
'ragtekRenameUser'
);
$this->cacheKey = 'ragtekInviteTab_' . $this->fromUser;
parent::initialCache();
}
protected function fetchAvatar($invite)
{
$avwidth = '';
$avheight = '';
if ($invite['avatarid'])
{
$avatarurl = $invite['avatarpath'];
}
else
{
if ($invite['hascustom'])
{
if ($this->registry->options['usefileavatar'])
{
$avatarurl = $this->registry->options['avatarurl'] . "/avatar$invite[userid]_$invite[avatarrevision].gif";
}
else
{
$avatarurl = 'image.php?' . $vbulletin->session->vars['sessionurl'] . "u=$invite[userid]&dateline=$invite[avatardateline]";
}
if ($invite['avheight'] AND $invite['avwidth'])
{
$avheight = "height=\"$invite[avheight]\"";
$avwidth = "width=\"$invite[avwidth]";
$avatarurl = $avatarurl . '" ' . $avheight . ' ' . $avwidth;
}
}
else
{
$avatarurl = '';
}
}
return $avatarurl;
}
/**
* fetch the data
* first try to get it from cache, if cache is disabled
* or there are no data, get it from DB
* and write them to cache (if enabled)
*/
protected function fetchData()
{
if ($this->data = $this->readFromCache())
{
return;
}
else
{
$query = "SELECT user.userid, user.username, user.joindate, user.avatarrevision "
. ($this->showAvatar ?
", avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustom,
customavatar.dateline AS avatardateline, customavatar.filedata_thumb,
customavatar.height AS avheight, customavatar.width AS avwidth,
customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb" : ""
) . "
FROM " .
TABLE_PREFIX . "user as user"
. ($this->showAvatar ? "
LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid)
LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) " : '') .
$this->condition .
" order by userid ASC";
$invites = $this->registry->db->query_read($query);
$return = array();
while ($invite = $this->registry->db->fetch_array($invites))
{
if ($this->showAvatar)
{
$invite['avatarurl'] = $this->fetchAvatar($invite);
}
$this->data[] = $invite;
}
}
$this->registry->db->free_result($invite);
$this->writeToCache();
}
}
class vB_ProfileBlock_Referrer extends ragtek_ProfileBlock
{
protected $showAvatar = false;
public $template_name = 'memberblock_block_invitedUsers';
function prepare_output($id = '', $options = array())
{
// here it makes not really sense for caching,
// alse there are too many events, i would need to observ
// for cleaning the cache (new registration, avatarchange, username change)
$showAvatar = $this->registry->options['avatarenabled'];
$invited = new invitedDAO($this->registry, $this->profile->userinfo['userid'], false, $showAvatar);
$users = $invited->getData();
unset($invited);
if (count($users) > 0)
{
$this->block_data['invited'] = '';
foreach ($users AS $user)
{
$user['joindate'] = vbdate($this->registry->options['dateformat'], $user['joindate']);
$referrerBits = vB_Template::create('referrerUserbit');
$referrerBits->register('user', $user);
$invitedbits .= $referrerBits->render();
}
$this->block_data['invited'] = $invitedbits;
}
}
public function confirm_display()
{
return ($this->block_data['invited'] != '') ? true : false;
}
}
/*======================================================================*\
|| ####################################################################
||
|| # Buildtime: ##buildtime##
|| ####################################################################
\*======================================================================*/
Kommentar