Commit a03f28b1 authored by Nigel McNie's avatar Nigel McNie
Browse files

Prevent a fatal error caused by adding the entireresume blocktype then...

Prevent a fatal error caused by adding the entireresume blocktype then visiting your resume for the first time.

The 'contactinformation' blocktype is attempted to be added to the entireresume blockinstance that has been created, causing badness as the blocktype hasn't actually been committed yet. Move the part of the commit where it's added to the database before the part where it's added to any views.

Also make sure that contact information isn't shown in a view as just a <table></table> if it has no content.
parent 66225696
......@@ -125,27 +125,26 @@ class ArtefactTypeResume extends ArtefactType {
*
* @param boolean $updateresumeblocks Whether to update any resume blockinstances
*/
public function commit($updateresumeblocks=true) {
if ($updateresumeblocks) {
if ($blockinstances = get_records_sql_array('
SELECT id, view, configdata
FROM {block_instance}
WHERE blocktype = \'entireresume\'
AND "view" IN (
SELECT id
FROM {view}
WHERE "owner" = ?)', array($this->owner))) {
foreach ($blockinstances as $blockinstance) {
$whereobject = (object)array(
'view' => $blockinstance->view,
'artefact' => $this->get('id'),
'block' => $blockinstance->id,
);
ensure_record_exists('view_artefact', $whereobject, $whereobject);
}
public function commit() {
parent::commit();
if ($blockinstances = get_records_sql_array('
SELECT id, view, configdata
FROM {block_instance}
WHERE blocktype = \'entireresume\'
AND "view" IN (
SELECT id
FROM {view}
WHERE "owner" = ?)', array($this->owner))) {
foreach ($blockinstances as $blockinstance) {
$whereobject = (object)array(
'view' => $blockinstance->view,
'artefact' => $this->get('id'),
'block' => $blockinstance->id,
);
ensure_record_exists('view_artefact', $whereobject, $whereobject);
}
}
parent::commit();
}
}
......@@ -175,13 +174,14 @@ class ArtefactTypeInterest extends ArtefactTypeResume {
class ArtefactTypeContactinformation extends ArtefactTypeResume {
public function render_self($options) {
$smarty = smarty();
$smarty = smarty_core();
$fields = ArtefactTypeContactinformation::get_profile_fields();
foreach ($fields as $f) {
try {
$$f = artefact_instance_from_type($f);
$rendered = $$f->render_self(array());
$smarty->assign($f, format_whitespace($rendered['html']));
$smarty->assign('hascontent', true);
}
catch (Exception $e) { }
}
......
{if $hascontent}
<table>
{if $address}
<tr>
......@@ -48,3 +49,4 @@
</tr>
{/if}
</table>
{/if}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment