Back to Campsite API.

Example Usage of Article API

To create a new article, you would do the following:

// Create the article object (does not create anything in the database).
$article =& new Article(languageId);
// Create the row in the database.
$article->create(articleType, optional_name_of_article);
// Get the article number.
$articleNumber = $article->getArticleNumber();

To display the input fields of the article, you would do the following:

// To retrieve an article from the database, specify the language ID and
// article number in the constructor.
$article =& new Article(languageId, articleNumber);
// The article type object stores the dynamic data for an article.
$articleData = $article->getArticleTypeObject();
// Get all the dynamic fields in the article (this returns
// an array of DbColumn objects).
$fields = $articleData->getUserDefinedColumns();
// Iterate through all the fields and display each one.
foreach ($fields as $field) {
	// Prompt the user with the name of the field.
	echo $field->getPrintName().":";
	// Article types can be "char", "date", or "blob".
	switch ($field->getType()) {
	case "char":
		...
		break;
	case "date":
		...
		break;
	case "blob":
		echo '<textarea name="'
			.$field->getName().'"></textarea><br>';
		break;
	}
}

To save an article:

$article =& new Article(languageId, articleId);
$articleData =& $article->getArticleTypeObject();
$fields = $articleData->getUserDefinedColumns();
foreach ($fields as $field) {
	$dbColumnName = $field->getName();
	if (isset($_REQUEST[$name])) {
		$articleData->setProperty($name, $_REQUEST[$name]);
	}
}

Reference files (in a default install):

/usr/local/campsite/www-common/html/classes/Article.php
/usr/local/campsite/www-common/html/classes/ArticleType.php
/usr/local/campsite/www-common/html/classes/DbColumn.php
/usr/local/campsite/www-common/html/priv/articles/edit.php
/usr/local/campsite/www-common/html/priv/articles/do_edit.php