/**
  * 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'));
 }
 /**
  * This function returns a list of the current ilps units.
  *
  * @param limit how many units to display per page
  * @param offset current page to display
  * @return array (grandtotalpoints: number, count: integer, data: array)
  * 
  */
 public static function get_units($ilp, $offset = 0, $limit = 20)
 {
     ($results = get_records_sql_array("\n            SELECT a.id, at.artefact AS unit, at.status, at.points, " . db_format_tsfield('targetcompletion') . ", " . db_format_tsfield('datecompleted') . ",\n                a.title, a.description, a.parent\n                FROM {artefact} a\n            JOIN {artefact_ilps_unit} at ON at.artefact = a.id\n            WHERE a.artefacttype = 'unit' AND a.parent = ?\n            ORDER BY at.targetcompletion DESC", array($ilp), $offset, $limit)) || ($results = array());
     // format the date and calculate grand total of points
     $grandtotalpoints = 0;
     $aquiredpoints = 0;
     $remainingpoints = ArtefactTypeilp::get_points($ilp);
     foreach ($results as $result) {
         $grandtotalpoints = $grandtotalpoints + $result->points;
         if (!empty($result->targetcompletion)) {
             $result->targetcompletion = strftime(get_string('strftimedate'), $result->targetcompletion);
         }
         if (!empty($result->datecompleted)) {
             $result->datecompleted = strftime(get_string('strftimedate'), $result->datecompleted);
             $aquiredpoints = $aquiredpoints + $result->points;
             $remainingpoints = $remainingpoints - $result->points;
         }
     }
     $result = array('grandtotalpoints' => $grandtotalpoints, 'aquiredpoints' => $aquiredpoints, 'remainingpoints' => $remainingpoints, 'count' => count_records('artefact', 'artefacttype', 'unit', 'parent', $ilp), 'data' => $results, 'offset' => $offset, 'limit' => $limit, 'id' => $ilp);
     return $result;
 }