2
votes

I am working on a Joomla site and I want to display a verification graphic and text in their Profile when a User has completed a certain quiz in a program. I have most of the code complete, but I can't get it to do what I want. Here's what I have:


        $db = &JFactory::getDBO();

        $uri    = JURI::base();
        $my     =& JFactory::getUser();
        $user   =& CFactory::getActiveProfile();

        $query = 'select distinct(a.id), a.title, a.alias, a.description, a.created, a.responses, c.title as category'
            . ' from #__quiz_quizzes a left join #__quiz_categories c on a.catid=c.id left join #__quiz_responses r on a.id=r.quiz_id'
            . ' where r.created_by='.$user->id.' and a.published=1 order by a.created desc';
        $db->setQuery($query, 0, 10);
        $items = $db->loadObjectList();
            $menu = &JSite::getMenu();
            $mnuitems   = $menu->getItems('link', 'index.php?option=com_communityquiz&view=quiz');
            $itemid = isset($mnuitems[0]) ? '&Itemid='.$mnuitems[0]->id : '';
    if (strpos($itemid,'3')) {
    echo " Rep is Verified";
    } else {
    echo " Rep is not Verified {SHOW_FOR profile_owner} How to get verified{/SHOW_FOR}{HIDE_FOR profile_owner}  What does this mean?{/HIDE_FOR}";
    echo "";
    }

Trouble is, if anyone has taken test with id '3', it say they're verified. I need it to only display the verified part if the quiz_id is equal to '3', and if the created_by field matches the $user. My code is taken from the original plugin and all of it may not even be needed for such a small function, help streamlining would be appreciated! Screenshot of database table

1

1 Answers

0
votes

I think I found it using a combination of other forum entries here on Stack Overflow. This works:

    $user   =& CFactory::getActiveProfile();
    $result = mysql_query("SELECT COUNT(*) AS num_rows FROM hxlth_quiz_responses WHERE created_by='{$user->id}' and quiz_id='3' and score='3' LIMIT 1;");
    $row = mysql_fetch_array($result);
    if($row["num_rows"] > 0){
    echo "<div style='margin: 0 15px 15px 0; padding: 5px; box-shadow: rgba(0,0,0,0.4) 1px 1px; border: 1px solid #cccccc;'><img src='/images/check1.jpg' align='absmiddle' width='22' height='21' /> Rep is Verified</div>";
    } else {
    echo "<div style='margin: 0 15px 15px 0; padding: 5px; box-shadow: rgba(0,0,0,0.4) 1px 1px; border: 1px solid #cccccc;'><img src='/images/x1.jpg' align='absmiddle' width='21' height='21'> Rep is not Verified {SHOW_FOR profile_owner}<a href='index.php?option=com_communityquiz&view=quiz&task=respond&id=3'><font size='1'> How to get verified</font></a>{/SHOW_FOR}{HIDE_FOR profile_owner} <a href='index.php?option=com_communityquiz&view=quiz&task=respond&id=3'><font size='1'> What does this mean?</font>{/HIDE_FOR}";
    echo "</a></div>";
    }

It is now displaying the graphic and text correctly, I even slipped in a AND score variant to ensure they actually passed the quiz!