Exemplo n.º 1
0
 public static function instance_config_save($values, $instance)
 {
     global $USER;
     require_once 'embeddedimage.php';
     $data = array();
     $view = $instance->get_view();
     foreach (array('owner', 'group', 'institution') as $f) {
         $data[$f] = $view->get($f);
     }
     if (empty($values['artefactid']) || $values['makecopy']) {
         // The artefact title will be the same as the block title when the
         // artefact is first created, or, if there's no block title, generate
         // 'Note (1)', 'Note (2)', etc.  After that, the artefact title can't
         // be edited inside the block, but can be changed in the Notes area.
         if (empty($values['title'])) {
             $title = artefact_new_title(get_string('Note', 'artefact.internal'), 'html', $data['owner'], $data['group'], $data['institution']);
         } else {
             $title = $values['title'];
         }
         $artefact = new ArtefactTypeHtml(0, $data);
         $artefact->set('title', $title);
         $artefact->set('description', $values['text']);
         if (get_config('licensemetadata')) {
             $artefact->set('license', $values['license']);
             $artefact->set('licensor', $values['licensor']);
             $artefact->set('licensorurl', $values['licensorurl']);
         }
         $artefact->set('allowcomments', !empty($values['allowcomments']) ? $values['allowcomments'] : 0);
         $artefact->set('tags', $values['tags']);
     } else {
         $artefact = new ArtefactTypeHtml((int) $values['artefactid']);
         if (!$USER->can_publish_artefact($artefact)) {
             throw new AccessDeniedException(get_string('nopublishpermissiononartefact', 'mahara', hsc($artefact->get('title'))));
         }
         // Stop users from editing textbox artefacts whose owner is not the same as the
         // view owner, even if they would normally be allowed to edit the artefact.
         // It's too confusing.  Textbox artefacts with other owners *can* be included in
         // the view read-only, provided the artefact has the correct republish
         // permission.
         if ($artefact->get('owner') === $data['owner'] && $artefact->get('group') === $data['group'] && $artefact->get('institution') === $data['institution'] && !$artefact->get('locked') && $USER->can_edit_artefact($artefact)) {
             $newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'textbox', (int) $values['artefactid'], $view->get('group'));
             $artefact->set('description', $newdescription);
             if (get_config('licensemetadata')) {
                 $artefact->set('license', $values['license']);
                 $artefact->set('licensor', $values['licensor']);
                 $artefact->set('licensorurl', $values['licensorurl']);
             }
             $artefact->set('tags', $values['tags']);
             $artefact->set('allowcomments', !empty($values['allowcomments']) ? 1 : 0);
         }
     }
     $artefact->commit();
     $newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'textbox', $artefact->get('id'), $view->get('group'));
     if ($newdescription !== $values['text']) {
         $updatedartefact = new stdClass();
         $updatedartefact->id = $artefact->get('id');
         $updatedartefact->description = $newdescription;
         update_record('artefact', $updatedartefact, 'id');
     }
     // Add attachments, if there are any...
     $old = $artefact->attachment_id_list();
     $new = is_array($values['artefactids']) ? $values['artefactids'] : array();
     // only allow the attaching of files that exist and are editable by user
     foreach ($new as $key => $fileid) {
         $file = artefact_instance_from_id($fileid);
         if (!$file instanceof ArtefactTypeFile || !$USER->can_publish_artefact($file)) {
             unset($new[$key]);
         }
     }
     if (!empty($new) || !empty($old)) {
         foreach ($old as $o) {
             if (!in_array($o, $new)) {
                 try {
                     $artefact->detach($o);
                 } catch (ArtefactNotFoundException $e) {
                 }
             }
         }
         foreach ($new as $n) {
             if (!in_array($n, $old)) {
                 try {
                     $artefact->attach($n);
                 } catch (ArtefactNotFoundException $e) {
                 }
             }
         }
     }
     $values['artefactid'] = $artefact->get('id');
     $instance->save_artefact_instance($artefact);
     unset($values['text']);
     unset($values['otherblocksmsg']);
     unset($values['readonlymsg']);
     unset($values['textreadonly']);
     unset($values['makecopy']);
     unset($values['chooseartefact']);
     unset($values['managenotes']);
     unset($values['allowcomments']);
     // Pass back a list of any other blocks that need to be rendered
     // due to this change.
     $values['_redrawblocks'] = array_unique(get_column('view_artefact', 'block', 'artefact', $values['artefactid'], 'view', $instance->get('view')));
     return $values;
 }
Exemplo n.º 2
0
 public static function import_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     $artefactmapping = array();
     $entrydata = self::get_entry_data_using_strategy($entry, $importer, $strategy, $otherentries);
     if (!empty($entrydata)) {
         switch ($entrydata['type']) {
             case 'introduction':
                 $introduction = new ArtefactTypeIntroduction(0, array('owner' => $importer->get('usr')));
                 $introduction->set('title', $entrydata['content']['title']);
                 $introduction->commit();
                 $artefactmapping[(string) $entry->id] = array($introduction->get('id'));
                 break;
             case 'html':
                 $note = new ArtefactTypeHtml();
                 $note->set('title', $entrydata['content']['title']);
                 $note->set('description', $entrydata['content']['description']);
                 $note->set('ctime', strtotime($entrydata['content']['ctime']));
                 $note->set('mtime', strtotime($entrydata['content']['mtime']));
                 $note->set('owner', $entrydata['owner']);
                 $note->commit();
                 $artefactmapping[(string) $entry->id] = array($note->get('id'));
                 // Check for note's attachments
                 if (isset($entry->link)) {
                     foreach ($entry->link as $link) {
                         if ($id = $importer->create_attachment($entry, $link, $note)) {
                             $artefactmapping[$link['href']][] = $id;
                         }
                     }
                     $note->commit();
                 }
                 break;
             default:
                 $artefactmapping[(string) $entry->id] = array(self::create_artefact($importer, $entrydata['type'], $entrydata['content']['title']));
                 break;
         }
     }
     return $artefactmapping;
 }