Exemplo n.º 1
0
function deletenote_submit(Pieform $form, array $values)
{
    global $SESSION, $data, $baseurl;
    require_once 'embeddedimage.php';
    $id = $data[$values['delete']]->id;
    $note = new ArtefactTypeHtml($id);
    $note->delete();
    $SESSION->add_ok_msg(get_string('notedeleted', 'artefact.internal'));
    redirect($baseurl);
}
Exemplo n.º 2
0
 /**
  * This function is meant to be run (either via the "convertnotes.php" CLI script,
  * or from the blocktype/text plugin config page) shortly after upgrading to
  * Mahara 1.10. It will locate all the existing Note blocks & their underlying Note
  * artefacts, and convert them into simple Text blocks if they are not using
  * any of the Note artefact's advanced features.
  *
  * @param integer $limit Limit the number of records processed to this many.
  * @return integer The number of notes converted
  */
 public static function convert_notes_to_text_blocks($limit = null)
 {
     $rs = self::find_convertible_text_blocks($limit);
     if (!$rs) {
         log_info("No old-style Text Box blocks to process.");
         return 0;
     }
     $total = $rs->NumRows();
     $countprocessed = 0;
     $countconverted = 0;
     log_info("Preparing to process {$total} old-style Text Box blocks.");
     while ($record = $rs->FetchRow()) {
         $countprocessed++;
         if ($countprocessed % 1000 == 0) {
             log_info("{$countprocessed}/{$total} processed...");
         }
         $record = (object) $record;
         $oldconfigdata = unserialize($record->configdata);
         // don't convert textboxes with tags, because the text doesn't support tags
         if (array_key_exists('tags', $oldconfigdata) && count($oldconfigdata['tags']) > 0) {
             continue;
         }
         // don't convert textboxes with a license, because the text
         // doesn't support licenses
         if (array_key_exists('license', $oldconfigdata) && strlen($oldconfigdata['license']) > 0) {
             continue;
         }
         // don't convert textboxes with connected artefacts, because the text
         // doesn't support additional artefacts
         if (array_key_exists('artefactids', $oldconfigdata) && count($oldconfigdata['artefactids']) > 0) {
             continue;
         }
         // ignore if the artefacttype returned is not 'html' - seems to exist if a text box has a download link in the markup
         if ($record->artefacttype != 'html') {
             continue;
         }
         db_begin();
         $record = (object) array('id' => $record->id, 'configdata' => $oldconfigdata, 'artefact' => $record->artefact);
         $htmlartefact = new ArtefactTypeHtml($record->artefact);
         $newconfigdata = array('text' => $htmlartefact->get('description'), 'retractable' => false, 'retractedonload' => false);
         if (array_key_exists('retractable', $record->configdata)) {
             $newconfigdata['retractable'] = $record->configdata['retractable'];
         }
         if (array_key_exists('retractedonload', $record->configdata)) {
             $newconfigdata['retractedonload'] = $record->configdata['retractedonload'];
         }
         $whereobj = (object) array('id' => $record->id);
         $newobj = (object) array('blocktype' => 'text', 'configdata' => serialize($newconfigdata));
         update_record('block_instance', $newobj, $whereobj);
         $htmlartefact->delete();
         $countconverted++;
         db_commit();
     }
     return $countconverted;
 }
Exemplo n.º 3
0
 /**
  * Pieform success callback function for the config form. Converts the
  * text blocks, if the checkbox is ticked
  *
  * @param $form the pieform to send the ok-message to
  * @param array $values
  */
 public static function save_config_options($form, $values)
 {
     global $SESSION;
     if (!array_key_exists('convertcheckbox', $values) || !$values['convertcheckbox']) {
         return;
     }
     $records = self::find_convertible_text_blocks();
     $countconverted = 0;
     db_begin();
     foreach ($records as $record) {
         $htmlartefact = new ArtefactTypeHtml($record->artefact);
         $newconfigdata = array('text' => $htmlartefact->get('description'), 'retractable' => false, 'retractedonload' => false);
         if (array_key_exists('retractable', $record->configdata)) {
             $newconfigdata['retractable'] = $record->configdata['retractable'];
         }
         if (array_key_exists('retractedonload', $record->configdata)) {
             $newconfigdata['retractedonload'] = $record->configdata['retractedonload'];
         }
         $whereobj = (object) array('id' => $record->id);
         $newobj = (object) array('blocktype' => 'text', 'configdata' => serialize($newconfigdata));
         update_record('block_instance', $newobj, $whereobj);
         $htmlartefact->delete();
         $countconverted++;
     }
     db_commit();
     $form->json_reply(PIEFORM_OK, get_string('convertibleokmessage', 'blocktype.text', $countconverted));
 }