本文整理汇总了PHP中BlockInstance::rebuild_artefact_list方法的典型用法代码示例。如果您正苦于以下问题:PHP BlockInstance::rebuild_artefact_list方法的具体用法?PHP BlockInstance::rebuild_artefact_list怎么用?PHP BlockInstance::rebuild_artefact_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockInstance
的用法示例。
在下文中一共展示了BlockInstance::rebuild_artefact_list方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: commit
public function commit()
{
if (empty($this->dirty)) {
return;
}
$new = empty($this->id);
db_begin();
parent::commit();
// Now fix up the text in case there were any embedded images.
// Do this after saving because we may not have an artefactid yet.
// This will add a record to the artefact_file_embedded table
// for each file that is embedded in the feedback text.
require_once 'embeddedimage.php';
$newtext = EmbeddedImage::prepare_embedded_images($this->get('description'), 'annotationfeedback', $this->id);
if ($newtext !== false && $newtext !== $this->get('description')) {
$updatedartefact = new stdClass();
$updatedartefact->id = $this->get('id');
$updatedartefact->description = $newtext;
update_record('artefact', $updatedartefact, 'id');
}
$data = (object) array('artefact' => $this->get('id'), 'onannotation' => $this->get('onannotation'), 'private' => $this->get('private'), 'deletedby' => $this->get('deletedby'), 'requestpublic' => $this->get('requestpublic'));
if ($this->get('lastcontentupdate')) {
$data->lastcontentupdate = db_format_timestamp($this->get('lastcontentupdate'));
}
if ($new) {
insert_record('artefact_annotation_feedback', $data);
} else {
update_record('artefact_annotation_feedback', $data, 'artefact');
}
// Get the block instance that contains this artefact
// so we can add to the view any artefacts containted in the feedback text
// as well as the feedback itself.
$sql = "SELECT bi.*\n FROM {block_instance} bi\n INNER JOIN {view_artefact} va ON va.view = bi.view\n WHERE bi.blocktype = 'annotation'\n AND va.artefact = ?";
if ($blocks = get_records_sql_array($sql, array($this->get('onannotation')))) {
require_once get_config('docroot') . 'blocktype/lib.php';
foreach ($blocks as $bi) {
$block = new BlockInstance($bi->id);
$blockconfig = $block->get('configdata');
if (isset($blockconfig['artefactid']) && $blockconfig['artefactid'] == $this->get('onannotation')) {
// Currently, all annotations can only exist on views.
// But, put the check anyway.
if ($block->get('view')) {
// We found the annotation we're inputting feedback for.
// Rebuild the block's list and break out of the loop.
$block->rebuild_artefact_list();
// Otherwise, we can do this but any images that were deleted while editing will still exist.
// if (count_records_select('view_artefact', "view = {$block->get('view')} AND block = {$block->get('id')} AND artefact = {$this->get('id')}") == 0) {
// // Insert the feedback record in the view_artefact table.
// $va = new StdClass;
// $va->view = $block->get('view');
// $va->block = $block->get('id');
// // this is the feedback id that was just inserted/updated.
// $va->artefact = $this->get('id');
// insert_record('view_artefact', $va);
// }
//
// // Get any artefacts (i.e. images) that may have been embedded
// // in the feedback text.
// $feedbackartefacts = artefact_get_references_in_html($this->get('description'));
// if (count($feedbackartefacts) > 0) {
//
// // Get list of allowed artefacts.
// // Please note that images owned by other users that are place on feedback
// // will not be part of the view_artefact because the owner of the
// // annotation does not own the image being placed on the feedback.
// // Therefore, when exported as Leap2A, these images will not come through.
// require_once('view.php');
// $searchdata = array(
// 'extraselect' => array(array('fieldname' => 'id', 'type' => 'int', 'values' => $feedbackartefacts)),
// 'userartefactsallowed' => true, // If this is a group view, the user can add personally owned artefacts
// );
// $view = $block->get_view();
// list($allowedfeedbackartefacts, $count) = View::get_artefactchooser_artefacts(
// $searchdata,
// $view->get('owner'),
// $view->get('group'),
// $view->get('institution'),
// true
// );
// foreach ($feedbackartefacts as $id) {
// $va = new StdClass;
// $va->view = $block->get('view');
// $va->block = $block->get('id');
// if (isset($allowedfeedbackartefacts[$id]) || isset($old[$id])) {
// // only insert artefacts that the view can actually own
// // and which are not already in the view_artefact table.
// $va->artefact = $id;
// if (count_records_select('view_artefact', "view = {$block->get('view')} AND block = {$block->get('id')} AND artefact = {$id}") == 0) {
// insert_record('view_artefact', $va);
// }
// }
// }
// }
}
break;
}
}
}
db_commit();
$this->dirty = false;
//.........这里部分代码省略.........
示例2: postcommit_hook
/**
* This method extends ArtefactType::commit() by adding additional data
* into the artefact_blog_blogpost table.
*
* This method also works out what blockinstances this blogpost is in, and
* informs them that they should re-check what artefacts they have in them.
* The post content may now link to different artefacts. See {@link
* PluginBlocktypeBlogPost::get_artefacts for more information}
*/
protected function postcommit_hook($new)
{
require_once get_config('docroot') . 'blocktype/lib.php';
require_once get_config('docroot') . 'artefact/blog/blocktype/taggedposts/lib.php';
$data = (object) array('blogpost' => $this->get('id'), 'published' => $this->get('published') ? 1 : 0);
if ($new) {
insert_record('artefact_blog_blogpost', $data);
} else {
update_record('artefact_blog_blogpost', $data, 'blogpost');
}
// We want to get all blockinstances that may contain this blog post. That is currently:
// 1) All blogpost blocktypes with this post in it
// 2) All blog blocktypes with this posts's blog in it
// 3) All recentposts blocktypes with this post's blog in it
// 4) All taggedposts blocktypes with this post's tags
$blocks = (array) get_column_sql('SELECT block
FROM {view_artefact}
WHERE artefact = ?
OR artefact = ?', array($this->get('id'), $this->get('parent')));
if (!$blocks) {
$blocks = array();
}
// Get all "tagged blog entries" blocks that may contain this block
// (we'll just check for a single matching tag here, and let each block
// instance further down decide whether or not it matches
$tags = $this->get('tags');
if ($tags) {
$blocks = array_merge($blocks, PluginBlocktypeTaggedposts::find_matching_blocks($tags));
}
// Now rebuild the list of which artefacts these blocks contain
// in the view_artefacts table. (This is used for watchlist notifications)
if ($blocks) {
foreach ($blocks as $id) {
$instance = new BlockInstance($id);
$instance->rebuild_artefact_list();
}
}
}
示例3: create_from_template
/**
* Creates a View for the given user, based off a given template and other
* View information supplied.
*
* Will set a default title of 'Copy of $viewtitle' if title is not
* specified in $viewdata and $titlefromtemplate == false.
*
* @param array $viewdata See View::_create
* @param int $templateid The ID of the View to copy
* @param int $userid The user who has issued the command to create the
* view. See View::_create
* @param int $checkaccess Whether to check that the user can see the view before copying it
* @return array A list consisting of the new view, the template view and
* information about the copy - i.e. how many blocks and
* artefacts were copied
* @throws SystemException under various circumstances, see the source for
* more information
*/
public static function create_from_template($viewdata, $templateid, $userid = null, $checkaccess = true, $titlefromtemplate = false)
{
if (is_null($userid)) {
global $USER;
$userid = $USER->get('id');
}
$user = new User();
$user->find_by_id($userid);
db_begin();
$template = new View($templateid);
if ($template->get('deleted')) {
throw new SystemException("View::create_from_template: This template has been deleted");
}
if ($checkaccess && !$template->get('template') && !$user->can_edit_view($template)) {
throw new SystemException("View::create_from_template: Attempting to create a View from another View that is not marked as a template");
} else {
if ($checkaccess && !can_view_view($templateid, $userid)) {
throw new SystemException("View::create_from_template: User {$userid} is not permitted to copy View {$templateid}");
}
}
$view = self::_create($viewdata, $userid);
// Set a default title if one wasn't set
if ($titlefromtemplate) {
$view->set('title', $template->get('title'));
} else {
if (!isset($viewdata['title']) && !($template->get('owner') == 0 && $template->get('type') == 'portfolio')) {
$desiredtitle = $template->get('title');
if (get_config('renamecopies')) {
$desiredtitle = get_string('Copyof', 'mahara', $desiredtitle);
}
$view->set('title', self::new_title($desiredtitle, (object) $viewdata));
$view->set('dirty', true);
}
}
$view->urlid = generate_urlid($view->title, get_config('cleanurlviewdefault'), 3, 100);
$viewdata['owner'] = $userid;
$view->urlid = self::new_urlid($view->urlid, (object) $viewdata);
try {
$copystatus = $view->copy_contents($template);
} catch (QuotaExceededException $e) {
db_rollback();
return array(null, $template, array('quotaexceeded' => true));
}
$view->commit();
// if layout is set, and it's not a default layout
// add an entry to usr_custom_layout if one does not already exist
if ($template->get('layout') !== null) {
$customlayout = get_record('view_layout', 'id', $template->get('layout'), 'iscustom', 1);
if ($customlayout !== false) {
// is the owner of the copy going to be a group or institution or not?
$owner = $view->owner;
$group = $view->group;
$institution = $view->institution;
$haslayout = false;
if (!empty($group)) {
$owner = null;
$haslayout = get_record('usr_custom_layout', 'layout', $template->get('layout'), 'group', $group);
}
if (!empty($institution)) {
$owner = null;
$haslayout = get_record('usr_custom_layout', 'layout', $template->get('layout'), 'institution', $institution);
} else {
if (isset($owner)) {
$haslayout = get_record('usr_custom_layout', 'layout', $template->get('layout'), 'usr', $owner);
}
}
if (!$haslayout) {
$newcustomlayout = insert_record('usr_custom_layout', (object) array('usr' => $owner, 'group' => $group, 'institution' => $institution, 'layout' => $template->get('layout')));
}
}
}
$blocks = get_records_array('block_instance', 'view', $view->get('id'));
if ($blocks) {
foreach ($blocks as $b) {
// As some artefact references have been changed, e.g embedded images
// we need to rebuild the artefact list for each block
$bi = new BlockInstance($b->id);
$bi->rebuild_artefact_list();
$configdata = unserialize($b->configdata);
if (!isset($configdata['artefactid'])) {
continue;
}
//.........这里部分代码省略.........
示例4: commit
/**
* This method extends ArtefactType::commit() by adding additional data
* into the artefact_blog_blogpost table.
*
* This method also works out what blockinstances this blogpost is in, and
* informs them that they should re-check what artefacts they have in them.
* The post content may now link to different artefacts. See {@link
* PluginBlocktypeBlogPost::get_artefacts for more information}
*/
public function commit()
{
if (empty($this->dirty)) {
return;
}
db_begin();
$new = empty($this->id);
parent::commit();
$this->dirty = true;
$data = (object) array('blogpost' => $this->get('id'), 'published' => $this->get('published') ? 1 : 0);
if ($new) {
insert_record('artefact_blog_blogpost', $data);
} else {
update_record('artefact_blog_blogpost', $data, 'blogpost');
}
// We want to get all blockinstances that contain this blog post. That is currently:
// 1) All blogpost blocktypes with this post in it
// 2) All blog blocktypes with this posts's blog in it
//
// With these, we tell them to rebuild what artefacts they have in them,
// since the post content could have changed and now have links to
// different artefacts in it
$blockinstanceids = (array) get_column_sql('SELECT block
FROM {view_artefact}
WHERE artefact = ?
OR artefact = ?', array($this->get('id'), $this->get('parent')));
if ($blockinstanceids) {
require_once get_config('docroot') . 'blocktype/lib.php';
foreach ($blockinstanceids as $id) {
$instance = new BlockInstance($id);
$instance->rebuild_artefact_list();
}
}
db_commit();
$this->dirty = false;
}