5

There is a very good feature in Joomla 3.3 that allows adding notes for each user.

In part of the admin area we can select a user and add a note for him/her.
When a user is logged in in the front end, I'd like them to be able to see this text. I googled and I can not find anything about this.
Is there any way to do this?

1

Try this code -

if ($user->id) {
    $db =JFactory::getDBO();
    $query = $db->getQuery(true);
    $query->select('*')
    ->from('#__user_notes')
    ->where('user_id = '. (int)$user->id)
    ->where('state=1');
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    print_r($rows[0]->body);
}

I hope it will help you :)

0

I suppose the only two columns of importance to your users will be subject and body. After requiring your users to be logged in, you can craft your query to exclude notes assigned to other users and unpublished notes. I'll demonstrate how to build your SELECT clause so that displaying a simple html table is a breeze with implode().

$user = JFactory::getUser();
if (!$user->guest) {
    $db =JFactory::getDBO();
    $query = $db->getQuery(true)
        ->select($db->qn(["subject", "body"], ["Topic", "Note"]))
        ->from($db->qn("#__user_notes"))
        ->where([
            $db->qn("user_id) . " = " . (int)$user->id,  // target the logged in user
            $db->qn("state") . " = 1"                     // ensure that only published notes are shown
        ]);
    $db->setQuery($query);
    if ($results = $db->loadAssocList())
    {
        echo "<table>";
            // display Topic and Note as column headings
            echo "<tr><th>" , implode("</th><th>", array_keys($results[0])) , "</th></tr>";
            // display rows of data
            foreach ($results as $row)
            {
                echo "<tr><td>" , implode("</td><td>", $row) , "</td></tr>";
            }
        echo "</table>";
    }
    else
    {
        echo "No Notes";
    }
}

Output will be like:

__________________________________________________________________
|    Topic    |    Note                                          |
|-------------|--------------------------------------------------|
|  Feedback1  |  I loved the way you did my laundry.             |
|-------------|--------------------------------------------------|
|  Feedback2  |  Perhaps I can interest you in my dry cleaning.  |
------------------------------------------------------------------

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.