Пример #1
0
 /**
  * Creates a plan or task from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the plan or task from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_plan(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a plan or a task depending
     // on whether it has any ancestral plans.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeTask();
     } else {
         $artefact = new ArtefactTypePlan();
     }
     $artefact->set('title', (string) $entry->title);
     $artefact->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     $artefact->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $artefact->set('authorname', $entry->author->name);
     } else {
         $artefact->set('author', $importer->get('usr'));
     }
     if ($published = strtotime((string) $entry->published)) {
         $artefact->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $artefact->set('mtime', $updated);
     }
     $artefact->set('tags', PluginImportLeap::get_entry_tags($entry));
     // Set completiondate and completed status if we can find them
     if ($artefact instanceof ArtefactTypeTask) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['target']['value'])) {
             $completiondate = strtotime($dates['target']['value']);
         }
         $artefact->set('completiondate', empty($completiondate) ? $artefact->get('mtime') : $completiondate);
         if ($entry->xpath($namespaces[$ns] . ':status[@' . $namespaces[$ns] . ':stage="completed"]')) {
             $artefact->set('completed', 1);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }
Пример #2
0
 /**
  * Creates a folder artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry The entry to base the folder's data on
  * @param PluginImport $importer  The importer
  * @param int $parent             The ID of the parent artefact for this folder
  * @throws ImportException If the given entry is not detected as being a folder
  * @return int The ID of the folder artefact created
  */
 private static function create_folder(SimpleXMLElement $entry, PluginImport $importer, $parent = null)
 {
     if (!self::is_folder($entry, $importer)) {
         throw new ImportException($importer, "create_folder(): Cannot create a folder artefact from an entry we don't recognise as a folder");
     }
     $folder = new ArtefactTypeFolder();
     $folder->set('title', (string) $entry->title);
     $folder->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     if ($published = strtotime((string) $entry->published)) {
         $folder->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $folder->set('mtime', $updated);
     }
     $folder->set('owner', $importer->get('usr'));
     $folder->set('tags', PluginImportLeap::get_entry_tags($entry));
     if ($parent) {
         $folder->set('parent', $parent);
     }
     $folder->commit();
     return $folder->get('id');
 }
Пример #3
0
 /**
  * Creates a blogpost from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the blogpost from
  * @param PluginImportLeap $importer The importer
  * @param int $blogid                The blog in which to put the post
  * @return array A list of artefact IDs created, to be used with the artefact mapping. 
  *               There will either be one (the blogpost ID), or two. If there is two, the 
  *               second one will be the ID of the file created to hold the out-of-line 
  *               content associated with the blogpost
  */
 private static function create_blogpost(SimpleXMLElement $entry, PluginImportLeap $importer, $blogid)
 {
     $createdartefacts = array();
     $blogpost = new ArtefactTypeBlogPost();
     $blogpost->set('title', (string) $entry->title);
     // If the entry has out of line content, we import that separately as a
     // file and set the content to refer to it
     if (isset($entry->content['src']) && isset($entry->content['type'])) {
         $file = LeapImportFile::create_file($entry, $importer);
         $createdartefacts[] = $file->get('id');
         $content = '<a href="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '"' . ' title="' . hsc($file->get('title')) . '">';
         if (is_image_mime_type($file->get('filetype'))) {
             $content .= '<img src="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '&amp;maxwidth=500&amp;maxheight=500"' . ' alt="' . hsc($file->get('title')) . '">';
         }
         $content .= '</a>';
         $blogpost->set('description', $content);
     } else {
         $description = PluginImportLeap::get_entry_content($entry, $importer);
         $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
         if ($type == 'text') {
             $description = format_whitespace($description);
         }
         $blogpost->set('description', $description);
     }
     if ($published = strtotime((string) $entry->published)) {
         $blogpost->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $blogpost->set('mtime', $updated);
     }
     $draftpost = count($entry->xpath('a:category[(' . $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'readiness#') . ') and @term="Unready"]')) == 1;
     $blogpost->set('published', $draftpost ? 0 : 1);
     $blogpost->set('owner', $importer->get('usr'));
     $blogpost->set('parent', $blogid);
     $blogpost->set('tags', PluginImportLeap::get_entry_tags($entry));
     $blogpost->commit();
     array_unshift($createdartefacts, $blogpost->get('id'));
     return $createdartefacts;
 }
Пример #4
0
 /**
  * Creates a comment from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the comment from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_comment(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     $createdartefacts = array();
     $comment = new ArtefactTypeComment();
     $comment->set('title', (string) $entry->title);
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     $comment->set('description', $description);
     if ($published = strtotime((string) $entry->published)) {
         $comment->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $comment->set('mtime', $updated);
     }
     $private = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private');
     $comment->set('private', (int) $private);
     $comment->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $comment->set('authorname', $entry->author->name);
     } else {
         $comment->set('author', $importer->get('usr'));
     }
     if (empty(self::$tempview)) {
         self::create_temporary_view($importer->get('usr'));
     }
     $comment->set('onview', self::$tempview);
     $comment->set('tags', PluginImportLeap::get_entry_tags($entry));
     $comment->commit();
     array_unshift($createdartefacts, $comment->get('id'));
     return $createdartefacts;
 }
Пример #5
0
 /**
  * Logic to figure out how to process an entry into a comment
  * Used by import_using_strategy() and add_import_entry_request_using_strategy().
  *
  * @param SimpleXMLElement $entry
  * @param PluginImportLeap $importer
  * @param unknown_type $strategy
  * @param array $otherentries
  * @return array An array of config stuff to either create the comment, or store an import request.
  * @throws ImportException
  */
 private static function get_entry_data_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     if ($strategy != self::STRATEGY_IMPORT_AS_COMMENT) {
         throw new ImportException($importer, 'TODO: get_string: unknown strategy chosen for importing entry');
     }
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $authorname = (string) $entry->author->name;
     } else {
         $author = $importer->get('usr');
     }
     return array('owner' => $importer->get('usr'), 'type' => 'comment', 'content' => array('title' => (string) $entry->title, 'description' => $description, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'private' => (int) PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'), 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'tags' => PluginImportLeap::get_entry_tags($entry)));
 }
Пример #6
0
 private static function get_folder_entry_data(SimpleXMLElement $entry, PluginImportLeap $importer, $parent = null)
 {
     if (!self::is_folder($entry, $importer)) {
         throw new ImportException($importer, "get_folder_entry_data(): Cannot add an import entry request for a folder we don't recognise as a folder");
     }
     return array('owner' => $importer->get('usr'), 'type' => 'folder', 'parent' => $parent, 'content' => array('title' => (string) $entry->title, 'description' => PluginImportLeap::get_entry_content($entry, $importer), 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'tags' => PluginImportLeap::get_entry_tags($entry)));
 }
Пример #7
0
 private static function get_annotationfeedback_entry_data(SimpleXMLElement $entry, PluginImportLeap $importer, $annotationentryid)
 {
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $authorname = (string) $entry->author->name;
     } else {
         $author = $importer->get('usr');
     }
     return array('owner' => $importer->get('usr'), 'type' => 'annotationfeedback', 'parent' => $annotationentryid, 'content' => array('title' => (string) $entry->title, 'description' => $description, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'tags' => PluginImportLeap::get_entry_tags($entry), 'private' => (int) PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'), 'onannotation' => $annotationentryid));
 }
Пример #8
0
 /**
  * Add an import entry request for a blogpost
  *
  * @param SimpleXMLElement $entry    The entry to create the blogpost from
  * @param PluginImportLeap $importer The importer
  * @param int $blogentryid         The ID of the import entry of the blog in which to put the post
  */
 private static function add_import_entry_request_blogpost(SimpleXMLElement $entry, PluginImportLeap $importer, $blogentryid)
 {
     $config = self::get_blogpost_entry_data($entry, $importer, $blogentryid);
     if ($config['isfile']) {
         LeapImportFile::add_import_entry_request_file($entry, $importer);
     }
     return PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string) $entry->id, self::STRATEGY_IMPORT_AS_ENTRY, 'blog', array('owner' => $importer->get('usr'), 'type' => 'blogpost', 'parent' => $blogentryid, 'content' => array('title' => $config['content']['title'], 'description' => $config['content']['description'], 'files' => self::add_files_to_import_entry_request_blogpost($entry, $importer, $blogentryid), 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'published' => PluginImportLeap::is_correct_category_scheme($entry, $importer, 'readiness', 'Unready') ? 0 : 1, 'tags' => PluginImportLeap::get_entry_tags($entry))));
 }
Пример #9
0
 /**
  * Creates a cpd or activity from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the cpd or activity from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_cpd(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a cpd or a activity depending
     // on whether it has any ancestral cpds.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeActivity();
     } else {
         $artefact = new ArtefactTypeCPD();
     }
     $artefact->set('title', (string) $entry->title);
     $artefact->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     $artefact->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $artefact->set('authorname', $entry->author->name);
     } else {
         $artefact->set('author', $importer->get('usr'));
     }
     if ($published = strtotime((string) $entry->published)) {
         $artefact->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $artefact->set('mtime', $updated);
     }
     $artefact->set('tags', PluginImportLeap::get_entry_tags($entry));
     // Set startdate and hours status if we can find them
     if ($artefact instanceof ArtefactTypeActivity) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $startdate = $enddate = null;
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['start']['value'])) {
             $startdate = strtotime($dates['start']['value']);
         }
         if (!empty($dates['end']['value'])) {
             $enddate = strtotime($dates['end']['value']);
         }
         $artefact->set('startdate', empty($startdate) ? $artefact->get('mtime') : $startdate);
         $artefact->set('enddate', $enddate);
         $location = $entry->xpath($namespaces[$ns] . ':spatial');
         if (is_array($location) && count($location) == 1) {
             $artefact->set('location', $location[0]);
         }
         $hours = $entry->xpath($namespaces[PluginImportLeap::NS_MAHARA] . ':hours');
         if (is_array($hours) && count($hours) == 1) {
             $artefact->set('hours', $hours[0]);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }