News:

Dear forum visitors, if the support forum is not available, please try again a few minutes later. Thanks!

Main Menu
Support-Forum

Related files on date added

Started by Tazzios, 15.08.2019 20:09:33

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tazzios

I was trying to rebuild the related module to my purpose.
But with my experience with coding i got quickly stuck adding the field was easy
<field name="download_filter" type="list" default="a.title" label="MOD_JDOWNLOADS_RELATED_FIELD" description="MOD_JDOWNLOADS_RELATED_FIELD_DESC">
                    <option value="a.ordering">MOD_JDOWNLOADS_RELATED_MANAGER</option>
                    <option value="a.date_added">MOD_JDOWNLOADS_RELATED_CREATED_DATE</option>
                    <option value="a.modified_date">MOD_JDOWNLOADS_RELATED_MODIFIED_DATE</option>
<option value="a.category">MOD_JDOWNLOADS_RELATED_MODIFIED_DATE</option>
                </field>
but after seeing the helper file i was trying a short cut like this. Only i know nothing about the array that has to bereturned something with $getitems i guess /* // Obtain a database connection
$db = JFactory::getDbo();
// Retrieve the shout
$query = $db->getQuery(true)
->select($db->quoteName(' file_id, file_alias '))
->from($db->quoteName('#__jdownloads_files'))
->where('date(`date_added`) in (SELECT date(date_added) FROM `josvz_jdownloads_files` WHERE id=' . $id . ') and id<>' . $id);
//SELECT * FROM `josvz_jdownloads_files` WHERE date(`date_added`) in (SELECT date(date_added) FROM `josvz_jdownloads_files` WHERE id=' . $id . ') and id<>' . $id
// Prepare the query
$db->setQuery($query);
// Load the row.
$result = $db->loadResult();
// Return the Hello
return $result;

Can some one help my so that i can return the right data to $files  inmod_jdownloads_related.php:$files = modJdownloadsRelatedHelper::getList($params, $catids, $id); Or maybe i`m doing it totaly wrong and some one has an better solution  :P

ColinM

Hi
It would help if you explained (with some pics) what you are tring to achieve.In jD  related Downloads are those in the same Category as the Download being viewed (or optionally those in subcategories).I guess you want to add some other criterion perhaps based on dates or by the same creator.  In either of these the same Category, and sub cats, would need to apply.
Colin
Colin M
  •  

Tazzios

#2
Instead of files in the same category i want to show files with the same added date (date_added) instead of category.
That way i have all the files related to a meeting.

It could be an new module to make it easier where you can select the date field that you want to match. an quick and dirty solution is also fine the database query that i made should work   only the code expects an item array instead of a table with only file_id, file_alias'.
trying to edit the existing module by my self  was just a long shot.  :P

ColinM

Hi
There seems to be no way in jD to search or select by a date range. :(   One can however order the downloads by date.

Think this would need to be a new module to set a date range.  I will add to suggestions - but please note we are presently very busy with the next major relase of jD.
Colin
Colin M
  •  

Tazzios


I found the date range function!
Quote from: ColinM on 17.08.2019 12:19:16
Hi
There seems to be no way in jD to search or select by a date range. :(   One can however order the downloads by date.

Think this would need to be a new module to set a date range.  I will add to suggestions - but please note we are presently very busy with the next major relase of jD.
Colin
In the helper I have added:
$downloads->setState('filter.date_field', 'date(a.date_added)');//date else it check alse the time
$downloads->setState('filter.start_date_range','2003-11-11', '2003-11-11');
$downloads->setState('filter.end_date_range', '2003-11-11', '2003-11-11');
$downloads->setState('filter.date_filtering', 'range');
Which works as filter!
I only now need the  date_added from the current file to replace the date!
I suppose it is something like this: getItem->($id)   getState('date_added')
Could you help me this small last part?
;D
If it works i will try to adjust the xml parameter and rename the module so that it is usable for other users too!

Tazzios




I have made a (dirty)work around for the time being. This way i can continue on the module parameter options like a choice between relative date and date range.

the code components/com_jdownloads/models/downloads.php 473 and 474 currently checks datetime instead of only the date I guess this is a bug.
Here is an fix:

$query->where(date('.$dateField.') >= '.$startDateRange.' AND date('.$dateField .
') <= '.$endDateRange.');
   

So to get it working:
Do the fix above and the following
modules/mod_jdownloads_related/ Helper.php 83
disable the category filter if you wish

//$downloads->setState('filter.start_date_range','2003-11-11', '2003-11-11');
//$downloads->setState('filter.end_date_range', '2003-11-11', '2003-11-11');
$downloads->setState('filter.date_filtering', 'range');

$Daterange_filter_field= $params->get('Daterange_filter_field', 'a.date_added');
$downloads->setState('filter.start_date_range', ' (select date(' . $Daterange_filter_field . ') from #__jdownloads_files a where a.file_id= ' . $id . ') ' , '');
$downloads->setState('filter.end_date_range', ' (select date(' . $Daterange_filter_field . ') from #__jdownloads_files a where a.file_id= ' . $id . ') ' , '');

components/com_jdownloads/models/downloads.php  line 471,472 the DBqoutes need to be removed else the query will be htread as a string
$startDateRange = $this->getState('filter.start_date_range', $nullDate);
$endDateRange = $this->getState('filter.end_date_range', $nullDate);

modules/mod_jdownloads_related/mod_jdownloads_related.xml line 118
This way you can currently choose between added and modified date.

<field name="Daterange_filter_field" type="list" default="a.date_added" label="MOD_JDOWNLOADS_RELATED_DATE" description="MOD_JDOWNLOADS_RELATED_DATE_DESC">
                    <option value="a.date_added">MOD_JDOWNLOADS_RELATED_CREATED_DATE</option>
                    <option value="a.modified_date">MOD_JDOWNLOADS_RELATED_MODIFIED_DATE</option>
</field>

ColinM

Hi
You are obviously making good progress. :)
Have posted the bit about bug with  date vs datetime as a bug.  But if one sets the time part to zero does that not do the same thing in effect - perhaps 11:59:9999 for end time.Colin
Colin M
  •  

Tazzios


If you convert to date the time is non existing any more so you don`t have to do anything with time.
Except making sure dat the parameter you throw in is a date and not a datetime.
For safety it is an option to convert the parameter also in the query to a date like this:
$query->where(date('.$dateField.') >= date('.$startDateRange.') AND date('.$dateField .
') <= date('.$endDateRange.'));

ColinM

HiSo we just use just the date part which is AOK
Looks like you have the module in a good shape.  If you could send me a a zip of the module in a PM I will test it out and document.  Also I will convert to operate on the upcoming jD3.9 series to see it works their.  And ask Arno if he could include in the installation for jD 3.9 which is close to first public beta test.Best wishesColin
Colin M
  •  

Tazzios

If i can get an example how i can retrieve information(like date_added) when i only have a file ID in this file: modules/mod_jdownloads_related/Helper.php 83.
Then i would not have to hack out the dbqoutes in this one which  makes it less safe: components/com_jdownloads/models/downloads.php  line 471,472


In this topic(http://www.jdownloads.com/forum/index.php?topic=8543.msg43799#msg43799) i have placed a zip with al my edits (pdf and related module) I can make one only with the module files, but like i said hacking the core files can be avoid if i can get an example (as my last program was 6 years ago in vb.net :P). i can improve the code and document it a bit further.

ColinM

Hi
Could we send info via PMs as your Zip had been downloaded  multiple times before I saw it
Colin
Colin M
  •