public function rebuild_artefact_list() { db_begin(); // Remember what was in this block before saving, and always allow those artefacts to remain // in it, regardless of the user's current permissions. $old = get_records_assoc('view_artefact', 'block', $this->id, '', 'artefact, id'); delete_records('view_artefact', 'block', $this->id); safe_require('blocktype', blocktype_name_to_namespaced($this->get('blocktype'))); if (!($artefacts = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'get_artefacts', $this))) { db_commit(); return true; } foreach ($artefacts as $key => $id) { if (!$id || intval($id) == 0) { log_warn("get_artefacts returned an invalid artefact ID for block instance {$this->id} (" . $this->get('blocktype') . ")"); unset($artefacts[$key]); } } if (count($artefacts) == 0) { db_commit(); return true; } // Get list of allowed artefacts require_once 'view.php'; $searchdata = array('extraselect' => array(array('fieldname' => 'id', 'type' => 'int', 'values' => $artefacts)), 'userartefactsallowed' => true); list($allowed, $count) = View::get_artefactchooser_artefacts($searchdata, $this->get_view()->get('owner'), $this->get_view()->get('group'), $this->get_view()->get('institution'), true); $va = new StdClass(); $va->view = $this->get('view'); $va->block = $this->id; foreach ($artefacts as $id) { if (isset($allowed[$id]) || isset($old[$id])) { $va->artefact = $id; insert_record('view_artefact', $va); } } db_commit(); }