API Addon - OVML

De OviWiki
Révision de 12 janvier 2007 à 17:22 par Nouaya (discussion | contributions) (Utilisation)

Aller à : navigation, rechercher

Introduction

L'API addon-OvML permet à un addon d'accéder à tous les containers OVML. Il est ainsi possible à un addon de lister les catégories, les thèmes d'articles, les articles, les contributions d'un forum etc ...

Tous les fonctionnalités offertes par l'OVML sont ainsi disponibles à un addon.

Utilisation

Afin d'utiliser cette API, l'addon doit inclure le fichier ovmlapi.php:

include_once $babInstallPath.'utilit/ovmlapi.php';

L'interraction de l'addon avec cette API se fait par l'intermédiaire de la classe bab_ovmlAPI:

include_once $babInstallPath.'utilit/ovmlapi.php';

function list_topics()
{
	global $babBody;

	class list_topics_class
		{
		function list_topics_class()
			{
			$this->tpl = new bab_ovmlAPI();
			}
		}
...

}

L'instanciation de cette classe créé un context global pour l'OVML. Il est possible de passer des variables à cet context en utilisant le paramètre $args:

include_once $babInstallPath.'utilit/ovmlapi.php';

function list_topics()
{
	global $babBody;

	class list_topics_class
		{
		function list_topics_class()
			{
			$args['babHtmlEntities'] = 1;
			$args['topics'] = bab_gp('topicid');
			$this->tpl = new bab_ovmlAPI($args);
			}
		}
...
}

L'instantiation d'un container OVML se fait par la méthode getContainer:

include_once $babInstallPath.'utilit/ovmlapi.php';

function list_topics()
{
	global $babBody;

	class list_topics_class
		{
		function list_topics_class()
			{
			$this->tpl = new bab_ovmlAPI();
			$args['topicid'] = 12;
			$args['archive']='No';
			$args['topicorder']='Yes';
			$this->cont = $this->tpl->getContainer('ArticleTopics', $args);
			}
		}
...
}

Dans ce qui précède on instancie le container OCArticleTopics et on lui passe les paramètres topicid, archive et topicorder.

On peut ajouter des paramètres au context courant et en récupérer en utilisant les deux méthodes suivantes:

$vars[] = array('name'=>'count', 'value' => $count);
$vars[] = array('name'=>'index', 'value' => 0);
$this->tpl->putVar($vars);
$title = $this->tpl->getVar('ArticleTitle');
$author = $this->tpl->getVar('ArticleAuthor', array('author'=>'%F %L'))

La méthode 'getContainer' retourne un objet implémentant la méthode 'getnext' permettant de récupérer les résultats du containers. La méthode 'getnext' retourne false quand il n'y a plus de résulat et true dans le cas contraire. Quand la méthode retourne false, elle détruit automatiquement son context. Sinon vous avez la possibilité de détruire le context en appelant la méthode:


$this->cont = $this->tpl->getContainer('ArticleTopics', $args);
$thsi->cont->destroyContext();

L'appel à 'destroyContext' détruit le context courant et supprime les variables.

Normalement, à chaque appel à la methode 'getnext', le système créé les variables du container dans l'objet implémntant la méthode 'getnext':


include_once $babInstallPath.'utilit/ovmlapi.php';

function list_articles()
{
	global $babBody;

	class list_articles_class
		{
		function list_articles_class()
			{
			$this->tpl = new bab_ovmlAPI();
			$args['topicid'] = 12;
			$args['archive']='No';
			$args['topicorder']='Yes';
			$this->cont = $this->tpl->getContainer('ArticleTopics', $args);
			}

		function getnextarticle()
			{
			if( $this->cont->getnext() )
				{
				$this->title =  $this->cont->ArticleTitle;
				return true;
				}
			else
				{
				return false;
				}
			}
		
		}
...
}

Si l'on souhaite créer ces variables dans un autre objet, on peut passer cet objet à chaque appel à la fonction 'getnext':

include_once $babInstallPath.'utilit/ovmlapi.php';

function list_articles()
{
	global $babBody;

	class list_articles_class
		{
		function list_articles_class()
			{
			$this->tpl = new bab_ovmlAPI();
			$args['topicid'] = 12;
			$args['archive']='No';
			$args['topicorder']='Yes';
			$this->cont = $this->tpl->getContainer('ArticleTopics', $args);
			}

		function getnextarticle()
			{
			if( $this->cont->getnext($this) )
				{
				echo $this->ArticleTitle;
				return true;
				}
			else
				{
				return false;
				}
			}
		
		}
...
}