Extending MidgardTopic

Wrapper Class for MidgardTopic. This class is not as far developed as CArticle or CPerson are, so if you need more methods (update(), delete(), etc.), look there and just port them :-).


Code

<?php

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// $Id: ctopic.php,v 1.6 2002/09/10 23:36:19 philipp Exp $
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Midgard Base Classes:
// http://www.nathan-syntronics.de/midgard/oop/baseclasses/
//
// The Midgard Base Classes build an infrastructure to create
// new classes based on Midgard Objects as direct inheritance
// from the original MidgardXXXX classes defined in Midgard's
// PHP extension has some serious drawbacks.  For more info see
// the URL above.
//
// Legal information: Most of this code was built by various
// developers for Linksystem Muenchen GmbH, Munich, Germany
// (http://www.link-m.de). It's therefore copyright (c) 2001-02
// Linksystem Muenchen GmbH, but you are free to use, modify and
// redistribute it under the terms of the GNU Lesser General
// Public License published by the Free Software Foundation;
// version 2.1 of the license (Feb 1999).
// This code 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 Lesser General Public License for more details:
// http://www.gnu.org/copyleft/lesser.html
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

class CTopic extends MidgardTopic {

    function
CTopic ($id = -1, $topic_name = NULL) {
    
        
// if called with empty parameter set or explicitly
        // with first param = -1
        
if ($id == -1) {
            
$topic = mgd_get_topic();
            if (!
$topic) {
                
$this = false;
                return
false;
            }
        }

        
// if called with one parameter it's the topic ID
        
elseif ($topic_name === NULL) {
            
$topic = mgd_get_topic($id);
            if (!
$topic) {
                
$this = false;
                return
false;
            }
        }

        
// if called with both id and name it should refer
        // to parent topic id and topic name to be found in this topic
        
else {
            
$topic = mgd_get_topic_by_name($id, $topic_name);
            if (!
$topic) {
                
$this = false;
                return
false;
            }
        }

        
$this->_copy_mgd_data($topic);
    }

    
// create()
    //
    // Create MidgardTopic object and populate our own fields.
    //
    
function create() {
        
$newid = MidgardTopic::create();
        if (!
$newid)
          return
false;
        
$newobject = mgd_get_topic ($newid);
        
$this->_copy_mgd_data($newobject);
        return
$newid;
    }
  
    
// delete()
    //
    // Removes direct dependants with the current object (parameters,
    // attachments, but NOT articles!).
    //
    
function delete() {

        
// List and remove parameters
        
$domainlist = $this->listparameters();
        if (
$domainlist) while ($domainlist->fetch()) {
            
$paramlist = $this->listparameters($domainlist->domain);
            if (
$paramlist) while ($paramlist->fetch()) {
                
$ret = $this->parameter($domainlist->domain,
                  
$paramlist->name, "");
                
// Cancel on error; a detailed message comes via mgd_errstr()
                
if (! $ret) return($ret);
            }
        }    
    
        
// List and remove attachments, including their parameters
        
$attlist = $this->listattachments();
        if (
$attlist) while ($attlist->fetch()) {
            
$att = mgd_get_attachment($attlist->id);
            
$attdomainlist = $att->listparameters();
            if (
$attdomainlist) while ($attdomainlist->fetch()) {
                
$attparamlist = $att->listparameters($attdomainlist->domain);
                if (
$attparamlist) while ($attparamlist->fetch()) {
                    
$ret = $this->parameter($attdomainlist->domain,
                      
$attparamlist->name, "");
                    
// Cancel on error; details in mgd_errstr()
                    
if (! $ret) return($ret);
                }
            }
            
$ret = mgd_delete_attachment($att->id);
            
// Cancel on error; a detailed message comes via mgd_errstr()
            
if (! $ret) return($ret);
        }

        return
MidgardTopic::delete();
    }
  

    
// == PRIVATE METHODS =====================================================

    
function _copy_mgd_data($topic) {
        
$this->__table__ = $topic->__table__;
        
$this->id = $topic->id;
        
$this->up = $topic->up;
        
$this->name = $topic->name;
        
$this->extra = $topic->extra;
        
$this->owner = $topic->owner;
        
$this->score = $topic->score;
        
$this->description = $topic->description;
        
$this->created = $topic->created;
        
$this->creator = $topic->creator;
        
$this->revised = $topic->revised;
        
$this->revisor = $topic->revisor;
        
$this->revision = $topic->revision;
        
$this->code = $topic->code;
    }

}

?>