Пример #1
0
 /**
  * Configures a blockinstance
  *
  * @param array $values parameters for this function
  */
 public function configureblockinstance($values)
 {
     require_once get_config('docroot') . 'blocktype/lib.php';
     $bi = new BlockInstance($values['id']);
     // Check if the block_instance belongs to this view
     if ($bi->get('view') != $this->get('id')) {
         throw new AccessDeniedException(get_string('blocknotinview', 'view', $bi->get('id')));
     }
     return $bi->render_editing(true);
 }
Пример #2
0
$smarty->assign('view', $view->get('id'));
$smarty->assign('groupid', $group);
$smarty->assign('institution', $institution);
$smarty->assign('can_change_layout', !$USER->get_account_preference('addremovecolumns') || $view->get('numcolumns') > 1 && $view->get('numcolumns') < 5);
if (get_config('userscanchooseviewthemes') && $view->is_themeable()) {
    $smarty->assign('viewtheme', $viewtheme);
    $smarty->assign('viewthemes', $allowedthemes);
}
$smarty->assign('viewid', $view->get('id'));
$smarty->assign('viewtitle', $viewtitle);
if ($owner) {
    $smarty->assign('ownerlink', 'user/view.php?id=' . $owner);
} else {
    if ($group) {
        $smarty->assign('ownerlink', 'group/view.php?id=' . $group);
    }
}
$blockid = $view->get_blockinstance_currently_being_configured();
if (!$blockid) {
    $blockid = param_integer('block', 0);
}
if ($blockid) {
    // Configuring a single block
    $bi = new BlockInstance($blockid);
    $smarty->assign('block', $bi->render_editing(true));
} else {
    // The HTML for the columns in the view
    $columns = $view->build_columns(true);
    $smarty->assign('columns', $columns);
}
$smarty->display('view/blocks.tpl');
Пример #3
0
 public function instance_config_store(Pieform $form, $values)
 {
     global $SESSION, $USER;
     // Destroy form values we don't care about
     unset($values['sesskey']);
     unset($values['blockinstance']);
     unset($values['action_configureblockinstance_id_' . $this->get('id')]);
     unset($values['blockconfig']);
     unset($values['id']);
     unset($values['change']);
     unset($values['new']);
     if (isset($values['retractable'])) {
         switch ($values['retractable']) {
             case BlockInstance::RETRACTABLE_YES:
                 $values['retractable'] = 1;
                 $values['retractedonload'] = 0;
                 break;
             case BlockInstance::RETRACTABLE_RETRACTED:
                 $values['retractable'] = 1;
                 $values['retractedonload'] = 1;
                 break;
             case BlockInstance::RETRACTABLE_NO:
             default:
                 $values['retractable'] = 0;
                 $values['retractedonload'] = 0;
                 break;
         }
     }
     // make sure that user is allowed to publish artefact. This is to stop
     // hacking of form value to attach other users private data.
     $badattachment = false;
     if (!empty($values['artefactid'])) {
         $badattachment = !$this->verify_attachment_permissions($values['artefactid']);
     }
     if (!empty($values['artefactids'])) {
         $badattachment = !$this->verify_attachment_permissions($values['artefactids']);
     }
     if ($badattachment) {
         $result['message'] = get_string('unrecoverableerror', 'error');
         $form->set_error(null, $result['message']);
         $form->reply(PIEFORM_ERR, $result);
         exit;
     }
     $redirect = '/view/blocks.php?id=' . $this->get('view');
     if (param_boolean('new', false)) {
         $redirect .= '&new=1';
     }
     if ($category = param_alpha('c', '')) {
         $redirect .= '&c=' . $category;
     }
     $result = array('goto' => $redirect);
     if (is_callable(array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save'))) {
         try {
             $values = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save', $values, $this);
         } catch (MaharaException $e) {
             $result['message'] = $e instanceof UserException ? $e->getMessage() : get_string('unrecoverableerror', 'error');
             $form->set_error(null, $result['message']);
             $form->reply(PIEFORM_ERR, $result);
         }
     }
     $title = isset($values['title']) ? $values['title'] : '';
     unset($values['title']);
     // A block may return a list of other blocks that need to be
     // redrawn after configuration of this block.
     $torender = !empty($values['_redrawblocks']) && $form->submitted_by_js() ? $values['_redrawblocks'] : array();
     unset($values['_redrawblocks']);
     $this->set('configdata', $values);
     $this->set('title', $title);
     $this->commit();
     try {
         $rendered = $this->render_editing(false, false, $form->submitted_by_js());
     } catch (HTMLPurifier_Exception $e) {
         $message = get_string('blockconfigurationrenderingerror', 'view') . ' ' . $e->getMessage();
         $form->reply(PIEFORM_ERR, array('message' => $message));
     }
     $result = array('error' => false, 'message' => get_string('blockinstanceconfiguredsuccessfully', 'view'), 'data' => $rendered, 'blockid' => $this->get('id'), 'viewid' => $this->get('view'), 'goto' => $redirect);
     // Render all the other blocks in the torender list
     $result['otherblocks'] = array();
     foreach ($torender as $blockid) {
         if ($blockid != $result['blockid']) {
             $otherblock = new BlockInstance($blockid);
             $result['otherblocks'][] = array('blockid' => $blockid, 'data' => $otherblock->render_editing(false, false, true));
         }
     }
     $form->reply(PIEFORM_OK, $result);
 }
Пример #4
0
 /**
  * Configures a blockinstance
  *
  * @param array $values parameters for this function
  */
 public function configureblockinstance($values)
 {
     require_once get_config('docroot') . 'blocktype/lib.php';
     $bi = new BlockInstance($values['id']);
     return $bi->render_editing(true);
 }