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

Aggregates of Customer Fields

Discussion in 'Styling and Customization Questions' started by jayramfootball, Aug 9, 2012.

  1. jayramfootball

    jayramfootball Active Member

    Hello

    I have a forum that allows users to enter and update custom fields such as 'Current View of Manager', with values such as Brilliant, Good, ... etc

    What I want to do is be able to count the values of these fields across all the members who have updated it so I get something like

    Excellent 15 votes (45%)
    Good 5 votes (15%)
    etc...

    I would like to be able to display this information on the forum page - either on the sidebar or main section at the bottom/top of the page, or even as a new 'forum opinion' page...

    Is this possible?

    Many thanks...

    :D
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Run this query on your database. You need to specify the field_id:

    Code:
    SELECT field_value, COUNT(*)
    FROM xf_user_field_value
    WHERE field_id = 'field_id here'
    GROUP BY field_value;
    
    A template hook can be used to insert content at a specific point on the page. Here is a code example of a template hook:

    http://xenforo.com/community/threads/how-to-create-a-bridge.28515/#post-331631

    For your purposes you can use the "forum_list_sidebar" hook which will insert your content in the sidebar on the index page.

    Then you need to write the code to run this query and append the result to the $contents of the hook.

    If you are not a programmer then you can post a request:

    http://xenforo.com/community/forums/custom-service-development-requests.69/
     
    jayramfootball likes this.
  3. jayramfootball

    jayramfootball Active Member

    Thank you Jake - Not a programmer, but will give it a go!

    Another quick question - is there a way of accessing the field_value labels (..as in the front end the values show up the 'Excellent', 'Good', etc. but in the database they show up as 1,2, etc...?)
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That requires some extra programming. You need to query xf_user_field.field_choices. That contains the labels as a serialized array.
     
    jayramfootball likes this.
  5. jayramfootball

    jayramfootball Active Member

    OK thanks Jake(y)

    Might be easier to just put the labels on the chart I build - and run the query for the values.
     
  6. jayramfootball

    jayramfootball Active Member

    OK, so I have struggled along learning as I go and have finally created working HTML calling a php script and using a flash charts package.:cautious:

    Here's the code:
    Code:
    <HTML>
    <script language="javascript">AC_FL_RunContent = 0;</script>
    <script language="javascript"> DetectFlashVer = 0; </script>
    <script src="AC_RunActiveContent.js" language="javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    var requiredMajorVersion = 10;
    var requiredMinorVersion = 0;
    var requiredRevision = 45;
    -->
    </script>
    <BODY bgcolor="#FFFFFF">
     
    <script language="JavaScript" type="text/javascript">
    <!--
    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
        alert("This page requires AC_RunActiveContent.js.");
    } else {
        var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
        if(hasRightVersion) {
            AC_FL_RunContent(
                'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',
                'width', '250',
                'height', '180',
                'scale', 'noscale',
                'salign', 'TL',
                'bgcolor', '#176093',
                'wmode', 'transparent',
                'movie', 'charts',
                'src', 'charts',
                'FlashVars', 'library_path=charts_library&xml_source=testphp8.php',
                'id', 'my_chart',
                'name', 'my_chart',
                'menu', 'true',
                'allowFullScreen', 'true',
                'allowScriptAccess','sameDomain',
                'quality', 'high',
                'align', 'middle',
                'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                'play', 'true',
                'devicefont', 'false'
                );
        } else {
            var alternateContent = 'This content requires the Adobe Flash Player. '
            + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
            document.write(alternateContent);
        }
    }
    // -->
    </script>
    <noscript>
        <P>This content requires JavaScript.</P>
    </noscript>
     
    </BODY>
    </HTML>
    
    This calls the file testphp8.php which accesses my sql database and creates the XML to populate the chart.

    Before I go any further (I am already in WAY over my head:eek:) can I just ask if this code will work to display what I want within xenforo? It works as a normal HTML page but I realise I am calling php files and also AC_RunActiveContent.js . I am not sure if these files need to go in new directories in order for xenforo to find them??

    Can you help me move this to the next step - done A LOT of iteration (Google is my friend:p) ... and I want to set off correctly on the next stage.

    my chart is currently at http://arsenaltalk.net/charts/testphp8x.php (works fine as I said as a stand alone HTML page)
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That javscript would have to be appended to the sidebar. One method is to use a template hook which I posted about previously. Or you can just edit the template directly:

    Admin CP -> Appearance -> Templates -> forum_list
     
  8. jayramfootball

    jayramfootball Active Member

    One of the problems I have Jake is that I don't know where to locate the php file that the javascript is calling... can it be in any location as long as it is referenced correctly?

    Thanks
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I assume the location is relative to the current directory in which case you would need to upload that file to the forum root.
     
  10. jayramfootball

    jayramfootball Active Member

    OK thank you.

    I tried adding some code to forum_list_sidebar within forum_list under this code:

    Code:
    <!-- block: forum_stats -->
            <div class="section">
                <div class="secondaryContent statsList" id="boardStats">
                    <h3>{xen:phrase forum_statistics}</h3>
                    <div class="pairsJustified">
                        <dl class="discussionCount"><dt>{xen:phrase discussions}:</dt>
                            <dd>{xen:number $boardTotals.discussions}</dd></dl>
                        <dl class="messageCount"><dt>{xen:phrase messages}:</dt>
                            <dd>{xen:number $boardTotals.messages}</dd></dl>
                        <dl class="memberCount"><dt>{xen:phrase members_count}:</dt>
                            <dd>{xen:number $boardTotals.users}</dd></dl>
                        <dl><dt>{xen:phrase latest_member}:</dt>
                            <dd><xen:username user="$boardTotals.latestUser" /></dd></dl>
                        <!-- slot: forum_stats_extra -->
                    </div>
                </div>
            </div>
            <!-- end block: forum_stats -->
    But no matter what I type in - even random text, nothing appears...

    For instance this shows nothing when placed under the code above:

    Code:
    <div class="section">
                  <h3>Forum Opinion</h3>
    </div>
     
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Edit the wrong style perhaps?

    Any addons installed? I know some addons involving the sidebar can override the sidebar.
     
  12. jayramfootball

    jayramfootball Active Member

    Apologies Jake - I was editing the master style not my default:notworthy:
     
  13. jayramfootball

    jayramfootball Active Member

    Jake, I have added this code under the stats block in forum_list

    Code:
    <!-- block -->
            <div class="section">
                <div class="secondaryContent statsList" id="boardStats">
                    <h3>Forum Opinion</h3>
                                   
                        <HTML>
                    <script language="javascript">AC_FL_RunContent = 0;</script>
                                    <script language="javascript"> DetectFlashVer = 0; </script>
                                    <script src="AC_RunActiveContent.js" language="javascript"></script>
                                    <script language="JavaScript" type="text/javascript">
                                    <!--
                                    var requiredMajorVersion = 10;
                                    var requiredMinorVersion = 0;
                                    var requiredRevision = 45;
                                    -->
                                    </script>
                                    <BODY bgcolor="#FFFFFF">
     
                                    <script language="JavaScript" type="text/javascript">
                                    <!--
                                    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
                                alert("This page requires AC_RunActiveContent.js.");
                                    } else {
                                var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
                                if(hasRightVersion) {
                            AC_FL_RunContent(
                        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',
                        'width', '250',
                        'height', '180',
                        'scale', 'noscale',
                        'salign', 'TL',
                        'bgcolor', '#176093',
                        'wmode',
                        'transparent',
                        'movie', 'charts',
                        'src', 'charts',
                      'FlashVars', 'library_path=charts&xml_source=testphp8.php',
                      'id', 'my_chart',
                      'name', 'my_chart',
                      'menu', 'true',
                      'allowFullScreen', 'true',
                      'allowScriptAccess','sameDomain',
                        'quality', 'high',
                          'align', 'middle',
                      'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                      'play', 'true',
                      'devicefont', 'false'
                        );
                          } else {
                      var alternateContent = 'This content requires the Adobe Flash Player. '
                      + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
                      document.write(alternateContent);
                          }
                            }
                              // -->
                            </script>
                                <noscript>
                          <P>This content requires JavaScript.</P>
                              </noscript>
     
                            </BODY>
                            </HTML>
                       
                </div>
            </div>
            <!-- end block -->
    
    All I seem to be getting is the title and a blank box... this has all been very much trial and error for me but I am starting to exhaust options... is there something obvious I am missing? Any help would be greatly appreciated.

    For reference my php file being called is in the root (public_html) and my flash library is at public_html/charts.
     
  14. jayramfootball

    jayramfootball Active Member

    I tried this a different way - by just adding a new div to the bottom of the sidebar_online_users template

    The used the following code (including absolute paths to avoid referencing issues):

    Code:
    <div class="section">
    <div class="secondaryContent">
    <h3>Forum Opinions</h3>
    <div style="text-align:center;margin-top:8px;">
     
    <script language="javascript">AC_FL_RunContent = 0;</script>
    <script language="javascript"> DetectFlashVer = 0; </script>
    <script src="AC_RunActiveContent.js" language="javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    var requiredMajorVersion = 10;
    var requiredMinorVersion = 0;
    var requiredRevision = 45;
    -->
    </script>
     
    <script language="JavaScript" type="text/javascript">
    <!--
    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
        alert("This page requires AC_RunActiveContent.js.");
    } else {
        var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
        if(hasRightVersion) {
            AC_FL_RunContent(
                'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',
                'width', '250',
                'height', '180',
                'scale', 'noscale',
                'salign', 'TL',
                'bgcolor', '#176093',
                'wmode', 'transparent',
                'movie', '../charts/charts_library/charts',
                'src', '../charts/charts_library/charts',
                'FlashVars', 'library_path=../charts/charts_library&xml_source=../charts/testphp8.php',
                'id', 'my_chart',
                'name', 'my_chart',
                'menu', 'true',
                'allowFullScreen', 'true',
                'allowScriptAccess','sameDomain',
                'quality', 'high',
                'align', 'middle',
                'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                'play', 'true',
                'devicefont', 'false'
                );
        } else {
            var alternateContent = 'This content requires the Adobe Flash Player. '
            + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
            document.write(alternateContent);
        }
    }
    // -->
    </script>
    <noscript>
        <P>This content requires JavaScript.</P>
    </noscript>
     
    </div></div></div> 
    Still all I get is a blank box with the heading...:confused:
     
  15. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Gotta debug your javascript to see where it's failing. I have very little javascript experience. If it was me I would have used the template_hook with PHP code to fetch the information instead of javascript.
     
  16. jayramfootball

    jayramfootball Active Member

    Its because I am using a flash charts package Jake that I need to use the javascript...

    the Flash charts package is here and I am using php to query the data to pass to the chart. All the flash chart libraries are on my server (I am pretty sure in the correct location - I copied them to all options as part of my process of deduction!)

    To be honest if I could just create a chart without the extra flash libraries I would, but don't know how to do that with just php (don't think you can???)
     
  17. jayramfootball

    jayramfootball Active Member

    Ok I got this working!:D... hate giving up, just needs a lot of coffee:coffee:

    Code was fine, but one of my flash files was missing:sick:

    I used the widget framework in the end - though I now know how to do this directly on the template too (not via a template hook yet!)

    Looks good too! http://arsenaltalk.net/

    Great for forum wide polls based on custom field inputs(y)
     
    Jake Bunce likes this.
  18. simbolo

    simbolo Well-Known Member

    One thing of note, since the site is live I would suggest removing debugging from your config file. Being able to get to http://arsenaltalk.net/?_debug=1 is a bad thing on a production site.

    If you want to still have it on for admins only, see Jake's post.
     
    jayramfootball likes this.
  19. jayramfootball

    jayramfootball Active Member

    Thanks!
     

Share This Page