Location: PHPKode > projects > Knowledge Box > knowledgebox/classes/relationClass.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
   * KBModuleRelation
   */
  class KBModuleRelation extends CDpObject
  {
    var $entry_id;
    var $keyword_id;


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

    /*
     * getKeywordId ()
     */
    function getKeywordId ()
    {
      return $this->keyword_id;
    }
    
    /*
     * setKeywordId ()
     */
    function setKeywordId ($keyword_id)
    {
      $this->keyword_id = (int) $keyword_id;
    }

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

      // execute
      db_exec ($sql);
    }

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

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

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

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

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

      // return
      return $r;
    }
    
    /*
     * getRelationsByKeyword ()
     */
    function getRelationsByKeyword ($keyword_id)
    {
      $r = array ();

      // sql
      $sql  = "SELECT * FROM " . KB_TABLE_RELATIONS;
      $sql .= " WHERE keyword_id = " . $keyword_id;

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

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

      // return
      return $r;
    }
    
    /*
     * getRelation ()
     */
    function getRelation ($entry_id, $keyword_id)
    {
      // sql
      $sql  = "SELECT * FROM " . KB_TABLE_RELATIONS;
      $sql .= " WHERE entry_id = '" . (int) $entry_id . "'";
      $sql .= " AND keyword_id = '" . (int) $keyword_id . "'";

      // load
      $obj = new KBModuleRelation ();

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

      // return
      return $obj;
    }

  }

?>
Return current item: Knowledge Box