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