Commit 0fccf160 authored by Penny Leach's avatar Penny Leach
Browse files
parents b2429d45 35428021
......@@ -31,12 +31,13 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$stopmonitoring = param_integer('stopmonitoring', 0);
$userlist = param_alpha('userlist', null);
$getartefacts = param_integer('getartefacts', 0);
$prefix = get_config('dbprefix');
$userid = $USER->get('id');
if ($stopmonitoring) {
$userid = $USER->get('id');
$count = 0;
db_begin();
try {
......@@ -82,11 +83,44 @@ if ($stopmonitoring) {
echo json_encode($data);
exit;
}
if (!empty($userlist)) {
if ($userlist == 'views') {
$sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?';
if (!$users = get_records_sql_array($sql, array($userid))) {
$users = array();
}
}
else if ($userlist == 'artefacts') {
$sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'artefact a ON a.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?';
if (!$users = get_records_sql_array($sql, array($userid))) {
$users = array();
}
}
else {
$users = array();
}
$data = array();
foreach ($users as $u) {
$data[] = array('id' => $u->id, 'name' => display_name($u, $USER));
}
json_reply(false, array('users' => $data));
}
// normal processing
// normal processing (fetching tablerenderer results)
$type = param_alpha('type', 'views');
$owner = param_integer('user', null);
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
......@@ -101,9 +135,15 @@ if ($type == 'views') {
$sql = 'SELECT v.*, v.title AS name
FROM ' . $prefix . 'view v
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?
WHERE w.usr = ?';
$values = array($userid);
if (isset($owner)) {
$sql .= ' AND v.owner = ?';
$values[] = $owner;
}
$sql .= '
ORDER BY v.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
$records = get_records_sql_array($sql, $values, $offset, $limit);
}
else if ($type == 'communities') {
$count = count_records('usr_watchlist_community', 'usr', $userid);
......@@ -119,9 +159,15 @@ else if ($type == 'artefacts') {
$sql = 'SELECT a.* , a.title AS name
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?
WHERE w.usr = ?';
$values = array($userid);
if (isset($owner)) {
$sql .= ' AND a.owner = ?';
$values[] = $owner;
}
$sql .= '
ORDER BY a.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
$records = get_records_sql_array($sql, $values, $offset, $limit);
}
if (empty($records)) {
......
......@@ -34,13 +34,11 @@ $viewstring = get_string('views', 'activity');
$communitystring = get_string('communities', 'activity');
$artefactstring = get_string('artefacts', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$allusersstring = get_string('allusers');
$savefailed = get_string('stopmonitoringfailed', 'activity');
$savesuccess = get_string('stopmonitoringsuccess', 'activity');
$getartefactsjson = get_config('wwwroot') . 'json/getartefacts.php';
$recursestr = '[<a href="" onClick="toggleChecked(\'tocheck-r\'); return false;">'
. get_string('recurseall', 'activity')
. '</a>]';
......@@ -116,24 +114,71 @@ function stopmonitoring(form) {
)
}
function typeChange(element) {
watchlist.doupdate({'type': element.options[element.selectedIndex].value});
changeTitle(element.options[element.selectedIndex].value);
function statusChange() {
var typevalue = $('type').options[$('type').selectedIndex].value;
var uservalue;
if ($('user').disabled == true) {
uservalue = undefined;
}
else {
uservalue = getNodeAttribute($('user').options[$('user').selectedIndex], 'value');
}
if (uservalue) {
watchlist.doupdate({'type': typevalue, 'user': uservalue});
}
else {
watchlist.doupdate({'type': typevalue});
}
changeTitle(typevalue);
$('messagediv').innerHTML = '';
if (element.options[element.selectedIndex].value == 'communities') {
if (typevalue == 'communities') {
$('recurseheader').innerHTML = '';
$('user').options.length = 0;
$('user').disabled = true;
}
else {
$('recurseheader').innerHTML = '{$recursestrjs}';
var pd = {'userlist': typevalue};
var d = loadJSONDoc('index.json.php', pd);
d.addCallbacks(function (data) {
var userSelect = $('user');
var newOptions = new Array()
var opt = OPTION(null, '{$allusersstring}');
if (!uservalue) {
opt.selected = true;
}
newOptions.push(opt);
forEach (data.message.users, function (u) {
var opt = OPTION({'value': u.id}, u.name);
if (uservalue == u.id) {
opt.selected = true;
}
newOptions.push(opt);
});
userSelect.disabled = false;
replaceChildNodes(userSelect, newOptions);
});
}
}
JAVASCRIPT;
$prefix = get_config('prefix');
$sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?';
if (!$viewusers = get_records_sql_array($sql, array($USER->get('id')))) {
$viewusers = array();
}
$smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('typechange', 'typeChange(this);');
$smarty->assign('viewusers', $viewusers);
$smarty->assign('typestr', get_string('views', 'activity'));
$smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;');
$smarty->assign('recursestr', $recursestr);
......
......@@ -193,7 +193,7 @@ function edititem(item) {
var menuitem = $('menuitem_'+item.id);
addElementClass(menuitem,'invisible');
var newrow = editform(item);
menuitem.parentNode.insertBefore(newrow,menuitem);
insertSiblingNodesBefore(menuitem, newrow);
}
// Receive standard json error message
......
......@@ -76,7 +76,7 @@ foreach (plugin_types() as $plugin) {
continue;
}
$plugins[$plugin]['notinstalled'][$dir] = array();
safe_require($plugin, $dir);
require_once('artefact.php');
$funname = $plugin . '_check_plugin_sanity';
if (function_exists($funname)) {
try {
......
......@@ -46,7 +46,7 @@ class PluginArtefactBlog extends PluginArtefact {
return array(
array(
'name' => 'myblogs',
'link' => 'blogs/',
'link' => 'list/',
)
);
}
......@@ -61,13 +61,35 @@ class PluginArtefactBlog extends PluginArtefact {
*/
class ArtefactTypeBlog extends ArtefactType {
/**
* This constant gives the per-page pagination for listing blogs.
*/
const pagination = 10;
/**
* Just the basic commit.
*/
public function commit() {
$this->commit_basic();
}
/**
* Just the basic delete. FIXME - needs to delete posts too.
*/
public function delete() {
$this->delete_basic();
}
/**
* FIXME - Not sure about this. It is copied entirely from
* ArtefactTypeProfile
*/
public function render($format, $options) {
if ($format == ARTEFACT_FORMAT_LISTITEM && $this->title) {
return $this->title;
}
return false;
}
public function get_icon() {
......@@ -76,10 +98,42 @@ class ArtefactTypeBlog extends ArtefactType {
public static function get_render_list() {
}
public static function can_render_to($format) {
public static function collapse_config() {
}
public static function collapse_config() {
/**
* This function returns a list of the given user's blogs.
*
* @param User
* @return array (count: integer, data: array)
*/
public static function get_blog_list(User $user, $limit = self::pagination, $offset = 0) {
($result = get_records_sql_array("
SELECT id, title, description
FROM " . get_config('dbprefix') . "artefact
WHERE owner = ?
AND artefacttype = 'blog'
ORDER BY title
LIMIT ? OFFSET ?", array($user->get('id'), $limit, $offset)))
|| ($result = array());
$count = (int)get_field('artefact', 'COUNT(*)', 'owner', $user->get('id'), 'artefacttype', 'blog');
return array($count, $result);
}
/**
* This function creates a new blog.
*
* @param User
* @param array
*/
public static function new_blog(User $user, $values) {
$artefact = new ArtefactTypeBlog();
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$artefact->set('owner', $user->get('id'));
$artefact->commit();
}
}
......@@ -88,7 +142,14 @@ class ArtefactTypeBlog extends ArtefactType {
*/
class ArtefactTypeBlogPost extends ArtefactType {
/**
* This gives the number of blog posts to display at a time.
*/
const pagination = 10;
public function commit() {
$this->commit_basic();
}
public function delete() {
......@@ -103,9 +164,50 @@ class ArtefactTypeBlogPost extends ArtefactType {
public static function get_render_list() {
}
public static function can_render_to($format) {
public static function collapse_config() {
}
public static function collapse_config() {
/**
* This function returns a list of the current user's blog posts, for the
* given blog.
*
* @param User
* @param integer
* @param integer
*/
public static function get_posts(User $user, $id, $limit = self::pagination, $offset = 0) {
($result = get_records_sql_array("
SELECT id, title, description, ctime, mtime
FROM " . get_config('dbprefix') . "artefact
WHERE parent = ?
AND artefacttype = 'blogpost'
AND owner = ?
ORDER BY ctime DESC
LIMIT ? OFFSET ?;", array(
$id,
$user->get('id'),
$limit,
$offset
)))
|| ($result = array());
$count = (int)get_field('artefact', 'COUNT(*)', 'owner', $user->get('id'), 'artefacttype', 'blogpost', 'parent', $id);
return array($count, $result);
}
/**
* This function creates a new blog post.
*
* @param User
* @param array
*/
public static function new_post(User $user, array $values) {
$artefact = new ArtefactTypeBlogPost();
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$artefact->set('owner', $user->get('id'));
$artefact->set('parent', $values['id']);
$artefact->commit();
}
}
<?php
/**
* This program is part of Mahara
*
......@@ -17,8 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Penny Leach <penny@catalyst.net.nz>
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
......@@ -26,65 +27,21 @@
define('INTERNAL', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require('view.php');
$view = param_integer('view');
$artefact = param_integer('artefact', 0);
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 10);
$watchlist = param_integer('watchlist', 0);
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
safe_require('artefact', 'blog');
json_headers();
// @todo permissions check here
$data = array(
'count' => 0,
'offset' => $offset,
'limit' => $limit,
'view' => $view,
'artefact' => $artefact,
);
$limit = param_integer('limit', ArtefactTypeBlog::pagination);
$offset = param_integer('offset', 0);
list($count, $data) = ArtefactTypeBlog::get_blog_list($USER, $limit, $offset);
if (!empty($artefact)) {
try {
$a = artefact_instance_from_id($artefact);
if (!empty($watchlist)) {
$children = $a->get_children_metadata_watchlist($USER->id);
}
else {
$children = $a->get_children_metadata();
}
if (empty($children)) {
$children = array();
}
$data['data'] = array_values($children);
$data['count'] = count($children);
}
catch (Exception $e) {
json_reply(true, $e->getMessage());
}
}
else {
try {
$v = new View($view);
if (!empty($watchlist)) {
$artefacts = $v->get_artefact_metadata_watchlist($USER->id);
}
else {
$artefacts = $v->get_artefact_metadata();
}
if (empty($artefacts)) {
$artefacts = array();
}
$data['data'] = array_values($artefacts);
$data['count'] = count($artefacts);
}
catch (Exception $e) {
json_reply(true, $e->getMessage());
}
}
echo json_encode($data);
exit;
echo json_encode(array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data
));
?>
\ No newline at end of file
?>
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-blog
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'myblogs');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
safe_require('artefact', 'blog');
// This is the wwwroot.
$wwwroot = get_config('wwwroot');
// This JavaScript creates a table to display the blog entries.
$js = <<<EOJAVASCRIPT
var bloglist = new TableRenderer(
'bloglist',
'index.json.php',
[
function(r) {
return TD(
null,
A({'href':'{$wwwroot}/artefact/blog/view/?id=' + r.id}, r.title)
);
},
'description'
]
);
bloglist.updateOnLoad();
EOJAVASCRIPT;
$smarty = smarty(array('tablerenderer'));
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
$smarty->assign_by_ref('blogs', $blogs);
$smarty->display('artefact:blog:list.tpl');
?>
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage artefact-internal
* @author Alastair Pharo <alastair@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'myblogs');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'blog');
$form = pieform(array(
'name' => 'newblog',
'method' => 'post',
'action' => '',
'elements' => array(
'title' => array(
'type' => 'text',
'title' => get_string('blogtitle', 'artefact.blog'),
'description' => get_string('blogtitledesc', 'artefact.blog'),
'rules' => array(
'required' => true
)
),
'description' => array(
'type' => 'textarea',
'rows' => 10,
'cols' => 80,
'title' => get_string('blogdesc', 'artefact.blog'),
'description' => get_string('blogdescdesc', 'artefact.blog'),
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('newblog', 'artefact.blog')
)
)
));
$smarty =& smarty();
$smarty->assign_by_ref('newblogform', $form);
$smarty->display('artefact:blog:new.tpl');
exit;
/**
* This function gets called to submit the new blog.
*
* @param array
*/
function newblog_submit($values) {
global $USER;
ArtefactTypeBlog::new_blog($USER, $values);
redirect(get_config('wwwroot') . '/artefact/blog/list/');
}
?>
<?php
/**
* This program is part of Mahara
*
* 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 2 of the License, or
* (at your option) any later version.
*