CMS MADE SIMPLE FORGE

CGBlog

 

[#8354] CGBlog articleid=-1 does not work

avatar
Created By: Deleted User (deleteduser_11200)
Date Submitted: Thu Sep 06 09:30:37 -0400 2012

Assigned To: Robert Campbell (calguy1000)
Version: 1.9.8
CMSMS Version: None
Severity: Trivial
Resolution: Fixed
State: Closed
Summary:
CGBlog articleid=-1 does not work
Detailed Description:
On my website I want to show the latest add CGBlog article via:

{CGBlog action='detail'}
{CGBlog action='detail' articleid="-1"}

This does not work.

By digging into your code base I found a typo inside
/modules/CGBlog/lib/class.cgblog_article.php -> public static function
&get_latest

 $query = 'SELECT mn.* FROM '.cms_db_prefix().'mdoule_cgblog mn WHERE';

should read

$query = 'SELECT mn.* FROM '.cms_db_prefix().'module_cgblog mn WHERE'


Besides $canviewdraft can either be TRUE|FALSE so the query should be executed
with or without placeholders.

    if (!$canviewdraft) {
        $row = $db->GetRow($query, $qparms);
    } else {
        $row = $db->GetRow($query);
    }


Your version:

public static function &get_latest($canviewdraft = FALSE,$get_fields =
'PUBLIC',$get_categories = TRUE)
  {
    $db = cmsms()->GetDb();
    $now = $db->DbTimeStamp(time());
    $query = 'SELECT mn.* FROM '.cms_db_prefix().'mdoule_cgblog mn WHERE';
    $qparms = array();
    if( !$canviewdraft )
      {
    $query .= ' status = ? AND ';
    $qparms[] = 'published';
      }
$query .= " (".$db->IfNull('start_time',$db->DBTimeStamp(1))." < $now) AND
";
$query .= "((".$db->IfNull('end_time',$db->DBTimeStamp(1))." =
".$db->DBTimeStamp(1).") OR (end_time > $now)) ";
    $query .= 'ORDER BY end_time,start_time DESC LIMIT 1';
    $row = $db->GetRow($query);

    $res = null;
    if( !is_array($row) ) {
      // todo: throw an exception?
      return $res;
    }

    return self::get_from_row($row);
  }


My version:


public static function &get_latest($canviewdraft = FALSE,$get_fields =
'PUBLIC',$get_categories = TRUE)
  {
    $db = cmsms()->GetDb();
    $now = $db->DbTimeStamp(time());
    $query = 'SELECT mn.* FROM '.cms_db_prefix().'module_cgblog mn WHERE';
    $qparms = array();
    if( !$canviewdraft )
      {
    $query .= ' status = ? AND ';
    $qparms[] = 'published';
      }
$query .= " (".$db->IfNull('start_time',$db->DBTimeStamp(1))." < $now) AND
";
$query .= "((".$db->IfNull('end_time',$db->DBTimeStamp(1))." =
".$db->DBTimeStamp(1).") OR (end_time > $now)) ";
    $query .= 'ORDER BY end_time,start_time DESC LIMIT 1';

    if (!$canviewdraft) {
        $row = $db->GetRow($query, $qparms);
    } else {
        $row = $db->GetRow($query);
    }

    $res = null;
    if( !is_array($row) ) {
      // todo: throw an exception?
      return $res;
    }

    return self::get_from_row($row);
  }



History

Comments
avatar
Date: 2013-09-04 13:52
Posted By: Robert Campbell (calguy1000)

fixed in svn.
      
Updates

Updated: 2014-04-01 12:29
state: Open => Closed

Updated: 2013-09-04 13:52
resolution_id: => 7
cmsms_version_id: 29730 => -1