Esempio n. 1
0
 /**
  * Attempts to import an entry as a mahara view
  *
  * We look for custom mahara namespaced tags that explain the View
  * structure. If they're present, we use them to create a View using that
  * structure.
  *
  * This differs a bit from the Leap2A specification, but we do so
  * deliberately to get 100% compatibility with Mahara to Mahara exports.
  * Other systems can also construct content in the right format to trigger
  * Mahara to import things as a full view.
  *
  * If the mahara tags are not present, we give up.
  *
  * @param SimpleXMLElement $entry The entry to be imported
  * @return boolean Whether it could be imported.
  */
 private function import_entry_as_mahara_view(SimpleXMLElement $entry)
 {
     $config = $this->get_mahara_view_entry_data($entry);
     if (!$config) {
         return false;
     }
     $view = View::import_from_config($this->rewrite_blockinstance_config($config), $this->get('usr'), 'leap');
     if ($published = strtotime((string) $entry->published)) {
         $view->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $view->set('mtime', $updated);
     }
     $view->set('owner', $this->get('usr'));
     $view->commit();
     $this->viewids[(string) $entry->id] = $view->get('id');
     return true;
 }
Esempio n. 2
0
 /**
  * Attempts to import an entry as a mahara view
  *
  * We look for custom mahara namespaced tags that explain the View 
  * structure. If they're present, we use them to create a View using that 
  * structure.
  *
  * This differs a bit from the Leap2A specification, but we do so 
  * deliberately to get 100% compatibility with Mahara to Mahara exports. 
  * Other systems can also construct content in the right format to trigger 
  * Mahara to import things as a full view.
  *
  * If the mahara tags are not present, we give up.
  *
  * @param SimpleXMLElement $entry The entry to be imported
  * @return boolean Whether it could be imported.
  */
 private function import_entry_as_mahara_view(SimpleXMLElement $entry)
 {
     static $blocktypes_installed = null;
     static $viewlayouts = null;
     static $viewtypes = null;
     $viewelement = $entry->xpath('mahara:view[1]');
     if (count($viewelement) != 1) {
         // This isn't a Mahara view
         return false;
     }
     if (is_null($viewlayouts)) {
         $viewlayouts = get_records_assoc('view_layout', '', '', '', 'widths, id');
     }
     if (is_null($viewtypes)) {
         $viewtypes = get_column('view_type', 'type');
     }
     $maharaattributes = PluginImportLeap::get_attributes($viewelement[0], PluginImportLeap::NS_MAHARA);
     $layout = null;
     if (isset($viewlayouts[$maharaattributes['layout']])) {
         $layout = $viewlayouts[$maharaattributes['layout']]->id;
     }
     $type = 'portfolio';
     if (isset($maharaattributes['type']) && in_array($maharaattributes['type'], $viewtypes)) {
         $type = $maharaattributes['type'];
     }
     $ownerformat = intval($maharaattributes['ownerformat']);
     if (!$ownerformat) {
         $ownerformat = FORMAT_NAME_DISPLAYNAME;
     }
     $columns = $entry->xpath('mahara:view[1]/mahara:column');
     $columncount = count($columns);
     if ($columncount < 1 || $columncount > 5) {
         // Whoops, invalid number of columns
         $this->trace("Invalid number of columns specified for potential view {$entry->id}, falling back to standard import", self::LOG_LEVEL_VERBOSE);
         return false;
     }
     $config = array('title' => (string) $entry->title, 'description' => (string) $entry->summary, 'type' => $type, 'layout' => $layout, 'tags' => self::get_entry_tags($entry), 'numcolumns' => $columncount, 'owner' => $this->get('usr'), 'ownerformat' => $ownerformat);
     $col = 1;
     foreach ($columns as $column) {
         $blockinstances = $column->xpath('mahara:blockinstance');
         $row = 1;
         $config['columns'][$col] = array();
         foreach ($blockinstances as $blockinstance) {
             $attrs = self::get_attributes($blockinstance, PluginImportLeap::NS_MAHARA);
             if (!isset($attrs['blocktype'])) {
                 $this->trace("  No mahara:blocktype attribute set for blockinstance at col {$col}, row {$row}: skipping");
                 continue;
             }
             $this->trace("  Found block with type {$attrs['blocktype']} at [{$col}][{$row}]", self::LOG_LEVEL_VERBOSE);
             if ($blocktypes_installed === null) {
                 $blocktypes_installed = array_map(create_function('$a', 'return $a->name;'), plugins_installed('blocktype'));
             }
             if (in_array($attrs['blocktype'], $blocktypes_installed)) {
                 $configelements = $blockinstance->xpath('mahara:*');
                 $config['columns'][$col][$row] = array('type' => $attrs['blocktype'], 'title' => $attrs['blocktitle'], 'config' => array());
                 foreach ($configelements as $element) {
                     $value = json_decode((string) $element);
                     if (is_array($value) && isset($value[0])) {
                         $config['columns'][$col][$row]['config'][$element->getName()] = $value[0];
                     } else {
                         $this->trace("  Value for {$element->getName()} is not an array, ignoring (value follows below)");
                         $this->trace($value);
                     }
                 }
                 $row++;
             } else {
                 $this->trace("  Ignoring unknown blocktype {$attrs['blocktype']}");
             }
         }
         $col++;
     }
     $view = View::import_from_config($this->rewrite_artefact_ids($config), $this->get('usr'), 'leap');
     if ($published = strtotime((string) $entry->published)) {
         $view->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $view->set('mtime', $updated);
     }
     $view->set('owner', $this->get('usr'));
     $view->commit();
     $this->viewids[(string) $entry->id] = $view->get('id');
     return true;
 }