Jeff VIP
Total posts: 745
29 Apr 2014 15:45

Hi Sergey,

I hope you can help me with this one.

In my current project, people can make a donation to prolong an expired article. I would like to list those people next to the article. Emerald already handles the donations together with a (custom made) prolong field.

It would be something like you see on Kiva.org, where lenders are listed below the person they gave a loan to.

Best regards, Jeff

Last Modified: 24 Feb 2015



Sergey
Total posts: 13,748
30 Apr 2014 03:18

If you eneable audit log, then everyone who ever make article featured will be saved there. And you can use that table to select all users and list them on the page.


Jeff VIP
Total posts: 745
01 May 2014 05:10

Ok, it took me a while to figure out I had to select a moderator first in order to display the audit list.

Sergey If you eneable audit log, then everyone who ever make article featured will be saved there.> Sergey

I don't need a list of people who made an article featured, I need a list of people who made a donation to prolong an article. You wrote a special plugin and action for me (remember?), to prolong an article by purchasing an article based subscription. Unfortunately, articles prolonged via your plugin aren't recorded by the Audit Trail. I think I need your help here to update the plugin.

Since Audit Trails are only visible to moderaters, wouldn't it be tricky to give it public access? (which I need) All I need is a list with names and avatars like: prolonged by (donated by)


Sergey
Total posts: 13,748
01 May 2014 10:41

In prolong field find method prolongRecord. This is where prolongation is happening. You can add there code that store user ID in some additional talbe.


Jeff VIP
Total posts: 745
25 Jun 2014 04:04

Sergey In prolong field find method prolongRecord. This is where prolongation is happening. You can add there code that store user ID in some additional talbe.

Can I use 'repostedby' of js_res_record for this purpose? I don't want to create a new table and since I don't use the repost function this might be a good way to display 'people who donated to this article'. Does repostedby support multiple users?

If I decide to use 'repostedby', how and where do I put it in the following code?

    $r = JTable::getInstance('Record', 'CobaltTable');
    $r->load($record->id);
    $r->extime = JDate::getInstance($newtime)->toSql();
    if($this->params->get('params.ownership'))
    {
        $r->user_id = $this->user->get('id');//Current user becomes new owner
    }
    $r->store();

    $note = JText::sprintf('P_SUBSCR_NOTE', JRoute::_(Url::record($record)), $record->title, $days,
        JDate::getInstance($time)->format($this->params->get('params.timeformat', 'd, M Y')),
        JDate::getInstance($newtime)->format($this->params->get('params.timeformat', 'd, M Y'))
    );

    EmeraldApi::applyCount($sid, JRoute::_(Url::record($record)), $note);

    return 1;

Sergey
Total posts: 13,748
25 Jun 2014 23:07

Before $r->store() add

ATlog::log($r, ATlog::REC_EDIT);

This will add audit log about article was edited. Eneable Audit log for this type. Now you can use audit log table to get all edit events and distinct user_id(s) from there.


Jeff VIP
Total posts: 745
26 Jun 2014 12:04

Thank you Sergey,

I have changed the code into

ATlog::log($r, ATlog::REC_PROLONGED);

and it also works :-)

Now, how can I display a list of donors next to each record in a seperate module? (I use Sourcerer in a custom-HTML module.)


Sergey
Total posts: 13,748
26 Jun 2014 13:27
$id = JFactory::getApplication()->input->get('id');
$sql = "SELECT DISTINCT user_id FROM #__js_res_audit_log WHERE record_id = {$id} AND event = 6";

Like this. 6 is ATlog::REC_PROLONGED.

I do not know what is sourcerer.


Jeff VIP
Total posts: 745
27 Jun 2014 01:21

Thank you pepperstreet for explaining what Sourcerer is.

I have created the following code. It shows correctly 'No donations yet' when there are no donors, but nothing is displayed when there are. What am I doing wrong?

<?php
$file = JPATH_ROOT.'/components/com_cobalt/library/php/helpers/auditlog.php';
if(JFile::exists($file))
{
include_once $file;
}

$id = JFactory::getApplication()->input->get('id');
$sql = "SELECT DISTINCT user_id FROM #__js_res_audit_log WHERE record_id = {$id} AND event = 6";

$db = JFactory::getDbo();
$db->setQuery($sql);
$ids = $db->loadColumn(6);

if(empty($ids))
echo 'No Donations yet';
{
return;
}

$api = new CobaltApi();
$section_id=1;
$limit=15;
$template=table;
$data = $api->getListQuery(

$record_id,
$type_id,
$section_id,
$comment_id,
$field_id,
$ctime,
$ip,
$user_id,
$event,
$params
);

foreach($data['list'] AS $item) {
  echo '<p>'.$item->user_id.'</p>';
} ?>

Sergey
Total posts: 13,748
27 Jun 2014 13:38
$app = JFactory::getApplication();
if($app->input->get('view') != 'record' && $app->input->get('option') != 'com_cobalt')
{
   // this is not a cobalt article full view.  
   return;
}

$id = $app->input->get('id');
$sql = "SELECT DISTINCT user_id FROM #__js_res_audit_log WHERE record_id = {$id} AND event = 6";

$db = JFactory::getDbo();
$db->setQuery($sql);
$ids = $db->loadColumn();

if(empty($ids))
{
    echo 'No Donations yet';
    return;
}

echo 'Donators are:';
echo '<ul>';
foreach($ids as $id) {
    echo '<li>' .JFactory::getUser($id)->get('name'). '</li>';
}
echo '</ul>';

Jeff VIP
Total posts: 745
27 Jun 2014 23:26

Sergey, your code works. :-) Excellent service, as always.....

Best regards, Jeff


Jeff VIP
Total posts: 745
20 Feb 2015 05:49

Hi Sergey,

how can I include another column of #__js_res_audit_log in the output? I would like to show ctime (the date of donation) next to the donator.

Best regards, Jeff


Sergey
Total posts: 13,748
23 Feb 2015 04:36
$id = $app->input->get('id');
$sql = "SELECT user_id, ctime FROM #__js_res_audit_log WHERE record_id = {$id} AND event = 6 GROUP BY user_id";

$db = JFactory::getDbo();
$db->setQuery($sql);
$users = $db->loadObjectList();

if(empty($users))
{
    echo 'No Donations yet';
    return;
}

echo 'Donators are:';
echo '<ul>';
foreach($users as $user) {
    echo '<li>' .JFactory::getUser($user->user_id)->get('name').
        ' ('. JHtml::_('date', $user->ctime, 'Y m d') .')</li>';
}
echo '</ul>';

Jeff VIP
Total posts: 745
24 Feb 2015 04:39

Thank you Sergey!

Powered by Cobalt