Location: PHPKode > projects > Knowledge Box > knowledgebox/classes/relativeClass.php
<?php

  /*
   * Free IT Foundation
   * Free Technology Serving Knowledge
   * http://www.free-it-foundation.org
   * 
   * This file is part of Knowledge Box.
   * 
   * Knowledge Box is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   * 
   * Knowledge Box is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with Knowledge Box.  If not, see <http://www.gnu.org/licenses/>.
   */


  /*
   * class
   * KBModuleRelative
   */
  class KBModuleRelative extends CDpObject
  {
    var $entry_id;
    var $relative_id;


    /*
     * constructor
     */
    function KBModuleRelative ()
    {
      // void
    }
    
    /*
     * getEntryId ()
     */
    function getEntryId ()
    {
      return $this->entry_id;
    }
    
    /*
     * setEntryId ()
     */
    function setEntryId ($entry_id)
    {
      $this->entry_id = (int) $entry_id;
    }

    /*
     * getRelativeId ()
     */
    function getRelativeId ()
    {
      return $this->relative_id;
    }
    
    /*
     * setRelativeId ()
     */
    function setRelativeId ($relative_id)
    {
      $this->relative_id = (int) $relative_id;
    }

    /*
     * store ()
     */
    function store ()
    {
      // insert
      $sql  = "INSERT INTO `" . KB_TABLE_RELATIVES . "`";
      $sql .= " ( `entry_id` , `relative_id` )";
      $sql .= " VALUES (";
      $sql .= "  '" . $this->entry_id . "', '" . $this->relative_id . "'";
      $sql .= ")";

      // execute
      db_exec ($sql);
    }

    /*
     * delete ()
     */
    function delete ()
    {
      // sql
      $sql  = "DELETE FROM " . KB_TABLE_RELATIVES;
      $sql .= " WHERE entry_id = " . $this->entry_id;
      $sql .= " AND relative_id = " . $this->relative_id;

      // execute
      db_exec ($sql);
    }
    
    /*
     * getRelativesByEntry ()
     */
    function getRelativesByEntry ($entry_id)
    {
      $r = array ();

      // sql
      $sql  = "SELECT * FROM " . KB_TABLE_RELATIVES;
      $sql .= " WHERE entry_id = " . $entry_id;

      // load
      $hash = db_loadList ($sql);

      // bind
      foreach ($hash as $row)
      {
        $obj = new KBModuleRelative ();
        bindHashToObject ($row, $obj);
        
        $r [] = $obj;
      }

      // return
      return $r;
    }
    
    /*
     * getRelative ()
     */
    function getRelative ($entry_id, $relative_id)
    {
      // sql
      $sql  = "SELECT * FROM " . KB_TABLE_RELATIVES;
      $sql .= " WHERE entry_id = '" . (int) $entry_id . "'";
      $sql .= " AND relative_id = '" . (int) $relative_id . "'";

      // load
      $obj = new KBModuleRelative ();

      // bind
      db_loadObject ($sql, $obj);

      // return
      return $obj;
    }

  }

?>
Return current item: Knowledge Box