diff --git a/htdocs/artefact/internal/notes.json.php b/htdocs/artefact/internal/notes.json.php new file mode 100644 index 0000000000000000000000000000000000000000..a090781833c35c42f24c6ab3c89316f43c769dde --- /dev/null +++ b/htdocs/artefact/internal/notes.json.php @@ -0,0 +1,239 @@ +get('id'))) { + throw new AccessDeniedException(get_string('accessdenied', 'error')); + } + $groupobj = group_current_group(); + $pageheading = get_string('notesfor', 'artefact.internal', $groupobj->name); + $where = '"group" = ?'; + $values = array($group); + $params['group'] = $group; +} +else if ($institution = param_alpha('institution', null)) { + if ($institution == 'mahara') { + define('ADMIN', 1); + define('MENUITEM', 'configsite'); + $pageheading = get_string('Notes', 'artefact.internal'); + } + else { + define('INSTITUTIONALADMIN', 1); + define('MENUITEM', 'manageinstitutions'); + require_once('institution.php'); + $institutionobj = new Institution($institution); + $pageheading = get_string('notesfor', 'artefact.internal', $institutionobj->displayname); + } + if (!$USER->can_edit_institution($institution)) { + throw new AccessDeniedException(get_string('accessdenied', 'error')); + } + $where = 'institution = ?'; + $values = array($institution); + $params['institution'] = $institution; +} +else { + define('MENUITEM', 'content/notes'); + $pageheading = get_string('mynotes', 'artefact.internal'); + $where = 'owner = ?'; + $values = array($USER->get('id')); +} + +if ($params) { + $baseurl .= '?' . http_build_query($params); +} + +$where .= ' AND artefacttype = ?'; +$values[] = 'html'; + +$count = count_records_select('artefact', $where, $values); + +$data = get_records_select_assoc( + 'artefact', $where, $values, + 'title, id', '*', $offset, $limit +); + +// Get blocks +if ($data) { + $blocks = get_records_sql_assoc(' + SELECT + bi.id AS block, bi.title AS blocktitle, + va.artefact, + va.view, v.title AS viewtitle, v.owner, v.group, v.institution, v.ownerformat, v.urlid + FROM + {block_instance} bi + JOIN {view_artefact} va ON bi.id = va.block + JOIN {view} v ON va.view = v.id + WHERE + va.artefact IN (' . join(',', array_fill(0, count($data), '?')) . ') + ORDER BY va.view, bi.title', + array_keys($data) + ); + if ($blocks) { + $viewdata = array(); + foreach ($blocks as $b) { + if (!isset($viewdata[$b->view])) { + $viewdata[$b->view] = (object) array( + 'id' => $b->view, + 'title' => $b->viewtitle, + 'owner' => $b->owner, + 'group' => $b->group, + 'institution' => $b->institution, + 'ownerformat' => $b->ownerformat, + 'urlid' => $b->urlid, + ); + } + } + View::get_extra_view_info($viewdata, false, false); + + foreach ($blocks as $b) { + if (!isset($data[$b->artefact]->views)) { + $data[$b->artefact]->views = array(); + } + if (!isset($data[$b->artefact]->views[$b->view])) { + $data[$b->artefact]->views[$b->view] = array( + 'view' => $b->view, + 'viewtitle' => $b->viewtitle, + 'fullurl' => $viewdata[$b->view]['fullurl'], + ); + // Add the view owner's name if it's not the same as the note owner. This will either + // be a group artefact inside an individual's view, or it's an institution/site artefact. + if ((!empty($params['group']) && $b->owner) + || (!empty($params['institution']) && $params['institution'] != $b->institution)) { + if ($b->owner) { + $ownername = display_default_name($viewdata[$b->view]['user']); + $ownerurl = profile_url($viewdata[$b->view]['user']); + } + else if ($b->group) { + $ownername = $viewdata[$b->view]['groupdata']['name']; + $ownerurl = group_homepage_url($viewdata[$b->view]['groupdata']); + } + else if ($b->institution == 'mahara') { + $ownername = get_config('sitename'); + } + else { + $ownername = $b->institutionname; + $ownerurl = get_config('wwwroot') . 'institution/index.php?institution=' . $b->institution; + } + $data[$b->artefact]->views[$b->view]['ownername'] = $ownername; + $data[$b->artefact]->views[$b->view]['ownerurl'] = $ownerurl; + } + } + if (!isset($data[$b->artefact]->blocks)) { + $data[$b->artefact]->blocks = array(); + } + if (!isset($data[$b->artefact]->blocks[$b->block])) { + $data[$b->artefact]->blocks[$b->block] = (array)$b; + (!isset($data[$b->artefact]->views[$b->view]['extrablocks'])) ? $data[$b->artefact]->views[$b->view]['extrablocks'] = 0 : $data[$b->artefact]->views[$b->view]['extrablocks'] ++; + } + if (!isset($data[$b->artefact]->tags)) { + $data[$b->artefact]->tags = ArtefactType::artefact_get_tags($b->artefact); + } + } + } + foreach ($data as $id => $n) { + $n->deleteform = pieform(deletenote_form($id, $n)); + } +} + +// Get the attached files. +$noteids = array(); +if ($data) { + $noteids = array_keys($data); +} +$files = ArtefactType::attachments_from_id_list($noteids); +if ($files) { + safe_require('artefact', 'file'); + foreach ($files as $file) { + $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', array('id' => $file->attachment)); + $data[$file->artefact]->files[] = $file; + } +} +// Add Attachments count for each Note +if ($data) { + foreach ($data as $item) { + $item->count = isset($item->files) ? count($item->files) : 0; + } +} + +$pagination = build_pagination(array( + 'id' => 'notes_pagination', + 'url' => $baseurl, + 'datatable' => 'notes', + 'count' => $count, + 'limit' => $limit, + 'offset' => $offset, + 'jsonscript' => 'artefact/internal/notes.json.php', + 'setlimit' => true, + 'jumplinks' => 6, + 'numbersincludeprevnext' => 2, +)); + +$smarty = smarty_core(); +$smarty->assign_by_ref('data', $data); +$html = $smarty->fetch('artefact:internal:noteresults.tpl'); + +function deletenote_form($id, $notedata) { + global $THEME; + $form = array( + 'name' => 'delete_' . $id, + 'successcallback' => 'deletenote_submit', + 'class' => 'form-as-button', + 'elements' => array( + 'delete' => array( + 'type' => 'hidden', + 'value' => $id, + ), + 'submit' => array( + 'type' => 'button', + 'usebuttontag' => true, + 'class' => 'btn-default btn-xs last', + 'elementtitle' => get_string('delete'), + 'value' => ' ', + ), + ), + ); + if (!empty($notedata->blocks)) { + $form['elements']['submit']['confirm'] = get_string( + 'confirmdeletenote', 'artefact.internal', + count($notedata->blocks), count($notedata->views) + ); + } + return $form; +} + +json_reply(false, array( + 'message' => null, + 'data' => array( + 'tablerows' => $html, + 'pagination' => $pagination['html'], + 'pagination_js' => $pagination['javascript'], + 'count' => $count, + 'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')), + 'offset' => $offset, + 'setlimit' => $setlimit, + ) +)); \ No newline at end of file diff --git a/htdocs/artefact/internal/notes.php b/htdocs/artefact/internal/notes.php index 11fe52f17a8a5307dc43cc9d1687fa9ab0f0ced7..dbebf79651ce88bcbc1a0f494384a27428095b46 100644 --- a/htdocs/artefact/internal/notes.php +++ b/htdocs/artefact/internal/notes.php @@ -186,6 +186,10 @@ $pagination = build_pagination(array( 'count' => $count, 'limit' => $limit, 'offset' => $offset, + 'jsonscript' => 'artefact/internal/notes.json.php', + 'setlimit' => true, + 'jumplinks' => 6, + 'numbersincludeprevnext' => 2, )); $js = ' @@ -196,11 +200,14 @@ jQuery(function($) { }); });'; -$smarty = smarty(); +$smarty = smarty(array('paginator')); $smarty->assign('PAGEHEADING', $pageheading); $smarty->assign('INLINEJAVASCRIPT', $js); $smarty->assign_by_ref('data', $data); -$smarty->assign('pagination', $pagination); +$html = $smarty->fetch('artefact:internal:noteresults.tpl'); +$smarty->assign('datarows', $html); +$smarty->assign('pagination', $pagination['html']); +$smarty->assign('pagination_js', $pagination['javascript']); $smarty->display('artefact:internal:notes.tpl'); function deletenote_form($id, $notedata) { diff --git a/htdocs/theme/raw/plugintype/artefact/internal/templates/noteresults.tpl b/htdocs/theme/raw/plugintype/artefact/internal/templates/noteresults.tpl new file mode 100755 index 0000000000000000000000000000000000000000..cbd35c0e4fec88f01b8ae3f93e584ea717f49ab5 --- /dev/null +++ b/htdocs/theme/raw/plugintype/artefact/internal/templates/noteresults.tpl @@ -0,0 +1,102 @@ + {foreach from=$data item=n} + + + {if $n->locked} +

+ + {$n->title} + + {str tag=clickformore} + + +

+ {else} +

+ + {$n->title} + + {str tag=clickformore} + + +

+ {/if} + + {if $n->tags} +
+ {str tag=tags}: {list_tags tags=$n->tags owner=$n->owner} +
+ {/if} + + + {foreach from=$n->blocks item=b} +
+ {$b.blocktitle} +
+ {/foreach} + + + {foreach from=$n->views item=v} +
+ {$v.viewtitle} + {if $v.ownername} - {str tag=by section=view} {if $v.ownerurl}{/if}{$v.ownername}{if $v.ownerurl}{/if}{/if} +
+ {if $v.extrablocks} + {for i 1 $v.extrablocks} +
 
+ {/for} + {/if} + {/foreach} + + + + {$n->count} + + + {if $n->locked} + + {str tag=Submitted section=view} + + {else} +
+ + + + {str(tag=editspecific arg1=$n->title)|escape:html|safe} + + + {if $n->deleteform}{$n->deleteform|safe}{/if} +
+ {/if} + + + {/foreach} \ No newline at end of file diff --git a/htdocs/theme/raw/plugintype/artefact/internal/templates/notes.tpl b/htdocs/theme/raw/plugintype/artefact/internal/templates/notes.tpl index da6b4ef6d1f7033323f0b1304f42d3579cab1fea..08c7a37d6434ee68085c2002b55c1554b3933773 100755 --- a/htdocs/theme/raw/plugintype/artefact/internal/templates/notes.tpl +++ b/htdocs/theme/raw/plugintype/artefact/internal/templates/notes.tpl @@ -21,110 +21,14 @@ - {foreach from=$data item=n} - - - {if $n->locked} -

- - {$n->title} - - {str tag=clickformore} - - -

- {else} -

- - {$n->title} - - {str tag=clickformore} - - -

- {/if} - - {if $n->tags} -
- {str tag=tags}: {list_tags tags=$n->tags owner=$n->owner} -
- {/if} - - - {foreach from=$n->blocks item=b} -
- {$b.blocktitle} -
- {/foreach} - - - {foreach from=$n->views item=v} -
- {$v.viewtitle} - {if $v.ownername} - {str tag=by section=view} {if $v.ownerurl}{/if}{$v.ownername}{if $v.ownerurl}{/if}{/if} -
- {if $v.extrablocks} - {for i 1 $v.extrablocks} -
 
- {/for} - {/if} - {/foreach} - - - - {$n->count} - - - {if $n->locked} - - {str tag=Submitted section=view} - - {else} -
- - - - {str(tag=editspecific arg1=$n->title)|escape:html|safe} - - - {if $n->deleteform}{$n->deleteform|safe}{/if} -
- {/if} - - - {/foreach} + {$datarows|safe} -{$pagination.html|safe} +{$pagination|safe} +{if $pagination_js} + +{/if} {include file="footer.tpl"}