I. Object Methods

Midgard 1.4 'Bifrost' introduces and object oriented aproach to the creation and manipulation of records. This allows for better readable code. It also can save typing, especially when updating records. This section covers the object oriented methods, and to what objects they are available.

The OOP-style functions simplify the handling of Midgard records. They allow you to set the record fields first and then just call a no-argument method to update the database contents. No more need to copy or reset all unused extra fields. Consider the difference:

Old style:

<?php
mgd_create_article(0, $topic, '', $title, $abstract, $content,
                   $midgard->user, '', '', 0, 0, 0, 0,
                   '', '', '', 0);
?>

OOP style:

<?php
  $article = mgd_get_article();
  $article->topic = $topic;
  $article->title = $title;
  $article->abstract = $abstract;
  $article->content = $content;
  $article->author = $midgard->user;
  $article->create();
?>

Yes, it is more lines, but the code is a lot clearer and easier to write. Another, even better example, setting an extra field of an article:

Old style:

<?php
  $article = mgd_get_article($id);
  mgd_update_article($id, $article->topic, $article->name,
                     $article->title, $article->abstract, 
                     $article->content, $article->author,
                     $article->url, $article->calstart,
                     $article->caldays, $article->icon, 
                     $article->view, $article->print,
                     $extra, $article->extra2, $article->extra3);
?>

OOP style:

<?php
  $article = mgd_get_article($id);
  $article->extra1 = $extra;
  $article->update();
?>
 
 
A
r
t
i
c
l
e
 
A
t
t
a
c
h
m
e
n
t
 
E
l
e
m
e
n
t
 
E
v
e
n
t
 
E
v
e
n
t
M
e
m
b
e
r
 
G
r
o
u
p
 
H
o
s
t
 
M
e
m
b
e
r
 
P
a
g
e
 
P
a
g
e
E
l
e
m
e
n
t
 
P
a
g
e
l
i
n
k
 
P
e
r
s
o
n
 
P
r
e
f
e
r
e
n
c
e
 
S
i
t
e
g
r
o
u
p
 
S
n
i
p
p
e
t
 
S
n
i
p
p
e
t
d
i
r
 
S
t
y
l
e
 
T
o
p
i
c
$object->fetch()XXXXXXXXXXXXXXXXXX
$object->create()X XXXXXXXXXXXXXXXX
$object->update()XXXXXXXXXXXXXXXXXX
$object->delete()XXXXXXXXXXXXXXXXXX
$object->setsitegroup()XXXXXXXXXXXXX XXXX
$object->getsitegroup()XXXXXXXXXXXXX XXXX
$object->parameter()XXXXXXXXXXXXXXXXXX
$object->listparameters()XXXXXXXXXXXXXXXXXX
$object->searchparameters()XXXXXXXXXXXXXXXXXX
$object->setscore()X                 
$object->settype()X  X              
$object->createattachment()XXXXXXXXXXXXXXXXXX
$object->updateattachment()XXXXXXXXXXXXXXXXXX
$object->deleteattachment()XXXXXXXXXXXXXXXXXX
$object->getattachment()XXXXXXXXXXXXXXXXXX
$object->listattachment()XXXXXXXXXXXXXXXXXX
$object->openattachment()XXXXXXXXXXXXXXXXXX
$object->serveattachment()XXXXXXXXXXXXXXXXXX
$object->stat() X                

Table 1. Object methods

Table of Contents
$object->fetch — Fetch a record
$object->create — Create a record
$object->update — Update a record
$object->delete — Delete a record
$object->getsitegroup — Get the sitegroup a record belongs to
$object->setsitegroup — Set the sitegroup a record belongs to
$object->parameter — Set or get a record parameter
$object->listparameters — List the parameters/parameter domains for a record
$object->searchparameters — Search record parameters
$object->setscore — Set the score of a record
$object->settype — Set the type of a record
$object->createattachment — Create a record attachment
$object->updateattachment — Update a record attachment
$object->deleteattachment — Delete a record attachment
$object->getattachment — Get a record attachment
$object->listattachments — List the attachments to a record
$object->openattachment — Open a filehandle to an attachment
$object->serveattachment — Serve a record attachment
$object->stat — Gives information about an attachment