Esempio n. 1
0
 /**
  * Add import entry request for a plan or a task from the given entry
  * TODO: Refactor this to combine it with create_plan()
  *
  * @param SimpleXMLElement $entry    The entry for the plan or task
  * @param PluginImportLeap $importer The importer
  */
 private static function add_import_entry_request_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 ($ancestorid = self::get_ancestor_entryid($entry, $importer)) {
         $type = 'task';
     } else {
         $type = 'plan';
     }
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $authorname = $entry->author->name;
     } else {
         $author = $importer->get('usr');
     }
     // Set completiondate and completed status if we can find them
     if ($type === 'task') {
         $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']);
         }
         $completiondate = empty($completiondate) ? $updated : $completiondate;
         $completed = 0;
         if ($entry->xpath($namespaces[$ns] . ':status[@' . $namespaces[$ns] . ':stage="completed"]')) {
             $completed = 1;
         }
     }
     PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string) $entry->id, self::STRATEGY_IMPORT_AS_PLAN, 'plans', array('owner' => $importer->get('usr'), 'type' => $type, 'parent' => $ancestorid, 'content' => array('title' => (string) $entry->title, 'description' => PluginImportLeap::get_entry_content($entry, $importer), 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'completiondate' => $type === 'task' ? $completiondate : null, 'completed' => $type === 'task' ? $completed : null, 'tags' => PluginImportLeap::get_entry_tags($entry))));
 }
Esempio n. 2
0
 /**
  * Find and update duplicates with imported namedata
  * TODO: Refactor this to combine it with import_namedata();
  */
 private static function add_import_entry_request_namedata(PluginImportLeap $importer, $persondataid, array $persondata)
 {
     $namefields = self::get_namefields($importer, $persondata);
     if (!empty($namefields['firstname'])) {
         PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), $persondataid, self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'internal', array('owner' => $importer->get('usr'), 'type' => 'firstname', 'content' => array('title' => $namefields['firstname'])));
     }
     if (!empty($namefields['lastname'])) {
         PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), $persondataid, self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'internal', array('owner' => $importer->get('usr'), 'type' => 'lastname', 'content' => array('title' => $namefields['lastname'])));
     }
     if (!empty($namefields['preferredname'])) {
         PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), $persondataid, self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'internal', array('owner' => $importer->get('usr'), 'type' => 'preferredname', 'content' => array('title' => $namefields['preferredname'])));
     }
 }
Esempio n. 3
0
 /**
  * Add import entry request for the personalinformation artefact type, by looking for
  * it in the persondata element
  */
 public static function add_import_entry_request_author_data(PluginImport $importer, $persondataid)
 {
     if ($data = self::get_personalinformation_from_author_data($importer, $persondataid)) {
         return PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), $persondataid, self::STRATEGY_IMPORT_AS_PERSONALINFORMATION, 'resume', $data);
     }
 }
Esempio n. 4
0
 /**
  * Parse the import entry as mahara view from LEAP2A file and add the import entry request to DB
  *
  * @param SimpleXMLElement $entry
  * @return request ID if successful
  *     false if it is not Mahara view
  */
 private function add_import_entry_request_view(SimpleXMLElement $entry)
 {
     $config = $this->get_mahara_view_entry_data($entry);
     if (!$config) {
         return false;
     }
     if ($published = strtotime((string) $entry->published)) {
         $config['ctime'] = $published;
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $config['mtime'] = $updated;
     }
     return PluginImportLeap::add_import_entry_request($this->get('importertransport')->get('importid'), (string) $entry->id, self::STRATEGY_IMPORT_AS_VIEW, 'core', array('owner' => $config['owner'], 'type' => 'view', 'title' => $config['title'], 'content' => $config));
 }
Esempio n. 5
0
 public static function add_import_entry_request_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     $config = self::get_entry_data_using_strategy($entry, $importer, $strategy, $otherentries);
     return PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string) $entry->id, self::STRATEGY_IMPORT_AS_COMMENT, 'comment', $config);
 }
Esempio n. 6
0
 /**
  * Add import entry request for a folder artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry    The entry to base the folder's data on
  * @param PluginImportLeap $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 import entry request created
  */
 private static function add_import_entry_request_folder(SimpleXMLElement $entry, PluginImportLeap $importer, $parent = null)
 {
     $config = self::get_folder_entry_data($entry, $importer, $parent);
     return PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string) $entry->id, self::STRATEGY_IMPORT_AS_FOLDER, 'file', $config);
 }
Esempio n. 7
0
 public static function add_import_entry_request_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     switch ($strategy) {
         case self::STRATEGY_IMPORT_AS_ANNOTATION:
             $config = self::get_annotation_entry_data($entry, $importer, $otherentries);
             // Add the annotation entry.
             PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), (string) $entry->id, $strategy, 'annotation', array('owner' => $config['owner'], 'type' => $config['type'], 'content' => $config['content']));
             // Add the feedback entries.
             foreach ($config['annotationfeedback'] as $item) {
                 self::add_import_entry_request_annotationfeedback($item['feedbackentry'], $importer, $item['annotationentryid']);
             }
             break;
         case self::STRATEGY_IMPORT_AS_ANNOTATION_FEEDBACK:
             if (is_array($otherentries) && count($otherentries) == 1) {
                 // Only one annotation should be linked to a feedback.
                 foreach ($otherentries as $annotationentryid) {
                     self::add_import_entry_request_annotationfeedback($entry, $importer, $annotationentryid);
                 }
             }
             break;
         default:
             throw new ImportException($importer, get_string('unknownstrategyforimport', 'artefact.annotation'));
     }
 }
Esempio n. 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))));
 }