Commit ca27f78b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Remove view owner search box; incorporate in single search result list

parent 05521c87
......@@ -1529,6 +1529,7 @@ class View {
* - v is visible to users with role r of group g at t, and u is a member of g with role r (view_access_group)
*
* @param string $query Search string
* @param string $ownerquery Search string for owner
* @param StdClass $ownedby Only return views owned by this owner (user, group, institution)
* @param StdClass $copyableby Only return views copyable by this owner (user, group, institution)
* @param integer $limit
......@@ -1536,7 +1537,7 @@ class View {
* @param bool $extra Return full set of properties on each view including an artefact list
*
*/
public static function view_search($query=null, $ownedby=null, $copyableby=null, $limit=null, $offset=0, $extra=true) {
public static function view_search($query=null, $ownerquery=null, $ownedby=null, $copyableby=null, $limit=null, $offset=0, $extra=true) {
global $USER;
$admin = $USER->get('admin');
$loggedin = $USER->is_logged_in();
......@@ -1554,8 +1555,8 @@ class View {
AND (v.template = 1 OR (v.' . self::owner_sql($copyableby) . '))';
}
$like = db_ilike();
if ($query) {
$like = db_ilike();
$where .= "
AND (v.title $like '%' || ? || '%' OR v.description $like '%' || ? || '%' )";
$ph = array($query, $query);
......@@ -1632,6 +1633,29 @@ class View {
$ph = array_merge(array($viewerid,$viewerid,$viewerid,$viewerid), $ph, array($viewerid,$viewerid,$viewerid,$viewerid));
}
if (!$ownedby && $ownerquery) {
$from .= '
LEFT OUTER JOIN {usr} qu ON (v.owner = qu.id)
LEFT OUTER JOIN {group} qg ON (v.group = qg.id)
LEFT OUTER JOIN {institution} qi ON (v.institution = qi.name)';
if (strpos(strtolower(get_config('sitename')), strtolower($ownerquery)) !== false) {
$sitequery = " OR qi.name = 'mahara'";
}
else {
$sitequery = '';
}
$where .= "
AND (
qu.preferredname $like '%' || ? || '%'
OR qu.firstname $like '%' || ? || '%'
OR qu.lastname $like '%' || ? || '%'
OR qg.name $like '%' || ? || '%'
OR qi.displayname $like '%' || ? || '%'
$sitequery
)";
$ph = array_merge($ph, array($ownerquery,$ownerquery,$ownerquery,$ownerquery,$ownerquery));
}
$count = count_records_sql('SELECT COUNT (DISTINCT v.id) ' . $from . $where, $ph);
$viewdata = get_records_sql_array('
SELECT * FROM (
......@@ -1970,49 +1994,8 @@ class View {
return $title . $ext;
}
public static function get_viewownersearch_data(&$search) {
$results = self::search_view_owners($search->query, $search->template, $search->limit, $search->offset);
$params = array();
if (!empty($search->query)) {
$params[] = 'ownerquery=' . $search->query;
}
if (!empty($search->group)) {
$params[] = 'group=' . $search->group;
}
if (!empty($search->institution)) {
$params[] = 'institution=' . $search->institution;
}
$params[] = 'ownerlimit=' . $search->limit;
$qstring = join('&', $params);
$smarty = smarty_core();
$smarty->assign_by_ref('results', $results);
$smarty->assign('viewurl', get_config('wwwroot') . 'view/choosetemplate.php?' . $qstring . '&owneroffset=' . $search->offset);
$search->html = $smarty->fetch('view/viewownersearchresults.tpl');
$search->count = $results['count'];
$search->pagination = build_pagination(array(
'id' => 'viewownersearch_pagination',
'class' => 'center',
'url' => get_config('wwwroot') . 'view/choosetemplate.php?' . $qstring,
'count' => $results['count'],
'limit' => $search->limit,
'offset' => $search->offset,
'offsetname' => 'owneroffset',
'firsttext' => '',
'previoustext' => '',
'nexttext' => '',
'lasttext' => '',
'numbersincludefirstlast' => false,
'resultcounttextsingular' => get_string('owner', 'view'),
'resultcounttextplural' => get_string('owners', 'view'),
));
}
public static function get_templatesearch_data(&$search) {
$results = self::view_search($search->query, $search->ownedby, $search->copyableby, $search->limit, $search->offset, true);
$results = self::view_search($search->query, $search->ownerquery, null, $search->copyableby, $search->limit, $search->offset, true);
foreach ($results->data as &$r) {
$r['form'] = pieform(create_view_form($search->copyableby->group, $search->copyableby->institution, $r['id']));
......@@ -2022,6 +2005,9 @@ class View {
if (!empty($search->query)) {
$params[] = 'viewquery=' . $search->query;
}
if (!empty($search->ownerquery)) {
$params[] = 'ownerquery=' . $search->query;
}
if (!empty($search->group)) {
$params[] = 'group=' . $search->group;
}
......@@ -2032,24 +2018,6 @@ class View {
$smarty = smarty_core();
$smarty->assign_by_ref('results', $results->data);
if ($search->ownedby) {
foreach ($search->ownedby as $k => $v) {
$params[] = 'owntype=' . $k;
$params[] = 'ownid=' . $v;
if ($k == 'user') {
$ownername = display_name($v);
} else if ($k == 'group') {
$ownername = get_field('group', 'name', 'id', $v);
} else if ($k == 'institution') {
if ($v == 'mahara') {
$ownername = get_config('sitename');
} else {
$ownername = get_field('institution', 'displayname', 'name', $v);
}
}
}
$smarty->assign('ownername', get_string('viewsby', 'view', $ownername));
}
$search->html = $smarty->fetch('view/templatesearchresults.tpl');
$search->count = $results->count;
......
......@@ -1588,29 +1588,13 @@ button#dosearch {
width: 100%;
margin-top: 5px;
}
#copyview #templatesearch {
float: left;
width: 500px;
}
#copyview #viewownersearch {
margin-top: 10px;
float: left;
margin-right: 10px;
width: 35%;
}
#copyview form.searchquery {
text-align: center;
margin-top: 10px;
}
#copyview .selectowner {
font-weight: bold;
}
#copyview #viewownersearch td img {
#copyview #templatesearch td img {
vertical-align: bottom;
}
#copyview #viewownersearch td.selectowner img {
vertical-align: middle;
}
.preview-group {
margin: 10px;
}
......@@ -1626,16 +1610,12 @@ button#dosearch {
border: 1px solid #ccc;
padding: 5px;
}
#viewpreviewclose,
#closeviewownersearch {
#viewpreviewclose {
width: 100%;
text-align: center;
border-bottom: 1px solid #ccc;
padding-bottom: 5px;
}
#closeviewownersearch {
margin-bottom: 5px;
}
#viewpreviewcontent {
margin-top: 5px;
}
......
......@@ -4,35 +4,23 @@
<h2>{$heading}</h2>
<div id="copyview">
<div id="viewownersearch" class="searchlist">
<div id="viewownersearchinner">
<div id="closeviewownersearch" class="hidden"> <a href="">Close</a></div>
<h4>{str tag="searchviewsbyowner" section="view"}</h4>
<form class="searchquery" action="{$WWWROOT}view/choosetemplate.php" method="post">
<label>{str tag="name"}:
<input type="text" name="ownerquery" id="ownerquery" class="query" value="{$owners->query|escape}">
</label>
<button class="query-button" type="submit">{str tag="go"}</button>
<input type="hidden" name="ownerlimit" value="{$owners->limit|escape}">
<input type="hidden" name="owneroffset" value="0">
</form>
<div id="viewownersearch_table">{$owners->html}</div>
<div id="viewownersearch_pagination">{$owners->pagination.html}</div>
</div>
</div>
<div id="templatesearch" class="searchlist">
<h3>{str tag="selectaviewtocopy" section="view"}</h3>
<form class="searchquery" action="{$WWWROOT}view/choosetemplate.php" method="post">
<label>{str tag="searchviews" section="view"}:
<input type="text" name="viewquery" id="viewquery" class="query" value="{$views->query|escape}">
</label>
<button class="query-button" type="submit">{str tag="go"}</button>
<input type="hidden" name="viewlimit" value="{$views->limit|escape}">
<input type="hidden" name="viewoffset" value="0">
<span id="openviewownersearch" class="hidden">
<a href="">{str tag="searchowners" section="view"}</a>
</span>
<label>{str tag="searchowners" section="view"}:
<input type="text" name="ownerquery" id="ownerquery" class="query" value="{$owners->query|escape}">
</label>
<button class="query-button" type="submit">{str tag="go"}</button>
</form>
<div id="templatesearch_table">{$views->html}</div>
<div id="templatesearch_pagination">{$views->pagination.html}</div>
......
<table class="templateresults tablerenderer">
<thead>
{if ($ownername)}
<tr><th colspan="3">{$ownername}</th></tr>
{else}
<tr>
<th>{str tag=name}</th>
<th>{str tag=Owner section=view}</th>
<th></th>
</tr>
{/if}
</thead>
<tbody>
{if !empty($results)}
{foreach from=$results item=row}
<tr class="r{cycle values=0,1}">
<td{if ($ownername)} colspan="2"{/if}>
<td>
<a class="viewlink" href="{$WWWROOT}view/view.php?id={$row.id|escape}" target="_blank">{$row.title|escape}</a>
</td>
{if (!$ownername)}
{if $row.institution}
<td>{$row.sharedby|escape}</td>
{elseif $row.group}
<td><a class="grouplink" href="{$WWWROOT}group/view.php?id={$row.group|escape}" target="_blank">{$row.sharedby|escape}</a></td>
{elseif $row.owner}
<td>
<img src="{$WWWROOT}thumb.php?type=profileicon&maxwidth=20&maxheight=20&id={$row.owner|escape}" />
<a class="userlink" href="{$WWWROOT}user/view.php?id={$row.owner|escape}" target="_blank">{$row.sharedby|escape}</a>
</td>
{else}
<td>-</td>
{/if}
<td>
{$row.form}
......
<table class="templateresults tablerenderer">
<tbody>
{if !empty($results.data)}
{foreach from=$results.data item=row}
<tr class="r{cycle values=0,1}">
{if $row->ownertype == 'institution'}
<td>{$row->display|escape}</td>
{elseif $row->ownertype == 'group'}
<td><a class="grouplink" href="{$WWWROOT}group/view.php?id={$row->id|escape}" target="_blank">{$row->display|escape}</a></td>
{else}
<td>
<img src="{$WWWROOT}thumb.php?type=profileicon&maxwidth=20&maxheight=20&id={$row->id|escape}" />
<a class="userlink" href="{$WWWROOT}user/view.php?id={$row->id|escape}" target="_blank">{$row->display|escape}</a>
</td>
{/if}
<td class="selectowner"><a href="{$viewurl}&amp;owntype={$row->ownertype}&amp;ownid={$row->id}">{str tag=listviews section=view}</a>&nbsp;<img src="{theme_path location='images/icon_fieldset_left.gif'}" alt=""></td>
</tr>
{/foreach}
{else}
<tr><td colspan="2">{str tag="noownersfound" section=view}</td></tr>
{/if}
</tbody>
</table>
......@@ -46,27 +46,11 @@ if ($group && !group_user_can_edit_views($group) || $institution && !$USER->can_
define('TITLE', get_string('copyaview', 'view'));
$owners = new StdClass;
$owners->query = trim(param_variable('ownerquery', ''));
$owners->template = null;
$owners->offset = param_integer('owneroffset', 0);
$owners->limit = param_integer('ownerlimit', 10);
if ($group) {
$owners->group = $group;
}
else if ($institution) {
$owners->institution = $institution;
}
View::get_viewownersearch_data($owners);
$views = new StdClass;
$views->query = trim(param_variable('viewquery', ''));
$views->offset = param_integer('viewoffset', 0);
$views->limit = param_integer('viewlimit', 10);
$views->ownedby = null;
if ($ownertype = param_alpha('owntype', null)) {
$views->ownedby = (object) array($ownertype => param_alphanum('ownid'));
}
$views->query = trim(param_variable('viewquery', ''));
$views->ownerquery = trim(param_variable('ownerquery', ''));
$views->offset = param_integer('viewoffset', 0);
$views->limit = param_integer('viewlimit', 10);
$views->copyableby = (object) array('group' => $group, 'institution' => $institution, 'user' => null);
if ($group) {
$views->group = $group;
......@@ -86,7 +70,6 @@ $js = <<<EOF
preview = DIV({'id':'viewpreview', 'class':'hidden'}, DIV({'id':'viewpreviewinner'}, DIV({'id':'viewpreviewclose'}, A({'href':'','id':'closepreview'}, {$strclose})), DIV({'id':'viewpreviewcontent'})));
function showPreview(size, data) {
hideElement('viewownersearch');
$('viewpreviewcontent').innerHTML = data.html;
var vdim = getViewportDimensions();
var vpos = getViewportPosition();
......@@ -101,54 +84,12 @@ function showPreview(size, data) {
showElement(preview);
}
function showOwnerSearch() {
hideElement(preview);
var vpos = getViewportPosition();
var offset = 16; // Left border & padding of preview container elements (@todo: use getStyle()?)
setElementPosition('viewownersearch', {
'x':vpos.x+100-offset,
'y':vpos.y+150
});
showElement('viewownersearch');
}
ownerlist = new SearchTable('viewownersearch');
templatelist = new SearchTable('templatesearch');
addLoadEvent(function() {
hideElement('viewownersearch');
showElement('closeviewownersearch');
setStyle('viewownersearch', {
'position': 'absolute',
'background': '#fff',
'width': '500px',
'border': '10px solid #eee',
'padding': '0'
});
setStyle('viewownersearchinner', {
'border': '1px solid #ccc',
'padding': '5px'
});
setStyle('templatesearch', {'width':'auto'});
ownerlist.rewriteOther = function () {
forEach(getElementsByTagAndClassName('td', 'selectowner', 'viewownersearch'), function(i) {
disconnectAll(i);
connect(i, 'onclick', function (e) {
e.stop();
var children = getElementsByTagAndClassName('a', null, this);
if (children.length == 1) {
var href = getNodeAttribute(children[0], 'href');
templatelist.params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
templatelist.params.viewlimit = {$views->limit};
templatelist.params.viewoffset = 0;
templatelist.doSearch();
}
hideElement('viewownersearch');
});
});
forEach(getElementsByTagAndClassName('a', 'grouplink', 'viewownersearch'), function(i) {
templatelist.rewriteOther = function () {
forEach(getElementsByTagAndClassName('a', 'grouplink', 'templatesearch'), function(i) {
connect(i, 'onclick', function (e) {
e.stop();
var href = getNodeAttribute(this, 'href');
......@@ -156,7 +97,7 @@ addLoadEvent(function() {
sendjsonrequest(config.wwwroot + 'group/groupinfo.json.php', params, 'POST', partial(showPreview, 'small'));
});
});
forEach(getElementsByTagAndClassName('a', 'userlink', 'viewownersearch'), function(i) {
forEach(getElementsByTagAndClassName('a', 'userlink', 'templatesearch'), function(i) {
connect(i, 'onclick', function (e) {
e.stop();
var href = getNodeAttribute(this, 'href');
......@@ -164,9 +105,6 @@ addLoadEvent(function() {
sendjsonrequest(config.wwwroot + 'user/userdetail.json.php', params, 'POST', partial(showPreview, 'small'));
});
});
};
ownerlist.rewriteOther();
templatelist.rewriteOther = function () {
forEach(getElementsByTagAndClassName('a', 'viewlink', 'templatesearch'), function(i) {
disconnectAll(i);
setNodeAttribute(i, 'title', {$strpreview});
......@@ -178,6 +116,7 @@ addLoadEvent(function() {
});
});
};
templatelist.rewriteOther();
appendChildNodes(getFirstElementByTagAndClassName('body'), preview);
......@@ -185,10 +124,6 @@ addLoadEvent(function() {
connect('closepreview', 'onclick', function (e) {e.stop(); fade(preview, {'duration':0.2});});
connect('viewpreviewcontent', 'onclick', function (e) {e.stop(); return false;});
setStyle('openviewownersearch', {'display': 'inline'});
connect('openviewownersearch', 'onclick', function (e) {e.stop(); showOwnerSearch();});
connect('closeviewownersearch', 'onclick', function (e) {e.stop(); fade('viewownersearch', {'duration':0.2});});
});
EOF;
......@@ -200,7 +135,6 @@ $smarty = smarty(
);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('heading', TITLE);
$smarty->assign('owners', $owners);
$smarty->assign('views', $views);
$smarty->display('view/choosetemplate.tpl');
......
......@@ -56,7 +56,7 @@ if ($can_edit) {
$data = View::get_myviews_data($limit, $offset, $group->id);
}
else {
$data = View::view_search(null, (object) array('group' => $group->id), null, $limit, $offset);
$data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset);
}
$userid = $USER->get('id');
......
......@@ -34,14 +34,11 @@ $institution = param_alphanum('institution', null);
$views = new StdClass;
$views->query = trim(param_variable('viewquery', ''));
$views->ownerquery = trim(param_variable('ownerquery', ''));
$views->offset = param_integer('viewoffset', 0);
$views->limit = param_integer('viewlimit', 10);
$views->group = param_integer('group', null);
$views->institution = param_alphanum('institution', null);
$views->ownedby = null;
if ($ownertype = param_alpha('owntype', null)) {
$views->ownedby = (object) array($ownertype => param_alphanum('ownid'));
}
$views->copyableby = (object) array('group' => $group, 'institution' => $institution);
if (!($group || $institution)) {
$views->copyableby->user = $USER->get('id');
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
$owners = new StdClass;
$owners->query = trim(param_variable('ownerquery', ''));
$owners->template = null;
$owners->offset = param_integer('owneroffset', 0);
$owners->limit = param_integer('ownerlimit', 10);
$owners->group = param_integer('group', null);
$owners->institution = param_alphanum('institution', null);
View::get_viewownersearch_data($owners);
json_reply(false, array(
'message' => null,
'data' => array(
'table' => $owners->html,
'pagination' => $owners->pagination['html'],
'count' => $owners->count,
)
));
?>
Supports Markdown
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