Location: PHPKode > projects > Jarida > jarida_1.0/classes/Article.php
<?php
                                                                                                                       
/*
                                                                                                                             
-------------------------------------------------------------------------
                                                                                                                             
Article Class
      A class to be used to handle Articles.
                                                                                                                             
-------------------------------------------------------------------------
                                                                                                                             
Developer
      Name -- Haddad Said.
      Date -- 16-07-2005
      Version -- 1.0
                                                                                                                             
-------------------------------------------------------------------------
                                                                                                                             
Member Functions
     
      1.edit
      2.delete
      3.setTitle
      4.getTitle
      5.setBody
      6.getBody
      7.setDate
      8.getDate
      9.getNumComments
     10.getComments
     

-------------------------------------------------------------------------
                                                                                                                             
*/


class Article extends Entry
{

  //Vars to hold attributes of the article
  var $body;
  var $views;
  var $title;
  var $date;



  /*

-------------------------------------------------------------------------
Class Constructor
      
Parameters:
      &db
      id


Notes:
      

Example Usage:
     
-------------------------------------------------------------------------

  */

  function Article(&$db, $id)
  {
    parent::Entry($db, $id);
    $query = "SELECT article_title, article_date, article_body
               FROM tblArticle WHERE article_id = " . $this->getId();

    if($this->result = $this->db->doQuery($query))
      {
		$row = $this->result->getArray();
		$this->setBody($row['article_body']);
		$this->setDate($row['article_date']);
		$this->setTitle($row['article_title']);
      }
    else
      {
		return false;
      }
  }



  /*

-------------------------------------------------------------------------
Function edit
      
Parameters:
     

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */

  function edit()
  {
    $query = "UPDATE tblArticle SET article_body = '" . $this->getBody() ."', 
                                 article_title = '" . $this->getTitle() . "' 
              WHERE article_id = ". $this->getId();

    if($this->result = $this->db->doQuery($query))
      {
		return true;
      }
    else
      {
		return false;
      }
  }


  /*

-------------------------------------------------------------------------
Function delete
      
Parameters:


Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */

  function delete()
  {
    return(parent::delete("tblArticle", "article_id"));
  }




  /*

-------------------------------------------------------------------------
Function setBody
      
Parameters:
      body

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */

  function setBody($body)
  {
    $this->body = $body;
  }



  /*

-------------------------------------------------------------------------
Function getBody
      
Parameters:
      

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */


  function getBody()
  {
    return $this->body;
  }



  /*

-------------------------------------------------------------------------
Function setTitle
      
Parameters:
      title

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */

  function setTitle($title)
  {
    $this->title = $title;
  }


  /*

-------------------------------------------------------------------------
Function getTitle
      
Parameters:
      

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */

  function getTitle()
  {
    return $this->title;
  }




  /*

-------------------------------------------------------------------------
Function setDate
      
Parameters:
      date

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */

  function setDate($date)
  {
    $this->date = $date;
  }



  /*

-------------------------------------------------------------------------
Function getDate
      
Parameters:
      

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */


  function getDate()
  {
    return $this->date;
  }



  /*

-------------------------------------------------------------------------
Function getNumComments
      
Parameters:
      

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */


  function getNumComments()
  {
    $query = "SELECT comment_id FROM tblArticleComment WHERE 
               comment_article_id = " . $this->getId();

    $this->result = $this->db->doQuery($query);

    return $this->result->getNumRows();
  }



  /*

-------------------------------------------------------------------------
Function getComments
      
Parameters:
      

Notes:
      

Example Usage:

-------------------------------------------------------------------------

  */


  function getComments()
  {
    $query = "SELECT comment_id FROM tblArticleComment WHERE 
               comment_article_id = " . $this->getId() . " ORDER BY comment_id ASC";

    $this->result = $this->db->doQuery($query);
    while($row = $this->result->getArray())
      {
	$comments[] = new ArticleComment($this->db, $row['comment_id']);
      }

    return $comments;
  }



}



?>
Return current item: Jarida