Xentrophies add-on

Korenwolf

New member
Hello all,

I'm currently looking into Xenforo and i;m trying to create an add-on too enable the use of custom trophies. See http://xenforo.com/community/threads/suggestion-manually-award-trophies.3239/page-2#post-224015

After reading http://xenforo.com/community/threads/creating-an-addon.5416/ i made a start creating the add-on but i ran into a problem.

What class / file is used to create the tabs in the admin view of the user profiles. Cause i need to add a tab there so admins are able to select/deselect trophies for a user.

Thanks for you time!
 
I'm working on the customTrophies add-on but i'm running into some trouble with the following:

I only found the admin tab options Ragtek suggested (admin_user_edit_tabs
and admin_user_edit_panes) inside an XML file -> install/data/admin_templates.xml

So i copied a part of the necessary the code and made a template called : customtrophies_admintab

Code:
<!-- slot: pre_trophies --> <li id="tabTrophies"><a>{xen:phrase trophies}</a></li>

When i put the above code directly into the class it works, but when i create a template it shows nothing.

Code:
WORKS: $contents.= '<!-- slot: pre_trophies --><li id="tabTrophies"><a>{xen:phrase trophies}</a></li>';

FAILS: $contents.= $template->create('customtrophies_admintab',$template->getParams());

Any ideas or directions are greatly appreciated.
 
gaaaaah! I wasn't even aware that admin templates existed..... i also found where to create them (development tab > add admin template)... gosh.. it worked instantly, a big thank you goes out to Ragtek :) !!
 
Is there a way to add the theme templates in the add-on?
I'm working with the $template->create() and made 2 theme templates but they do not showup in the add-on export xml.

Is there a way ? (besides not using $template->create )
 
For the add-on export, you need to associate the templates, phrases, events, routes,.etc.. to your add-on!
 
Could you explain how that works ?
Can't find any info on associating templates on the forum and google doens't want to be my friend on this subject...

Thanks!
 
Could you explain how that works ?
Can't find any info on associating templates on the forum and google doens't want to be my friend on this subject...

Thanks!

edit one of your addon tempalates and at the bottom, you will see Add-on: and a drop down listing of all addons. This is how you associate a template with a specific add-on. This needs to be done on the MASTER STYLE.
 
Template=> you need to create a template in the master style
Then you'll have a add-on field at the bottom of the form, where you need to select the addon

Edit: Oh, too slow
 
Darn i got this far: created add-on, created master style templates, created admin templates, created working code event listeners too add a tab to member profile and admin user edit screen.

Working on the "adminpane" admin template i ran into new challenges. The pane needs to show a list of all trophy names with checkboxes in a form.
The trophies a user already owns will get checked. All trophies can be checked/unchecked and saved to a user.

So for this i need a form, foreach, if and some knowledge how to use function withins a template.... (if even possible)
I got this far (and next up is a new function for checking called CheckUserTrophies):

Code:
{xen:phrase customtrophies_adminpane_title}

<form action="{xen:adminlink users/username/edit}" method="post" class="xenForm AutoValidator">

<ul>

<xen:foreach loop="$trophy" value="$trophy">
<li>
<xen:checkboxunit label="">
<xen:option name="{$trophy.id}" label="{$trophy.name}" hint="{$trophy.name}" />
<xen:if is="CheckUserTrophies({$trophy.check})">CHECKED</xen:if>
</xen:checkboxunit>
</li>
</xen:foreach>

</ul>

<xen:submitunit save="{xen:phrase customtrophies_submit}" />

</form>

I will gladly receive tips, examples, explanations, help on how to continue and some laughs about my code (and english) :notworthy:

*i will updated the above code regularly to add my latest findings
 
I cant figure out how to send vars to a template, something with, i'm have to idea i'm missing the point bigtime:

CheckTrophies.php in directory Model
Code:
<?php

class CustomTrophies_Model_CheckTrophies extends XFCP_XenForo_Model_Trophy
{

//check user for awarded trophies
public function CheckUserTrophies()
{
$viewParams = getAllTrophies($userId);

//* Gets all trophies, ordered by their points (ascending).
//* @return array Format: [trophy id] => info
$viewParams = $this->fetchAllKeyed('
SELECT id
FROM xf_trophy
ORDER BY trophy_points
', 'trophy_id');
 
//* Gets all trophies that the specified user has earned. Ordered by award date descending.
//* Needs @param integer $userId
//* @return array Format: [trophy id] => trophy info plus award_date
$user_trophies = $this->fetchAllKeyed('
SELECT trophy.*,
user_trophy.award_date
FROM xf_user_trophy AS user_trophy
INNER JOIN xf_trophy AS trophy ON (trophy.trophy_id = user_trophy.trophy_id)
WHERE user_trophy.user_id = ?
ORDER BY user_trophy.award_date DESC
', 'trophy_id', $userId);

$i = 0;
foreach ($all_trophies)
{
if in_array($viewParams[$i],$all_trophies)
{
//add check value to array [check] = true ?
}

$i++;
}

return $this->responseView('XenForo_ViewAdmin_Customtrophies_Adminpane','customtrophies_adminpane', $viewParams);
}

}

Can anyone point me out how to use this and make $trophy available in my template ?
 
I cant figure out how to send vars to a template, something with, i'm have to idea i'm missing the point bigtime:

CheckTrophies.php in directory Model
Code:
class CustomTrophies_Model_CheckTrophies extends XFCP_XenForo_Model_Trophy
{

//check user for awarded trophies - just showing all for testing purpose
public function CheckUserTrophies()
{
$viewParams = array( 'trophy' => getAllTrophies($userId));

return $this->responseView('XenForo_ViewAdmin_Customtrophies_Adminpane','customtrophies_adminpane', $viewParams);
}

Can anyone point me out how to use this and make $trophy available in my template ?
Have you checked what
$viewParams = array( 'trophy' => getAllTrophies($userId));

contains?

Doesn't this throw an error?
 
No idea how do you check it from within a class in xenforo ?
normally i would do a vardump (did a search with no result on the forum)...
Watch the video, remembered it from last week
http://xenforo.com/community/thread...at-variables-are-available-in-templates.6960/

Code:
die(Zend_Debug::dump($viewparams));
if i'm correct ?

getAllTrophies is an excisting public function within Trophy.php (xenforo/model/)
The only error i'm getting is this one (emtpy $trophy):
Code:
Template Errors: customtrophies_adminpane
[LIST=1]
[*]Invalid argument supplied for foreach() in /home/oldrep/public_html/beta/library/XenForo/Template/Abstract.php(262) : eval()'d code, line 11:
10: '; 11: foreach ($trophy AS $trophy) 12: {
[/LIST]

I started out with this
Code:
$viewParams = getAllTrophies($userId);
and just tried some stuff i read on the forum

Code:
/**
* Gets all trophies, ordered by their points (ascending).
*
* @return array Format: [trophy id] => info
*/
public function getAllTrophies()
{
return $this->fetchAllKeyed('
SELECT *
FROM xf_trophy
ORDER BY trophy_points
', 'trophy_id');
}
 
Top Bottom