Extending MidgardArticle
Wrapper Class for MidgardArticle.
In addition to the features described in Extending the Midgard Classes CArticle features additional object methods to (un)approve the article.
Code
<?php
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// $Id: carticle.php,v 1.8 2002/09/10 23:30:47 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 CArticle extends MidgardArticle {
function CArticle ($id = -1, $article_name = NULL) {
// if called with empty parameter set or explicitly
// with first param = -1
if ($id == -1) {
$article = mgd_get_article();
if (! $article) {
$this = FALSE;
return FALSE;
}
}
// if called with one parameter it's the article ID
elseif ($article_name === NULL) {
$article = mgd_get_article($id);
if (! $article) {
$this = FALSE;
return FALSE;
}
}
// if called with both id and name it should refer
// to parent topic id and article name to be found in this topic
else {
$article = mgd_get_article_by_name($id, $article_name);
if (! $article) {
$this = FALSE;
return FALSE;
}
}
$this->_copy_mgd_data($article);
}
function create() {
$newid = MidgardArticle::create();
if (!$newid)
return FALSE;
$newarticle = mgd_get_article ($newid);
if (! $newarticle)
return FALSE;
$this->_copy_mgd_data($newarticle);
return $newid;
}
function update() {
// MidgardArticle::update() is broken, bug #153
if (! mgd_update_article($this->id, $this->topic, $this->name,
$this->title, $this->abstract, $this->content, $this->author,
$this->url, $this->calstart, $this->caldays, $this->icon,
$this->view, $this->print, $this->extra1, $this->extra2,
$this->extra3)) return FALSE;
$newarticle = mgd_get_article($this->id);
if (! $newarticle) return FALSE;
$this->_copy_mgd_data($newarticle);
return TRUE;
}
function delete() {
// Remove dependencies
$ret = $this->_delete_dependants($this);
if (! $ret) return($ret);
return MidgardArticle::delete();
}
function deleteattachment($name) {
$attlist = $this->listattachments();
if ($attlist) while ($attlist->fetch()) {
if ($attlist->name != $name) continue;
$att = mgd_get_attachment($attlist->id);
$ret = $this->_delete_dependants($att);
if (! $ret) return($ret);
return(mgd_delete_attachment($attlist->id));
}
return(FALSE); // Attachment $name not found
}
function approve() {
if (! mgd_approve_article ($this->id, TRUE))
return FALSE;
$article = mgd_get_article ($this->id);
$this->_copy_mgd_data($article);
return TRUE;
}
function unapprove() {
if (! mgd_approve_article ($this->id, FALSE))
return FALSE;
$article = mgd_get_article ($this->id);
$this->_copy_mgd_data($article);
return TRUE;
}
function is_approved() {
return ($this->approved ? TRUE : FALSE);
}
// == PRIVATE METHODS =====================================================
function _copy_mgd_data($article) {
$this->__table__ = $article->__table__;
$this->id = $article->id;
$this->up = $article->up;
$this->topic = $article->topic;
$this->name = $article->name;
$this->title = $article->title;
$this->abstract = $article->abstract;
$this->content = $article->content;
$this->author = $article->author;
$this->date = $article->date;
$this->adate = $article->adate;
$this->aldate = $article->aldate;
$this->extra1 = $article->extra1;
$this->extra2 = $article->extra2;
$this->extra3 = $article->extra3;
$this->score = $article->score;
$this->type = $article->type;
$this->created = $article->created;
$this->creator = $article->creator;
$this->revised = $article->revised;
$this->revisor = $article->revisor;
$this->revision = $article->revision;
$this->approved = $article->approved;
$this->approver = $article->approver;
$this->url = $article->url;
$this->icon = $article->icon;
$this->view = $article->view;
$this->print = $article->print;
$this->calendar = $article->calendar;
$this->acalendar = $article->acalendar;
$this->alcalendar = $article->alcalendar;
$this->startdate = $article->startdate;
$this->enddate = $article->enddate;
$this->calstart = $article->calstart;
$this->calstop = $article->calstop;
$this->caldays = $article->caldays;
}
function _delete_dependants(&$object) {
// List and remove parameters
$domainlist = $object->listparameters();
if ($domainlist) while ($domainlist->fetch()) {
$paramlist = $object->listparameters($domainlist->domain);
if ($paramlist) while ($paramlist->fetch()) {
$ret = $object->parameter($domainlist->domain,
$paramlist->name, "");
// Cancel on error; a detailed message comes via mgd_errstr()
if (! $ret) return($ret);
}
}
if (! method_exists($object, "listattachments"))
return(TRUE); // $object is an attachment :-)
// List and remove attachments, including their parameters
$attlist = $object->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 = $att->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(TRUE);
}
// == COMPATIBILITY METHODS ===============================================
function Unapprove () {
return($this->unapprove());
}
function IsApproved () {
return($this->is_approved());
}
function Approve () {
return($this->approve());
}
}
?>