* @revision 01 * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons Attribution-Share Alike 3.0 Germany * @homepage http://oss.tiggerswelt.net/xmpp * @copyright Copyright © 2010 tiggersWelt.net **/ require_once ('tiggerXMPP/xml/tag.php'); /** * Abstract class to handle XEP-0004 Forms * * @package tiggerXMPP * @class tiggerXMPP_XEP_0004_Form **/ class tiggerXMPP_XEP_0004_Form extends tiggerXMPP_XML_Tag { // General informations about this tag const TAG_NAME = 'x'; const TAG_NAMESPACE = 'jabber:x:data'; // Form-Types as of XEP-0004 const TYPE_CANCEL = 'cancel'; const TYPE_FORM = 'form'; const TYPE_RESULT = 'result'; const TYPE_SUBMIT = 'submit'; // Our attributes private $Type = tiggerXMPP_XEP_0004_Form::TYPE_FORM; // {{{ __construct /** * Create a new XML-Tag * * @param string $Name (optional) * @param object $Parent (optional) * @param string $Value (optional) * * @access friendly * @return void **/ function __construct ($Name = '', $Parent = null, $Value = null) { $this->setName (self::TAG_NAME); $this->setNamespace (self::TAG_NAMESPACE); $this->setParent ($Parent); } // }}} // {{{ getAttributes /** * Retrive a list of attributes for this tag * * @access protected * @return array **/ protected function getAttributes () { return array ( 'type' => $this->Type, ); } // }}} // {{{ setAttribute /** * Set an attribute of this tag * * @param string $Name * @param mixed $Value * * @access public * @return void **/ public function setAttribute ($Name, $Value) { if ($Name == 'type') return $this->setType ($Value); return parent::setAttribute ($Name, $Value); } // }}} // {{{ addSubtag /** * Append a tag to our collection * * @param object $Tag * * @access public * @return void **/ public function addSubtag ($Tag) { // Retrive the name of the new subtag switch ($Tag->getName ()) { case 'title': case 'instructions': case 'reported': $this->removeSubtagsByName ($N); break; case 'field': case 'item': break; default: return false; } // Let our parent do the rest return parent::addSubtag ($Tag); } // }}} // {{{ getType /** * Retrive the type of this form * * @access public * @return enum **/ public function getType () { return $this->Type; } // }}} // {{{ setType /** * Set the type of this form * * @param enum $Type * * @access public * @return bool **/ public function setType ($Type) { if (!in_array ($Type, array (self::TYPE_FORM, self::TYPE_CANCEL, self::TYPE_SUBMIT, self::TYPE_RESULT))) return false; $this->Type = $Type; return true; } // }}} // {{{ getTitle /** * Retrive the title from this form * * @access public * @return string **/ public function getTitle () { if (!is_object ($Title = $this->getSubtagByName ('title'))) return false; return $Title->getValue (); } // }}} // {{{ setTitle /** * Set the title of this form * * @param string $Title * * @access public * @return bool **/ public function setTitle ($Title) { new tiggerXMPP_XML_Tag ('title', $this, $Title); return true; } // }}} // {{{ getInstructions /** * Retrive instructions from this form * * @access public * @return string **/ public function getInstructions () { if (!is_object ($Instructions = $this->getSubtagByName ('instructions'))) return false; return $Instructions->getValue (); } // }}} // {{{ setInstructions /** * Set instructions for using this form * * @param string $Instructions * * @access public * @return bool **/ public function setInstructions ($Instructions) { new tiggerXMPP_XML_Tag ('instructions', $this, $Instructions); return true; } // }}} } ?>