-
AuthorPosts
-
midhat Friend
midhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 20, 2010 at 8:58 pm #153678getLastUpdate function records the time of the last registered article.
My site is a web directory with almost 40,000 registered companies. Every day new companies are registered. Can we do that “Last update” records the last change in the web directory? (Component SOBI2)
Using getLastUpdate function of Gray:[PHP] # Get time of last updated article Hacked by Gray
function getLastUpdate(){
$db = &JFactory::getDBO();
$query = ‘SELECT created FROM #__content a ORDER BY created DESC LIMIT 1’;
$db->setQuery($query);
$data = $db->loadObject();if( $data->created ){
$user =& JFactory::getUser();
if ($user) {
$offset = $user->getParam(‘timezone’);
} else {
$offset = NULL;
}
$format = ‘%d.%m.%Y %H:%M’;
return JHTML::_(‘date’, $data->created, $format, $offset);
} else {
return ”; // emtpy string
}
} [/PHP]Thanks in advance
gray Friendgray
- Join date:
- October 2009
- Posts:
- 957
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 28
- Thanked:
- 292 times in 230 posts
August 20, 2010 at 11:36 pm #353292The function was updated by tienhc
[PHP]
function getLastUpdate(){
$db = &JFactory::getDBO();
$query = ‘SELECT created FROM #__content a ORDER BY created DESC LIMIT 1’;
$db->setQuery($query);
$data = $db->loadObject();if( $data->created ){
$user =& JFactory::getUser();
if ( $user->getParam(‘timezone’) ) {
$offset = $user->getParam(‘timezone’);
} else {
$conf =& JFactory::getConfig();
$offset = $conf->get(‘config.offset’);
}
$format = ‘%d.%m.%Y %H:%M’;
return JHTML::_(‘date’, $data->created, $format, $offset);
} else {
return ”; // emtpy string
}
}
[/PHP]To use other last updated source you have to change
$query = ‘SELECT created FROM #__content a ORDER BY created DESC LIMIT 1’;
to something like
$query = ‘SELECT created_field FROM #__sobi_table a ORDER BY created DESC LIMIT 1’;
where change created_field to SOBI data field of respective sobi_table1 user says Thank You to gray for this useful post
midhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 21, 2010 at 1:21 pm #353343I tried this and put your code. I changed the line:
$query = ‘SELECT data_txt FROM #__sobi2_fields_data a ORDER BY created DESC LIMIT 1’;
but does not work, I get the following error:
Notice: Trying to get property of non-object in …templatesja_teline_iiilibsja.template.helper.php on line 526Any changes in the web directory administrator must approve. Is it easier to make that getLastUpdate function change every time I log in as administrator
gray Friendgray
- Join date:
- October 2009
- Posts:
- 957
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 28
- Thanked:
- 292 times in 230 posts
August 21, 2010 at 4:32 pm #353351Please remove letter ‘a’ I see in your code and put data_txt instead of created
$query = ‘SELECT data_txt FROM #__sobi2_fields_data ORDER BY data_txt DESC LIMIT 1’;
if ‘data_txt’ field is correct (should be of ‘date’ type) and table name is correct – it should work.midhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 21, 2010 at 5:16 pm #353355Sorry for letter “a”, I’m just used a copy-paste.
Now is better, it not shows error, but do not get any time. The table jos __sobi2_fields_data has 9 fields, and I tried all, but not working. What does it mean of ‘date’ typemidhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 21, 2010 at 10:19 pm #353365I read a bit about MySQL and found what is the date type.
I found another table with field publish_up and changed the code so it now looks like this:
$query = ‘SELECT publish_up FROM #__sobi2_item ORDER BY publish_up DESC LIMIT 1’;
Still does not work, no error but the date does not appear.gray Friendgray
- Join date:
- October 2009
- Posts:
- 957
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 28
- Thanked:
- 292 times in 230 posts
August 22, 2010 at 8:00 am #353369It’s necessary to add respective reference to publish_up in the code. Try
[php]
function getLastUpdate(){
$db = &JFactory::getDBO();
$query = $query = ‘SELECT publish_up FROM #__sobi2_item ORDER BY publish_up DESC LIMIT 1’;
$db->setQuery($query);
$data = $db->loadObject();if( $data->publish_up ){
$user =& JFactory::getUser();
if ( $user->getParam(‘timezone’) ) {
$offset = $user->getParam(‘timezone’);
} else {
$conf =& JFactory::getConfig();
$offset = $conf->get(‘config.offset’);
}
$format = ‘%d.%m.%Y %H:%M’;
return JHTML::_(‘date’, $data->publish_up, $format, $offset);
} else {
return ”; // emtpy string
}
}
[/php]1 user says Thank You to gray for this useful post
midhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 22, 2010 at 9:57 am #353374It is OK now, thank you very much.
midhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 26, 2010 at 4:01 pm #353779Sorry, but it seems that I have another problem.
Is it possible to getLastUpdate function monitor two fields in one table.
There is another field ” last_update” in same table, that is also important if someone make a correction in profilegray Friendgray
- Join date:
- October 2009
- Posts:
- 957
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 28
- Thanked:
- 292 times in 230 posts
August 26, 2010 at 5:59 pm #353785<em>@midhat 191744 wrote:</em><blockquote>Sorry, but it seems that I have another problem.
Is it possible to getLastUpdate function monitor two fields in one table.
There is another field ” last_update” in same table, that is also important if someone make a correction in profile</blockquote>Just replace all instances of ‘publish_up’ with ‘last_update’ in the above function.
Or you want to have both displayed at the same time? What is the reason?midhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 26, 2010 at 8:49 pm #353792I want to getLastUpdate function monitor two fields in same time and displayed only one (last)
gray Friendgray
- Join date:
- October 2009
- Posts:
- 957
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 28
- Thanked:
- 292 times in 230 posts
August 27, 2010 at 4:41 am #353827try this one
[php]
<?php
function getLastUpdate(){$db = &JFactory::getDBO();
$query = $query = ‘SELECT publish_up FROM #__sobi2_item ORDER BY publish_up DESC LIMIT 1’;
$db->setQuery($query);
$publish = $db->loadObject();
$query = $query = ‘SELECT last_update FROM #__sobi2_item ORDER BY last_update DESC LIMIT 1’;
$db->setQuery($query);
$updated = $db->loadObject();if ($publish->publish_up > $updated->last_update) {
$date = $publish->publish_up;
} else {
$date = $updated->last_update;
}if ($date) {
$user =& JFactory::getUser();
if ( $user->getParam(‘timezone’) ) {
$offset = $user->getParam(‘timezone’);
} else {
$conf =& JFactory::getConfig();
$offset = $conf->get(‘config.offset’);
}
$format = ‘%d.%m.%Y %H:%M’;
return JHTML::_(‘date’, $date, $format, $offset);
} else {
return ”; // emtpy string
}
}
?>
[/php]midhat Friendmidhat
- Join date:
- January 2010
- Posts:
- 161
- Downloads:
- 101
- Uploads:
- 21
- Thanks:
- 43
- Thanked:
- 12 times in 1 posts
August 31, 2010 at 10:21 am #354242I apologize for the late reply.
Works, thanks a lot. But, show me 4 hours more. So at 1 pm show 5 hours in the afternoon. Can I fix it?gray Friendgray
- Join date:
- October 2009
- Posts:
- 957
- Downloads:
- 0
- Uploads:
- 17
- Thanks:
- 28
- Thanked:
- 292 times in 230 posts
August 31, 2010 at 1:44 pm #354252<em>@midhat 192321 wrote:</em><blockquote>I apologize for the late reply.
Works, thanks a lot. But, show me 4 hours more. So at 1 pm show 5 hours in the afternoon. Can I fix it?</blockquote>If you are not loged-in, time is offset by
[php]$offset = $conf->get(‘config.offset’);[/php]
Look at Global configurations, Server tab, Time ZoneIf it’s a logged-in user the following code works:
[php]$offset = $user->getParam(‘timezone’);[/php]
It’s set in User’s Time Zone configurations.Please review all this configurations.
-
AuthorPosts
This topic contains 14 replies, has 2 voices, and was last updated by gray 14 years, 3 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum