Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
1bf518aa
Commit
1bf518aa
authored
Aug 26, 2009
by
Richard Mansfield
Browse files
Initial commit for tag sideblock/search
parent
39171a79
Changes
11
Hide whitespace changes
Inline
Side-by-side
htdocs/json/tagsearch.php
0 → 100644
View file @
1bf518aa
<?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
(
'searchlib.php'
);
$tag
=
param_variable
(
'tag'
);
$offset
=
param_integer
(
'offset'
,
0
);
$limit
=
param_integer
(
'limit'
,
10
);
$owner
=
(
object
)
array
(
'type'
=>
'user'
,
'id'
=>
$USER
->
get
(
'id'
));
$data
=
get_portfolio_items_by_tag
(
$tag
,
$owner
,
$limit
,
$offset
);
build_portfolio_search_html
(
$data
);
json_reply
(
false
,
array
(
'data'
=>
$data
));
?>
htdocs/lang/en.utf8/mahara.php
View file @
1bf518aa
...
...
@@ -84,6 +84,9 @@ $string['tags'] = 'Tags';
$string
[
'tagsdesc'
]
=
'Enter comma separated tags for this item.'
;
$string
[
'tagsdescprofile'
]
=
'Enter comma separated tags for this item. Items tagged with \'profile\' are displayed in your sidebar.'
;
$string
[
'youhavenottaggedanythingyet'
]
=
'You have not tagged anything yet'
;
$string
[
'mytags'
]
=
'My Tags'
;
$string
[
'Tag'
]
=
'Tag'
;
$string
[
'itemstaggedwith'
]
=
'Items tagged with "%s"'
;
$string
[
'selfsearch'
]
=
'Search My Portfolio'
;
...
...
htdocs/lib/mahara.php
View file @
1bf518aa
...
...
@@ -2033,6 +2033,30 @@ function onlineusers_sideblock() {
);
}
function
mytags_sideblock
()
{
global
$USER
;
$id
=
$USER
->
get
(
'id'
);
$tags
=
get_records_sql_array
(
"
SELECT
t.tag, COUNT(t.tag)
FROM (
(SELECT at.tag, a.id, 'artefact' AS type
FROM
{
artefact_tag
}
at JOIN
{
artefact
}
a ON a.id = at.artefact
WHERE a.owner = ?)
UNION
(SELECT vt.tag, v.id, 'view' AS type
FROM
{
view_tag
}
vt JOIN
{
view
}
v ON v.id = vt.view
WHERE v.owner = ?)
) t
GROUP BY t.tag
ORDER BY COUNT(t.tag) DESC
LIMIT 10"
,
array
(
$id
,
$id
)
);
return
array
(
'tags'
=>
$tags
);
}
/**
* Cronjob to recalculate how much quota each user is using and update it as
* appropriate.
...
...
@@ -2098,4 +2122,40 @@ function random_string($length=15) {
return
$string
;
}
function
build_portfolio_search_html
(
&
$data
)
{
$artefacttypes
=
get_records_assoc
(
'artefact_installed_type'
);
foreach
(
$data
->
data
as
&
$item
)
{
$item
->
ctime
=
format_date
(
$item
->
ctime
);
if
(
$item
->
type
==
'view'
)
{
$item
->
typestr
=
get_string
(
'view'
);
$item
->
url
=
get_config
(
'wwwroot'
)
.
'view/view.php?id='
.
$item
->
id
;
}
else
{
// artefact
safe_require
(
'artefact'
,
$artefacttypes
[
$item
->
artefacttype
]
->
plugin
);
$links
=
call_static_method
(
generate_artefact_class_name
(
$item
->
artefacttype
),
'get_links'
,
$item
->
id
);
$item
->
url
=
$links
[
'_default'
];
$item
->
icon
=
call_static_method
(
generate_artefact_class_name
(
$item
->
artefacttype
),
'get_icon'
,
array
(
'id'
=>
$item
->
id
));
$item
->
typestr
=
get_string
(
$item
->
artefacttype
,
'artefact.'
.
$artefacttypes
[
$item
->
artefacttype
]
->
plugin
);
}
}
$smarty
=
smarty_core
();
$smarty
->
assign_by_ref
(
'data'
,
$data
->
data
);
$data
->
tablerows
=
$smarty
->
fetch
(
'portfoliosearchresults.tpl'
);
$pagination
=
build_pagination
(
array
(
'id'
=>
'portfoliosearch_pagination'
,
'class'
=>
'center'
,
'url'
=>
get_config
(
'wwwroot'
)
.
'tags.php?tag='
.
urlencode
(
$data
->
tag
),
'jsonscript'
=>
'json/tagsearch.php'
,
'datatable'
=>
'results'
,
'count'
=>
$data
->
count
,
'limit'
=>
$data
->
limit
,
'offset'
=>
$data
->
offset
,
'numbersincludefirstlast'
=>
false
,
'resultcounttextsingular'
=>
get_string
(
'result'
),
'resultcounttextplural'
=>
get_string
(
'results'
),
));
$data
->
pagination
=
$pagination
[
'html'
];
$data
->
pagination_js
=
$pagination
[
'javascript'
];
}
?>
htdocs/lib/searchlib.php
View file @
1bf518aa
...
...
@@ -441,6 +441,21 @@ function search_selfsearch($query_string, $limit, $offset, $type = 'all') {
return
call_static_method
(
generate_class_name
(
'search'
,
$plugin
),
'self_search'
,
$query_string
,
$limit
,
$offset
,
$type
);
}
function
get_portfolio_items_by_tag
(
$tag
,
$owner
,
$limit
,
$offset
)
{
// For now, can only be used to search a user's portfolio
if
(
empty
(
$owner
->
id
)
||
empty
(
$owner
->
type
))
{
throw
new
SystemException
(
'get_views_and_artefacts_by_tag: invalid owner'
);
}
if
(
$owner
->
type
!=
'user'
)
{
throw
new
SystemException
(
'get_views_and_artefacts_by_tag only implemented for users'
);
}
$plugin
=
'internal'
;
safe_require
(
'search'
,
$plugin
);
return
call_static_method
(
generate_class_name
(
'search'
,
$plugin
),
'portfolio_search_by_tag'
,
$tag
,
$owner
,
$limit
,
$offset
);
}
function
get_search_plugins
()
{
$searchpluginoptions
=
array
();
...
...
htdocs/lib/web.php
View file @
1bf518aa
...
...
@@ -435,6 +435,11 @@ EOF;
'weight'
=>
0
,
'data'
=>
array
(),
);
$SIDEBLOCKS
[]
=
array
(
'name'
=>
'mytags'
,
'weight'
=>
0
,
'data'
=>
mytags_sideblock
(),
);
}
if
(
$USER
->
is_logged_in
()
&&
!
defined
(
'ADMIN'
)
&&
!
defined
(
'INSTITUTIONALADMIN'
))
{
...
...
htdocs/search/internal/lib.php
View file @
1bf518aa
...
...
@@ -836,6 +836,47 @@ class PluginSearchInternal extends PluginSearch {
}
/**
* Returns portfolio items (artefacts, views) owned by $owner and tagged
* with $tag.
*
* @param string $tag Tag
* @param object $owner: owner type (user,group,institution), and id
* @param integer $limit
* @param integer $offset
*/
public
static
function
portfolio_search_by_tag
(
$tag
,
$owner
,
$limit
,
$offset
)
{
$from
=
"FROM (
(SELECT a.id, a.title, a.description, 'artefact' AS type, a.artefacttype, "
.
db_format_tsfield
(
'a.ctime'
,
'ctime'
)
.
"
FROM
{
artefact
}
a JOIN
{
artefact_tag
}
at ON (a.id = at.artefact AND at.tag = ?)
WHERE a.owner = ?)
UNION
(SELECT v.id, v.title, v.description, 'view' AS type, NULL AS artefacttype, "
.
db_format_tsfield
(
'v.ctime'
,
'ctime'
)
.
"
FROM
{
view
}
v JOIN
{
view_tag
}
vt ON (v.id = vt.view AND vt.tag = ?)
WHERE v.owner = ?)
) p"
;
$values
=
array
(
$tag
,
$owner
->
id
,
$tag
,
$owner
->
id
);
$result
=
(
object
)
array
(
'tag'
=>
$tag
,
'owner'
=>
$owner
,
'offset'
=>
$offset
,
'limit'
=>
$limit
,
'count'
=>
0
,
'data'
=>
array
(),
);
if
(
$count
=
count_records_sql
(
'SELECT COUNT(*) '
.
$from
,
$values
,
$offset
,
$limit
))
{
$result
->
count
=
$count
;
if
(
$data
=
get_records_sql_array
(
'SELECT * '
.
$from
.
' ORDER BY p.title ASC'
,
$values
,
$offset
,
$limit
))
{
$result
->
data
=
$data
;
}
}
return
$result
;
}
/**
* Parses a query string into SQL fragments for searching. Supports
* phrases, AND/OR etc.
...
...
htdocs/tags.php
0 → 100644
View file @
1bf518aa
<?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
(
'MENUITEM'
,
'myportfolio'
);
require
(
'init.php'
);
require
(
'searchlib.php'
);
define
(
'TITLE'
,
get_string
(
'tags'
));
if
(
$tag
=
param_variable
(
'tag'
,
null
))
{
$limit
=
param_integer
(
'limit'
,
10
);
$offset
=
param_integer
(
'offset'
,
0
);
$owner
=
(
object
)
array
(
'type'
=>
'user'
,
'id'
=>
$USER
->
get
(
'id'
));
$data
=
get_portfolio_items_by_tag
(
$tag
,
$owner
,
$limit
,
$offset
);
build_portfolio_search_html
(
$data
);
}
$smarty
=
smarty
(
array
(
'paginator'
));
$smarty
->
assign
(
'PAGEHEADING'
,
hsc
(
TITLE
));
if
(
!
is_null
(
$tag
)
&&
isset
(
$data
))
{
$smarty
->
assign
(
'tag'
,
$tag
);
$smarty
->
assign_by_ref
(
'results'
,
$data
);
$smarty
->
assign
(
'INLINEJAVASCRIPT'
,
'addLoadEvent(function() {'
.
$data
->
pagination_js
.
'});'
);
}
$smarty
->
display
(
'tags.tpl'
);
?>
htdocs/theme/raw/static/style/style.css
View file @
1bf518aa
...
...
@@ -76,6 +76,9 @@ img {
font-size
:
.9em
;
font-weight
:
normal
;
}
.ctime
{
color
:
#838383
;
}
pre
,
tt
{
font-size
:
1.2em
;
white-space
:
normal
;
...
...
htdocs/theme/raw/templates/portfoliosearchresults.tpl
0 → 100644
View file @
1bf518aa
{
foreach
from
=
$data
item
=
result
}
<tr
class=
"
{
cycle
name
=
rows
values
=
r1
,
r0
}
"
>
<td
style=
"width:2em;"
>
{
if
$result
->
icon
}
<img
src=
"
{
$result
->
icon
}
"
alt=
"
{
$result
->
typestr
}
"
>
{/
if
}
</td>
<td>
<div><strong><a
href=
"
{
$result
->
url
}
"
>
{
$result
->
title
|
escape
}
</a></strong></div>
<div>
{
$result
->
description
|
str_shorten_html
:
100
}
</div>
</td>
<td
class=
"right s"
>
{
$result
->
typestr
}
<div
class=
"ctime"
>
{
$result
->
ctime
}
</div></td>
</tr>
{/
foreach
}
htdocs/theme/raw/templates/sideblocks/mytags.tpl
0 → 100644
View file @
1bf518aa
<h3>
{
str
tag
=
"mytags"
}
</h3>
<div
class=
"sidebar-content"
>
{
if
$data.tags
}
<ul>
{
foreach
from
=
$data.tags
item
=
tag
}
<li><a
href=
"
{
$WWWROOT
}
tags.php?tag=
{
$tag
->
tag
|
urlencode
}
"
>
{
$tag
->
tag
|
escape
}
</a>
(
{
$tag
->
count
}
)
</li>
{/
foreach
}
</ul>
{/
if
}
</div>
\ No newline at end of file
htdocs/theme/raw/templates/tags.tpl
0 → 100644
View file @
1bf518aa
{
include
file
=
"header.tpl"
}
{
if
empty
(
$results
->
data
)
}
<div>
{
str
tag
=
youhavenoblogs
section
=
artefact
.
blog
}
</div>
{
else
}
<h3>
{
str
tag
=
"itemstaggedwith"
arg1
=
$tag
|
escape
}
</h3>
<table
id=
"results"
class=
"tablerenderer fullwidth"
>
<thead>
<tr><th></th><th></th><th></th></tr>
</thead>
<tbody>
{
$results
->
tablerows
}
</tbody>
</table>
{
$results
->
pagination
}
{/
if
}
{
include
file
=
"footer.tpl"
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment