Skip to content

Instantly share code, notes, and snippets.

@mikevalstar
Created May 23, 2011 15:22
Show Gist options
  • Save mikevalstar/986872 to your computer and use it in GitHub Desktop.
Save mikevalstar/986872 to your computer and use it in GitHub Desktop.
<?PHP
class article extends basedata{
var $_table = 'article';
var $_keycol = 'id_article';
var $_cols = array('title', 'short_txt', 'long_txt', 'posted', 'is_welcome', 'is_featured');
var $_createbycol = 'created_by';
var $_createwhencol = 'created_when';
var $_delbycol = 'deleted_by';
var $_delwhencol = 'is_deleted';
var $_editbycol = 'modified_by';
var $_editwhencol = 'modified_when';
function post(){
$sql = "UPDATE `{$this->_table}` SET `posted` = NOW() WHERE `{$this->_keycol}` = ? ";
$parms = array($this->id_article);
DBQuery2::prepare_execute($sql, $parms);
}
/* gets a list of all comments related to this article */
function comments(){
$sql = "SELECT concat(`name_first`, ' ', `name_last`) as `full_name`, `name_first`, `name_last`, `comment`, `created_when`
FROM `article_comment`, `user`
WHERE `id_user` = `created_by` AND `id_article` = ? AND `is_deleted` IS NULL
ORDER BY `created_when` ";
$parms = array($this->id_article);
$query = DBQuery2::prepare_execute($sql, $parms);
return $query->fetchAll();
}
/* posts a comment */
function post_comment($user, $comment){
$sql = "INSERT INTO `article_comment` SET `comment` = ?, `created_by` = ?, `id_article` = ?, `created_when` = NOW()";
$parms = array(htmlspecialchars($comment), $user, $this->id_article);
return DBQuery2::prepare_execute($sql, $parms);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment