Example #1
0
 public function assign_smarty_vars()
 {
     $user = $this->get('exporter')->get('user');
     $userid = $user->get('id');
     $updated = get_record_sql('select ' . db_format_tsfield('max(mtime)', 'mtime') . ' from {artefact} a join {artefact_installed_type} t on a.artefacttype = t.name where t.plugin = \'internal\'');
     $this->smarty->assign('artefacttype', 'internal');
     $this->smarty->assign('artefactplugin', 'internal');
     $this->smarty->assign('title', display_name($user, $user));
     $this->smarty->assign('updated', PluginExportLeap::format_rfc3339_date($updated->mtime));
     // If this ID is changed, you'll have to change it in author.tpl too
     $this->smarty->assign('id', 'portfolio:artefactinternal');
     $this->smarty->assign('leaptype', $this->get_leap_type());
     $persondata = array();
     $spacialdata = array();
     usort($this->artefacts, array($this, 'artefact_sort'));
     foreach ($this->artefacts as $a) {
         if (!($data = $this->data_mapping($a))) {
             if ($a->get('artefacttype') == 'introduction') {
                 $this->smarty->assign('contenttype', 'html');
                 $this->smarty->assign('content', clean_html($a->get('title')));
             }
             continue;
         }
         $value = $a->render_self(array());
         $value = $value['html'];
         // TODO fix this when we non-js stuff
         $data = array_merge(array('value' => $value, 'artefacttype' => $a->get('artefacttype'), 'artefactplugin' => 'internal'), $data);
         if (array_key_exists('spacial', $data)) {
             $spacialdata[] = (object) $data;
         } else {
             $label = get_string($a->get('artefacttype'), 'artefact.internal');
             if ($a->get('artefacttype') == 'socialprofile') {
                 $label = $a->get('description');
             }
             $data = array_merge($data, array('label' => $label));
             $persondata[] = (object) $data;
         }
     }
     if ($extras = $this->exporter->get('extrapersondata')) {
         $persondata = array_merge($persondata, $extras);
     }
     $this->smarty->assign('persondata', $persondata);
     $this->smarty->assign('spacialdata', $spacialdata);
     // Grab profile icons and link to them, making sure the default is first
     if ($icons = get_column_sql("SELECT id\n            FROM {artefact}\n            WHERE artefacttype = 'profileicon'\n            AND \"owner\" = ?\n            ORDER BY id = (\n                SELECT profileicon FROM {usr} WHERE id = ?\n            ) DESC, id", array($userid, $userid))) {
         foreach ($icons as $icon) {
             $icon = artefact_instance_from_id($icon);
             $this->add_artefact_link($icon, 'related');
         }
         $this->smarty->assign('links', $this->links);
     }
     if (!($categories = $this->get_categories())) {
         $categories = array();
     }
     $this->smarty->assign('categories', $categories);
 }
 /**
  * assign the smarty vars used in this template
  */
 public function assign_smarty_vars()
 {
     if (!$this->artefact instanceof ArtefactType) {
         // If you're seeing this error, this means you have subclassed
         // LeapExportElement and are using it to represent something more
         // than just one artefact. In this case, you must override this
         // method.
         throw new ExportException($this, "LeapExportElement::assign_smarty_vars was called with null artefact. " . "If you are using LeapExportElement as a dummy class for exporting more than one artefact, " . "you must override assign_smarty_vars yourself.");
     }
     $this->smarty->assign('artefacttype', $this->artefact->get('artefacttype'));
     $this->smarty->assign('artefactplugin', $this->artefact->get_plugin_name());
     $this->smarty->assign('title', $this->artefact->get('title'));
     $this->smarty->assign('id', 'portfolio:artefact' . $this->artefact->get('id'));
     $this->smarty->assign('updated', PluginExportLeap::format_rfc3339_date($this->artefact->get('mtime')));
     $this->smarty->assign('created', PluginExportLeap::format_rfc3339_date($this->artefact->get('ctime')));
     // these are the ones we really need to override
     $this->add_links();
     $content = $this->get_content();
     // try to coerce it to xhtml
     if ($this->get_content_type() != 'text' && ($newcontent = PluginExportLeap::parse_xhtmlish_content($content))) {
         $this->smarty->assign('contenttype', 'xhtml');
         $this->smarty->assign('content', $newcontent);
     } else {
         $this->smarty->assign('contenttype', 'text');
         $this->smarty->assign('content', $content);
     }
     $this->smarty->assign('leaptype', $this->get_leap_type());
     $this->smarty->assign('author', $this->get_entry_author());
     $this->smarty->assign('dates', $this->get_dates());
     if ($tags = $this->artefact->get('tags')) {
         $tags = array_map(create_function('$a', 'return array(
                 \'term\' => LeapExportElement::normalise_tag($a),
                 \'label\' => $a
             );'), $tags);
     }
     if (!($categories = $this->get_categories())) {
         $categories = array();
     }
     $this->smarty->assign('categories', array_merge($tags, $categories));
     $this->smarty->assign('links', $this->links);
 }
Example #3
0
 /**
  * assign the smarty vars used in this template
  */
 public function assign_smarty_vars()
 {
     $this->smarty->assign('artefacttype', $this->artefact->get('artefacttype'));
     $this->smarty->assign('artefactplugin', $this->artefact->get_plugin_name());
     $this->smarty->assign('title', $this->artefact->get('title'));
     $this->smarty->assign('id', 'portfolio:artefact' . $this->artefact->get('id'));
     $this->smarty->assign('updated', PluginExportLeap::format_rfc3339_date($this->artefact->get('mtime')));
     $this->smarty->assign('created', PluginExportLeap::format_rfc3339_date($this->artefact->get('ctime')));
     // these are the ones we really need to override
     $this->add_links();
     $this->smarty->assign('content', $this->get_content());
     $this->smarty->assign('contenttype', $this->get_content_type());
     $this->smarty->assign('leaptype', $this->get_leap_type());
     $this->smarty->assign('author', $this->get_entry_author());
     if ($tags = $this->artefact->get('tags')) {
         $tags = array_map(create_function('$a', 'return array(
                 \'term\' => LeapExportElement::normalise_tag($a),
                 \'label\' => $a
             );'), $tags);
     }
     if (!($categories = $this->get_categories())) {
         $categories = array();
     }
     $this->smarty->assign('categories', array_merge($tags, $categories));
     $this->smarty->assign('links', $this->links);
 }
Example #4
0
 private function format_persondata($key, $value)
 {
     $basics = array('artefactplugin' => 'resume', 'artefacttype' => 'personalinformation/' . $key, 'field' => $key, 'label' => get_string($key, 'artefact.resume'), 'value' => $value);
     switch ($key) {
         case 'dateofbirth':
             return array_merge($basics, array('field' => 'dob', 'value' => PluginExportLeap::format_rfc3339_date($value)));
         case 'gender':
             return array_merge($basics, array('value' => $key == 'male' ? 1 : 2));
         default:
             return array_merge($basics, array('mahara' => true));
     }
 }
 public function record_to_entrydata($record)
 {
     return array('end' => $record->date, 'title' => $record->title, 'myrole' => $record->contribution, 'content' => $record->description, 'updated' => PluginExportLeap::format_rfc3339_date($record->mtime));
 }
Example #6
0
function bulkexport_submit(Pieform $form, $values)
{
    global $SESSION;
    $usernames = array();
    // Read in the usernames explicitly specified
    foreach (explode("\n", $values['usernames']) as $username) {
        $username = trim($username);
        if (!empty($username)) {
            $usernames[] = $username;
        }
    }
    if (empty($usernames) and !empty($values['authinstance'])) {
        // Export all users from the selected institution
        $rs = get_recordset_select('usr', 'authinstance = ? AND deleted = 0', array($values['authinstance']), '', 'username');
        while ($record = $rs->FetchRow()) {
            $usernames[] = $record['username'];
        }
    }
    safe_require('export', 'leap');
    $listing = array();
    $files = array();
    $exportcount = 0;
    $exporterrors = array();
    $num_users = count($usernames);
    foreach ($usernames as $username) {
        if (!($exportcount % 25)) {
            set_progress_info('bulkexport', $exportcount, $num_users, get_string('validating', 'admin'));
        }
        $user = new User();
        try {
            $user->find_by_username($username);
        } catch (AuthUnknownUserException $e) {
            continue;
            // Skip non-existent users
        }
        $exporter = new PluginExportLeap($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS);
        try {
            $zipfile = $exporter->export();
        } catch (Exception $e) {
            $exporterrors[] = $username;
            continue;
        }
        $listing[] = array($username, $zipfile);
        $files[] = $exporter->get('exportdir') . $zipfile;
        $exportcount++;
    }
    if (!($zipfile = create_zipfile($listing, $files))) {
        export_iframe_die(get_string('bulkexportempty', 'admin'));
    }
    log_info("Exported {$exportcount} users to {$zipfile}");
    if (!empty($exporterrors)) {
        $SESSION->add_error_msg(get_string('couldnotexportusers', 'admin', implode(', ', $exporterrors)));
    }
    // Store the filename in the session, and redirect the iframe to it to trigger
    // the download. Here it would be nice to trigger the download for everyone,
    // but alas this is not possible for people without javascript.
    $SESSION->set('exportfile', $zipfile);
    set_progress_done('bulkexport', array('redirect' => get_config('wwwroot') . 'admin/users/bulkexport.php'));
    // Download the export file once it has been generated
    require_once 'file.php';
    serve_file($zipfile, basename($zipfile), 'application/x-zip', array('lifetime' => 0, 'forcedownload' => true));
    // TODO: delete the zipfile (and temporary files) once it's been downloaded
}
$listing = array();
$files = array();
$exportcount = 0;
$exporterrors = array();
foreach ($exportdata as $username) {
    $user = new User();
    try {
        $user->find_by_username($username);
    } catch (AuthUnknownUserException $e) {
        continue;
        // Skip non-existent users
    }
    $percentage = (double) $exportcount / count($exportdata) * 100;
    $percentage = min($percentage, 98);
    export_iframe_progress_handler($percentage, get_string('exportingusername', 'admin', $username));
    $exporter = new PluginExportLeap($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS);
    try {
        $zipfile = $exporter->export();
    } catch (Exception $e) {
        $exporterrors[] = $username;
        continue;
    }
    $listing[] = array($username, $zipfile);
    $files[] = $exporter->get('exportdir') . $zipfile;
    $exportcount++;
}
export_iframe_progress_handler(99, get_string('creatingzipfile', 'export'));
if (!($zipfile = create_zipfile($listing, $files))) {
    export_iframe_die(get_string('bulkexportempty', 'admin'));
}
export_iframe_progress_handler(100, get_string('Done', 'export'));