00001 <?php
00002
00012 class SnapContentInteractivateInstructor extends SnapContent {
00013 protected $NEED_TRANSLATION = true;
00014
00015 protected $currentXML = null;
00016 protected $loadErrors = array();
00017
00032 protected function prepareAndValidateXML($content, $field, $pre = '', $post = '') {
00033 $content = ltrim(rtrim($content));
00034 $pre = '<XMLResource><section>' . $pre;
00035 $post = $post . '</section></XMLResource>';
00036 $res = XmlFormatter::prepareXML($content, $field, true);
00037 if(is_array($res)) {
00038 $this->loadErrors = array_merge($this->loadErrors, $res);
00039 return false;
00040 }
00041 $res = SXMLHelper::validateXML($in = "$pre$content$post", true);
00042 if(is_array($res)) {
00043 $res = XmlFormatter::prepareXML($content, $field, false);
00044 $res = SXMLHelper::validateXML($in = "$pre$content$post", true);
00045 }
00046 if(is_array($res)) {
00047 foreach($res as $err)
00048 $this->loadErrors[] = "In field <b>$field</b>: $err";
00049 return false;
00050 }
00051 $ret = SXMLHelper::formatXML($content);
00052 if(!$ret)
00053 $ret = $content;
00054 return $ret;
00055
00056 }
00057
00066 public function setDescription($description) {
00067 $description = $this->prepareAndValidateXML($description, 'Description');
00068 if($description === false)
00069 return false;
00070 else
00071 return $this->set('description', $description);
00072 }
00073
00079 public function clearPlacements() {
00080 $this->set('placements', array());
00081 }
00082
00089 public function addPlacement($obj) {
00090 $obj = $this->prepareAndValidateXML($obj, 'Objective', '<ul><li>', '</li></ul>');
00091 if($obj === false)
00092 return false;
00093 $placements = $this->get('placements');
00094 if(!is_array($placements))
00095 $placements = array($obj);
00096 else
00097 $placements[] = $obj;
00098 $this->set('placements', $placements);
00099 }
00100
00108 public function clearPreparations() {
00109 $this->set('preparations', array());
00110 }
00111
00120 public function addPreparation($content) {
00121 $content = $this->prepareAndValidateXML($content, 'Follow Up', '<ul><li>', '</li></ul>');
00122 if($content === false)
00123 return false;
00124 $preparations = $this->get('preparations');
00125 $preparations[] = $content;
00126 $this->set('preparations', $preparations);
00127 return true;
00128 }
00129
00137 public function getXML() {
00138 if(!$this->currentXML) {
00139 $ret = $this->generateXML();
00140 if(is_array($ret)) {
00141 foreach($ret as $entry)
00142 $this->setError($entry);
00143 return false;
00144 }
00145 $this->currentXML = $ret;
00146 }
00147
00148 return $this->currentXML;
00149 }
00150
00158 protected function generateXML() {
00159 $errors = array();
00160
00161 $description = XmlFormatter::prepareXML($this->get('description'), 'Description');
00162 $placements = (is_array($this->get('placements')) ? $this->get('placements') : array());
00163 $preparations = (is_array($this->get('preparations')) ? $this->get('preparations') : array());
00164
00165 $plcStr = '';
00166 foreach($placements as $plc)
00167 $plcStr .= '<li>' . $this->prepareAndValidateXML($plc, 'Placements', '<p>', '</p>') . '</li>';
00168 if(count($placements) > 0)
00169 $plcStr = <<<END_XML
00170 <section mapping="placements">
00171 <p>This activity can be used to:</p>
00172 <ul>$plcStr</ul>
00173 </section>
00174
00175 END_XML;
00176
00177 $prepStr = '';
00178 foreach($preparations as $prep)
00179 $prepStr .= '<li>' . $this->prepareAndValidateXML($prep, 'Preparations', '<p>', '</p>') . '</li>';
00180 if(count($preparations) > 0)
00181 $prepStr = <<<END_XML
00182 <section mapping="preparations">
00183 <ul>$prepStr</ul>
00184 </section>
00185
00186 END_XML;
00187
00188 if($description != '')
00189 $description = "<section mapping=\"description\"><p>$description</p></section>";
00190
00191 if(count($errors) > 0)
00192 return $errors;
00193
00194 $xmlString = <<<END_XML
00195 <XMLResource>
00196 <section mapping="title">
00197 <p>{{{PLACEHOLDER}}}</p>
00198 </section>
00199 $description
00200 $plcStr
00201 <section mapping="standards">
00202 <p>{{{PLACEHOLDER}}}</p>
00203 </section>
00204 <section mapping="textbooks">
00205 <p>{{{PLACEHOLDER}}}</p>
00206 </section>
00207 $prepStr
00208 </XMLResource>
00209 END_XML;
00210
00211 $ret = XmlFormatter::finalGenerateXML($xmlString, true);
00212
00213 return $ret;
00214 }
00215
00223 public function getDescription() {
00224 return $this->get('description');
00225 }
00226
00234 public function getPlacements() {
00235 $o = $this->get('placements');
00236 return is_array($o) ? $o : array();
00237 }
00238
00246 public function getPreparations() {
00247 $o = $this->get('preparations');
00248 return is_array($o) ? $o : array();
00249 }
00250
00258 public function getLoadErrors() {
00259 return $this->loadErrors;
00260 }
00261
00263 protected function validate() {
00264 return true;
00265 }
00266
00268 protected function doGetHTML($params) {
00269 return $this->getAll();
00270 }
00271
00272 public function checkMedia() {
00273 return true;
00274 }
00275
00276 public function updateFileList() {
00277 return true;
00278 }
00279
00284 public static function initialValue() {
00285 return "<XMLResource>\n</XMLResource>\n";
00286 }
00287 }
00288
00289 ?>