/**
  * Optional method. If exists, allows this class to decide the title for
  * all blockinstances of this type
  */
 public static function get_instance_title(BlockInstance $bi)
 {
     $configdata = $bi->get('configdata');
     if (!empty($configdata['artefactid'])) {
         safe_require('artefact', 'ilps');
         $ilp = new ArtefactTypeilp($configdata['artefactid']);
         $title = $ilp->get('title');
         return $title;
     }
     return '';
 }
 /**
  * Creates a ilp or unit from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the ilp or unit 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_ilp(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     // First decide if it's going to be a ilp or a unit depending
     // on whether it has any ancestral ilps.
     if (self::get_ancestor_entryid($entry, $importer)) {
         $artefact = new ArtefactTypeunit();
     } else {
         $artefact = new ArtefactTypeilp();
     }
     $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 targetcompletion and points status if we can find them
     if ($artefact instanceof ArtefactTypeunit) {
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $dates = PluginImportLeap::get_leap_dates($entry, $namespaces, $ns);
         if (!empty($dates['target']['value'])) {
             $targetcompletion = strtotime($dates['target']['value']);
         }
         $artefact->set('targetcompletion', empty($targetcompletion) ? $artefact->get('mtime') : $targetcompletion);
         if ($entry->xpath($namespaces[$ns] . ':status[@' . $namespaces[$ns] . ':stage="points"]')) {
             $artefact->set('points', 1);
         }
     }
     $artefact->commit();
     return array($artefact->get('id'));
 }
 public static function submit(Pieform $form, $values)
 {
     global $USER, $SESSION;
     $new = false;
     if (!empty($values['ilp'])) {
         $id = (int) $values['ilp'];
         $artefact = new ArtefactTypeilp($id);
     } else {
         $artefact = new ArtefactTypeilp();
         $artefact->set('owner', $USER->get('id'));
         $new = true;
     }
     $artefact->set('title', $values['title']);
     $artefact->set('description', $values['description']);
     $artefact->set('points', (int) $values['points']);
     $artefact->commit();
     $SESSION->add_ok_msg(get_string('ilpsavedsuccessfully', 'artefact.ilps'));
     if ($new) {
         redirect('/artefact/ilps/ilp.php?id=' . $artefact->get('id'));
     } else {
         redirect('/artefact/ilps/');
     }
 }