test
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • midhat Friend
    #153678

    getLastUpdate 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 Friend
    #353292

    The 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_table

    midhat Friend
    #353343

    I 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 526

    Any 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 Friend
    #353351

    Please 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 Friend
    #353355

    Sorry 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’ type

    midhat Friend
    #353365

    I 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 Friend
    #353369

    It’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]

    midhat Friend
    #353374

    It is OK now, thank you very much.

    midhat Friend
    #353779

    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

    gray Friend
    #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 Friend
    #353792

    I want to getLastUpdate function monitor two fields in same time and displayed only one (last)

    gray Friend
    #353827

    try 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 Friend
    #354242

    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?

    gray Friend
    #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 Zone

    If 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.

Viewing 14 posts - 1 through 14 (of 14 total)

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