3 namespace Hub\Node\Helper\Answer\Announcement;
5 // Import application-specific stuff
6 use Hub\Helper\Node\NodeHelper;
9 * A AnnouncementMessageAnswer node helper class
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
16 * @todo Find an interface for hub helper
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements HelpableNode {
33 * Protected constructor
37 protected function __construct () {
38 // Call parent constructor
39 parent::__construct(__CLASS__);
42 $this->setPackageTags(array('announcement_answer'));
46 * Creates the helper class
48 * @param $messageData An array with all message data
49 * @return $helperInstance A prepared instance of this helper
51 public final static function createNodeAnnouncementMessageAnswerHelper (array $messageData) {
53 $helperInstance = new NodeAnnouncementMessageAnswerHelper();
55 // Set session id of other peer as recipient
56 $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
59 $helperInstance->setMessageData($messageData);
61 // Return the prepared instance
62 return $helperInstance;
66 * Loads the descriptor XML file
68 * @param $nodeInstance An instance of a NodeHelper class
71 public function loadDescriptorXml (NodeHelper $nodeInstance) {
73 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting to answer an announcement...');
75 // Get a XML template instance
76 $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_answer_template_class');
78 // Set it for later use
79 $this->setTemplateInstance($templateInstance);
81 // Read the XML descriptor
82 $templateInstance->loadXmlTemplate();
84 // Render the XML content
85 $templateInstance->renderXmlContent();
89 * Send out announcement answer package
91 * @param $nodeInstance An instance of a NodeHelper class
94 public function sendPackage (NodeHelper $nodeInstance) {
95 // Sanity check: Is the node in the approx. state? (active/reachable)
96 $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrReachable();
98 // Compile the template, this inserts the loaded node data into the gaps.
99 $this->getTemplateInstance()->compileTemplate();
101 // Get a singleton network package instance
102 $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
104 // Next, feed the content in. The network package class is a pipe-through class.
105 $packageInstance->enqueueRawDataFromTemplate($this);