Jeff VIP
Total posts: 745
15 Apr 2014 00:22

Hi,

I have a database of people (not registered users btw) and I would like to list their birthdays in a module like: Born today, or Born this week, or Born this month. Perhaps the module records can be altered to include such functionality? Hope you can help me with this.

Best regards, Jeff

Last Modified: 01 Jun 2016


Sergey
Total posts: 13,748
15 Apr 2014 06:42

Where birth date is stored? Date and Time field? Is it also affect article create date?


Jeff VIP
Total posts: 745
15 Apr 2014 09:02

Sergey Where birth date is stored? Date and Time field?

Yes

Is it also affect article create date?

No


Sergey
Total posts: 13,748
15 Apr 2014 09:09

I think you can custom code records module using records API. But I do not know good way to make it the way, you do not lose changes on update.


Jeff VIP
Total posts: 745
15 Apr 2014 09:24

I have been struggeling for ages trying to achieve this, without success. At the moment I don't care much about loosing it on update. Could you please show me how to accomplish this?


Sergey
Total posts: 13,748
16 Apr 2014 06:27

You have to use records API

But as a last paramter $ids you have pass result of your filter.

$sql = "SELECT record_id FROM #__js_res_record_values 
    WHERE field_id = 12
      AND MONTH(field_value) = MONTH(NOW())";
$db = JFactory::getDbo();
$db->setQuery($sql);
$ids = $db->loadColumn();

This is how you get $ids of the records where date and time field ID 12 the same month as now.


Jeff VIP
Total posts: 745
16 Apr 2014 10:03

Thanks Sergey,

What about Born Today?


Sergey
Total posts: 13,748
16 Apr 2014 11:56

Born today

SELECT record_id FROM #__js_res_record_values
WHERE field_id = 12
AND MONTH(field_value) = MONTH(NOW())
AND DAY(field_value) = DAY(NOW())

Born tomorow

SELECT record_id FROM #__js_res_record_values
WHERE field_id = 12
AND MONTH(field_value) = MONTH(NOW() + INTERVAL 1 DAY)
AND DAY(field_value) = DAY(NOW() + INTERVAL 1 DAY)

Jeff VIP
Total posts: 745
17 Apr 2014 07:17

Born today

SELECT record_id FROM #__js_res_record_values
WHERE field_id = 12
AND MONTH(field_value) = MONTH(NOW())
AND DAY(field_value) = DAY(NOW())

returns a full unfiltered list. Pretty weird, isn't it?


Sergey
Total posts: 13,748
17 Apr 2014 08:26

This is because this query rturn 0 and when you pass 0 to API it does not limit at all.

You have to call API only if there are IDs.

if($ids)
{
    $items = $api->records(...);
}

Jeff VIP
Total posts: 745
17 Apr 2014 12:08
if($ids)
{
    $items = $api->records(...);
}

ok, now you have lost me. I am not a programmer, remember?


Sergey
Total posts: 13,748
17 Apr 2014 12:33

What is your code to use records API? I gave tou the link in 6th post.


Jeff VIP
Total posts: 745
17 Apr 2014 14:04

I have used NoNumber's Sourcerer and module Custom HTML to create the list:

{source}
<!-- You can place html anywhere within the source tags -->

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

$sql = "SELECT record_id FROM #__js_res_record_values
    WHERE field_id = 3
AND MONTH(field_value) = MONTH(NOW())";

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

$api = new CobaltApi();
$section_id=1;
$limit=15;
$template=table;
$data = $api->records(
    $section_id,
    $view_what,
    $orderby,
    $type_ids,
    $user_id,
    $category_id,
    $limit,
    $template,
    $client,
    $client_id,
    $lang,
    $ids
);
?>

<ul>
<?php
foreach($data['list'] AS $item) {
    printf('<li><a href="/%s">%s</a></li>', $item->url, $item->title);
} ?>
</ul>
{/source}

Sergey
Total posts: 13,748
18 Apr 2014 03:33
  1. Insead of $section_id theer should be section ID like 1 or 5. Somethign liek this.
$data = $api->records(
    1,
    'all',
    'r.ctime DESC',
    NULL,
    NULL,
    NULL,
    10,
    NULL,
    NULL,
    NULL,
    NULL,
    $ids
);

And after $ids = $db->loadColumn(); insert

if(empty($ids))
{
    return;
}

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

Sorry for my late response, Sergey. With your code I managed to create exactly what I want.

Thank you!


Jeff VIP
Total posts: 745
14 Oct 2014 03:38

Hi whilst debugging I've encountered some warnings in my custom module :

Notice: Undefined offset: 1 in /home/mysite/public_html/sandbox/components/com_cobalt/api.php on line 259

Warning: strpos() expects parameter 1 to be string, array given in /home/mysite/public_html/sandbox/libraries/joomla/language/text.php on line 72

Warning: strtoupper() expects parameter 1 to be string, array given in /home/mysite/public_html/sandbox/libraries/joomla/language/language.php on line 328

I was wondering if these warnings are related to code you have provided and if so how to solve them.


Jeff VIP
Total posts: 745
14 Oct 2014 23:42
Notice: Undefined offset: 1 in /home/mysite/public_html/sandbox/components/com_cobalt/api.php on line 259

This was caused due to an empty value for $orderby

2 warnings left to solve.....


Sergey
Total posts: 13,748
15 Oct 2014 02:44

If you manage to install xdebug to your PHP you will see your errors like so

2014-10-15_10-30-47

This will give you error stak and you will be able to identify where is the origin of the error.


Sergey
Total posts: 13,748
20 Oct 2014 08:56

It is very hard to tell without tracking system.


Jeff VIP
Total posts: 745
20 Oct 2014 23:46

Sergey It is very hard to tell without tracking system.

I understand. I'll leave it for the moment then, because it's not a major problem.

I do however, have another question:

How can I exclude expired records from this list?

I assume a connection has to be made to another table (__js_res_record_) to retrieve the column access where access = 1 ?

Could you give me a hint how to achieve this?


Sergey
Total posts: 13,748
23 Oct 2014 04:23

This module should display acording to section param,eters. Show future records parameter in section to NO.

Powered by Cobalt