1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Xentrophies add-on

Discussion in 'XenForo Development Discussions' started by Korenwolf, Jun 22, 2011.

  1. Korenwolf

    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!
  2. ragtek

    ragtek Guest

    You need to use the Template hook

    Korenwolf likes this.
  3. Korenwolf

    Korenwolf New Member

  4. Korenwolf

    Korenwolf New Member

    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

    <!-- 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.

    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.
  5. ragtek

    ragtek Guest

    Have you created a ADMIN TEMPLATE? ( I run also several times into the problem, that i created a public template instead of admin ;)
    DarkSign and Korenwolf like this.
  6. Korenwolf

    Korenwolf New Member

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

    ragtek Guest

  8. Korenwolf

    Korenwolf New Member

    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 )
  9. ragtek

    ragtek Guest

    For the add-on export, you need to associate the templates, phrases, events, routes,.etc.. to your add-on!
  10. Korenwolf

    Korenwolf New Member

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

  11. Bob

    Bob Well-Known Member

    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.
    Korenwolf and ragtek like this.
  12. ragtek

    ragtek Guest

    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
    Korenwolf likes this.
  13. Korenwolf

    Korenwolf New Member

    Aha in the Master style, check! Thanks for the info Bobster65!

    (Ragtek i'll like you post just for trying ;) )
  14. Korenwolf

    Korenwolf New Member

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

    {xen:phrase customtrophies_adminpane_title}
    <form action="{xen:adminlink users/username/edit}" method="post" class="xenForm AutoValidator">
    <xen:foreach loop="$trophy" value="$trophy">
    <xen:checkboxunit label="">
    <xen:option name="{$trophy.id}" label="{$trophy.name}" hint="{$trophy.name}" />
    <xen:if is="CheckUserTrophies({$trophy.check})">CHECKED</xen:if>
    <xen:submitunit save="{xen:phrase customtrophies_submit}" />
    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
  15. Korenwolf

    Korenwolf New Member

    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
    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.*,
    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 ?
    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 ?
  16. ragtek

    ragtek Guest

    Have you checked what
    $viewParams = array( 'trophy' => getAllTrophies($userId));


    Doesn't this throw an error?
  17. Korenwolf

    Korenwolf New Member

    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

    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):
    Template Errors: customtrophies_adminpane
    [*]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: {
    I started out with this
    $viewParams = getAllTrophies($userId);
    and just tried some stuff i read on the forum

    * 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');

Share This Page