Esempio n. 1
0
 /**
  * Get the id of the plan entry which ultimately contains this entry
  */
 public static function get_ancestor_entryid(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     $entryid = (string) $entry->id;
     if (!isset(self::$ancestors[$entryid])) {
         self::$ancestors[$entryid] = null;
         $child = $entry;
         while ($child) {
             $childid = (string) $child->id;
             if (!isset(self::$parents[$childid])) {
                 self::$parents[$childid] = null;
                 foreach ($child->link as $link) {
                     $href = (string) $link['href'];
                     if ($href != $entryid && $importer->curie_equals($link['rel'], PluginImportLeap::NS_LEAP, 'is_part_of') && $importer->entry_has_strategy($href, self::STRATEGY_IMPORT_AS_PLAN, 'plans')) {
                         self::$parents[$childid] = $href;
                         break;
                     }
                 }
             }
             if (!self::$parents[$childid]) {
                 break;
             }
             if ($child = $importer->get_entry_by_id(self::$parents[$childid])) {
                 self::$ancestors[$entryid] = self::$parents[$childid];
             }
         }
     }
     return self::$ancestors[$entryid];
 }
Esempio n. 2
0
 /**
  * Get the id of the entry reflected on by a comment entry
  */
 public static function get_referent_entryid(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     foreach ($entry->link as $link) {
         if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'reflects_on') && isset($link['href'])) {
             return (string) $link['href'];
         }
     }
     // Shouldn't happen -- this was checked when offering the strategy
     throw new ImportException($importer, 'TODO: get_string: cannot find an entry for a comment to comment on');
 }
Esempio n. 3
0
 /**
  * Returns a list of entry IDs that are children of this folder
  *
  * If necessary, this method can act recursively to find children at all 
  * levels under this folder
  *
  * TODO: protection against circular references
  *
  * @param SimpleXMLElement $entry    The folder to get children for
  * @param PluginImportLeap $importer The importer
  * @param boolean $recurse           Whether to return children at all levels below this folder
  * @return array A list of the entry IDs of children in this folder
  */
 private static function get_children_of_folder(SimpleXMLElement $entry, PluginImportLeap $importer, $recurse = false)
 {
     $children = array();
     // Get entries that this folder feels are a part of it
     foreach ($entry->link as $link) {
         if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'has_part') && isset($link['href'])) {
             $child = $importer->get_entry_by_id((string) $link['href']);
             if ($child) {
                 if (self::is_file($child, $importer) || self::is_folder($child, $importer)) {
                     $children[] = (string) $link['href'];
                 } else {
                     $importer->trace("NOTICE: Child {$child->id} of folder {$entry->id} won't be imported by the file plugin because it is not a file or folder");
                 }
             } else {
                 $importer->trace("WARNING: folder {$entry->id} claims to have child {$link['href']} which does not exist");
             }
         }
     }
     if ($recurse) {
         foreach ($children as $childid) {
             $child = $importer->get_entry_by_id($childid);
             if (self::is_folder($child, $importer)) {
                 $children = array_merge($children, self::get_children_of_folder($child, $importer, true));
             }
         }
     }
     return $children;
 }
Esempio n. 4
0
 /**
  * Given an entry, see if it's attached to one of the special selections 
  * representing a Mahara resume group. If so, return the display order it 
  * should have in that group.
  *
  * We look for the special Mahara selections only, because entries could be 
  * in more than one selection, with different display orders in each.
  *
  * @param SimpleXMLElement $entry    The entry to check
  * @param PluginImportLeap $importer The importer
  * @param string $selectiontype      The type of selection we're checking to 
  *                                   see if the entry is part of - one of the 
  *                                   special Mahara resume selections
  * @return int The display order of the element in the selection, should it 
  *             be in one - else null
  */
 private static function get_display_order_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer, $selectiontype)
 {
     static $cache = array();
     $found = false;
     foreach ($entry->link as $link) {
         if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'is_part_of') && isset($link['href'])) {
             $href = (string) $link['href'];
             if (isset($cache[$href])) {
                 $found = true;
             } else {
                 if ($potentialselection = $importer->get_entry_by_id($href)) {
                     if (PluginImportLeap::is_rdf_type($potentialselection, $importer, 'selection')) {
                         if (PluginImportLeap::is_correct_category_scheme($potentialselection, $importer, 'selection_type', 'Grouping')) {
                             if (count($potentialselection->xpath('mahara:artefactplugin[@mahara:type="' . $selectiontype . '"]')) == 1) {
                                 $cache[$href] = true;
                                 $found = true;
                             }
                         }
                     }
                 }
             }
             if ($found) {
                 $leapattributes = $importer->get_attributes($link, $importer->get_leap2a_namespace());
                 $displayorder = isset($leapattributes['display_order']) && intval($leapattributes['display_order']) > 0 ? $leapattributes['display_order'] : '';
                 return $displayorder;
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Add file attachment information to 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_files_to_import_entry_request_blogpost(SimpleXMLElement $entry, PluginImportLeap $importer, $blogentryid)
 {
     $files = array();
     if (isset($entry->link)) {
         foreach ($entry->link as $link) {
             if ($importer->curie_equals($link['rel'], '', 'related') && isset($link['href'])) {
                 if ($has_attachments = get_records_select_array('import_entry_requests', 'importid = ? AND entryid = ?', array($importer->get('importertransport')->get('importid'), (string) $link['href']))) {
                     foreach ($has_attachments as $has_attachment) {
                         $attachment = unserialize($has_attachment->entrycontent);
                         $files[] = array('title' => $attachment['title'], 'description' => $attachment['description']);
                     }
                 }
             }
         }
     }
     return $files;
 }