/*
* Table Definition for article
*/
require_once 'DB/DataObject.php';
require_once 'DataObjects/Topic.php';
require_once 'DataObjects/Blobs.php';
class DataObjects_Article extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
var $__table = 'article'; // table name
var $id; // int(11) not_null primary_key auto_increment
var $up; // int(11) not_null
var $topic; // int(11) not_null multiple_key
var $title; // string(255) not_null
var $abstract; // blob(16777215) not_null blob
var $content; // blob(16777215) not_null blob
var $author; // int(11) not_null
var $created; // datetime(19) not_null
var $url; // string(255) not_null
var $calstart; // date(10)
var $caldays; // int(11) not_null
var $icon; // int(11) not_null
var $view; // int(11) not_null
var $print; // int(11) not_null
var $extra1; // string(255) not_null
var $extra2; // string(255) not_null
var $extra3; // string(255) not_null
var $name; // string(255) not_null multiple_key
var $creator; // int(11) not_null
var $revisor; // int(11) not_null
var $revision; // int(11) not_null
var $approver; // int(11) not_null
var $revised; // datetime(19) not_null
var $approved; // datetime(19) not_null
var $score; // int(11) not_null
var $type; // int(11) not_null
var $locked; // datetime(19) not_null
var $locker; // int(11) not_null
var $sitegroup; // int(11) not_null multiple_key
/* ZE2 compatibility trick*/
function __clone() { return $this;}
/* Static get */
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Article',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function DataObjects_Article() {
$auth = PEAR::getStaticProperty('Auth','singleton');
if (!method_exists($auth,'getSitegroup')) {
return;
}
$sitegroup = $auth->getSitegroup();
if ($sitegroup) {
$this->whereAdd("sitegroup in (0,$sitegroup)");
}
}
function staticList($k,$v) {
$t = new DataObjects_Article;
$t->$k = $v;
$t->orderBy('created DESC');
$t->find();
return $t;
}
function staticGetByPath($request) {
if (!$request) {
return;
}
//echo "REQUEST: $request";
$topicname = dirname($request);
$articlename = rawurldecode(basename($request));
//echo "GET TOPIC $topicname";
//echo "GET ARTICLE $articlename";
if ($topic = DataObjects_Topic::staticGetByPath($topicname)) {
$article = DataObjects_Article::staticGetTopicArticle($topic->id,'name',$articlename);
}
return $article;
}
function staticGetTopicArticle($up,$key,$val) {
$article = new DataObjects_Article;
$article->topic = $up;
$article->get($key,$val);
if (!$article->N) {
return;
}
return $article;
}
function buildIconBlob() {
//return;
//echo " {$this->view} ";
$this->iconBlob = "";
if ($this->view) {
$this->iconBlob = DataObjects_Blobs::staticGet( $this->view);
//echo "{$this->iconBlob->name} ";
$this->iconBlob->getUrl();
$this->iconBlob->hspace = (int) ((100- $this->iconBlob->sizex) /2) + 5;
return;
}
//echo "LOOKING FOR IMG";
$atts = $this->listattachments();
//echo "GOT?";print_r($atts);
if (!$atts) {
return;
}
while ($atts->fetch()) {
//echo "tESTING {$atts->name}
";
if (!preg_match("/00x100\.([a-z]+)$/i",$atts->name)) continue;
//echo "returning /attachment/{$sg_guid}{$guid}/.".urlencode($atts->name);
$atts->getUrl();
$atts->hspace = (int) ((100- $atts->sizex) /2) + 5;
$this->iconBlob = $atts;
$t = DataObjects_Article::staticGet($this->id);
$t->view = $atts->id;
$t->update();
//echo "
";print_r($atts);echo ""; return; } } function listattachments() { return DataObjects_Blobs::staticList(get_class($this),$this->id); } function getSortedAttachments() { return DataObjects_Blobs::staticGetSortedAttachments(get_class($this),$this->id); } function getAttachment($k,$v=NULL) { $t = new DataObjects_Blobs; $t->ptable = substr(get_class($this),strlen('dataobjects_')); $t->pid = $this->id; $t->get($k,$v); if (!$t->N) { return; } return $t; } function createAttachment(&$attachment, $data,$size) { $attachment->ptable = substr(get_class($this),strlen('dataobjects_')); $attachment->pid = $this->id; $attachment->insert(); $attachment->updateData($data,$size); } function findChildren($id) { $this->topic = $id; $this->find(); } function getParent() { return DataObjects_Topic::staticGet($this->topic); } /* can methods - can delete can create etc. */ function canEdit() { $parent = $this->getParent(); if (!$parent) { echo "
"; print_r($this);
}
return $parent->canEdit();
}
function canCreate() {
return $this->canEdit();
}
function canDelete() {
return $this->canEdit();
}
/* overrides */
function insert() {
//$this->_setSitegroup(); not at present!
$this->_setAuthor();
$this->_setCreated();
$this->_setRevised();
if (!$this->title) {
$this->title = $this->name;
}
return parent::insert();
}
function update() {
$this->_setAuthor();
$this->_setRevised();
return parent::update();
}
/* set author */
function _setAuthor() {
//$auth = PEAR::getStaticProperty('Auth','singleton');
//$this->author = $auth->getUserId();
}
/* set created/creator */
function _setCreated() {
//$auth = PEAR::getStaticProperty('Auth','singleton');
//$this->creator = $auth->getUserId();
$date = new Date(time());
$this->created = $date->format('%Y-%m-%d %H:%M:%S');
}
/* set revised/revisor */
function _setRevised() {
//$auth = PEAR::getStaticProperty('Auth','singleton');
//$this->revisor = $auth->getUserId();
$date = new Date(time());
$this->revised = $date->format('%Y-%m-%d %H:%M:%S');
$this->revision++;
}
function getLinkUrl() {
$parent = $this->getParent();
$base = $parent->getLinkUrl('');
return $base . '/'.$this->name;
}
function getContent() {
echo "LINK URL = ". $this->getLinkUrl();
return $this->content;
}
function dumptoFs($dir) {
$thisname = "{$dir}/{$this->name}";
//print_r($this);
$title = $this->title;
if (!strlen($this->title)) $title = $this->name;
$out = "".htmlspecialchars($title)." ";
$out .= $this->abstract . "
";
if (strlen(trim($this->content))) {
$out .= "\n\n\n
__BODY__\n\n" . $this->content;
}
$out .= '';
$this->file_write_contents("{$thisname}.html",$out);
$blobs = $this->listAttachments();
if (!$blobs) {
return;
}
while ($blobs->fetch()) {
$blobs->dumptoFs($thisname);
}
}
function file_write_contents($file,$cont) {
//echo 'mkdir -p '. escapeshellarg(dirname($file));
if (file_exists($file)) {
return;
}
mkdir(dirname($file));
$fh = fopen($file, 'w');
fwrite($fh,$cont);
fclose($fh);
}
function listTopic($id) {
$ret = new DataObjects_Article;
$ret->topic = $id;
$ret->find();
return $ret;
}
}
?>