Commit d48edf0a authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files
parents 63bd95bd c5f78afa
......@@ -61,12 +61,22 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$userid = $USER->get('id');
$prefix = get_config('prefix');
if ($type == 'all') {
$count = count_records('notification_internal_activity', 'usr', $userid);
$records = get_records_array('notification_internal_activity', 'usr', $userid,
'ctime DESC', '*', $offset, $limit);
} else {
'ctime DESC', '*', $offset, $limit);
} else if ($type == 'adminmessages' && $USER->get('admin')) {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type IN (
SELECT name FROM ' . $prefix . 'activity_type WHERE admin = ?)',
array($userid, 1));
$records = get_records_select_array('notification_internal_activity', 'usr = ? AND type IN (
SELECT name FROM ' . $prefix . 'activity_type WHERE admin = ?)',
array($userid, 1),
'ctime DESC', '*', $offset, $limit);
}
else {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type = ?',
array($userid,$type));
$records = get_records_select_array('notification_internal_activity', 'usr = ? AND type = ?',
......
......@@ -31,6 +31,10 @@ define('SUBMENUITEM', 'activity');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$types = get_records_array('activity_type', 'admin', 0);
if ($USER->get('admin')) {
$admintypes = get_records_array('activity_type');
$types[] = (object)array('name' => 'adminmessages');
}
$readsavefail = get_string('failedtomarkasread', 'activity');
$readsave = get_string('markedasread', 'activity');
......
......@@ -182,9 +182,10 @@ if ($institution || $add) {
}
else {
// Get a list of institutions
$prefix = get_config('dbprefix');
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.authplugin, i.registerallowed, COUNT(u.*) AS hasmembers
FROM institution i
LEFT OUTER JOIN usr u ON (u.institution = i.name)
FROM ' . $prefix . 'institution i
LEFT OUTER JOIN ' . $prefix . 'usr u ON (u.institution = i.name)
GROUP BY 1, 2, 3, 4
ORDER BY i.name', array());
$smarty->assign('institutions', $institutions);
......
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20061127" COMMENT="XMLDB file for Mahara's blog-related tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<!-- This table is supposed to have a 1-1 relation with every row in the
artefact table with artefacttype = 'blog'. It contains additional
information that isn't in the artefact table. -->
<TABLE NAME="artefact_blog_blog">
<FIELDS>
<FIELD NAME="blog" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="commentsallowed" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" UNSIGNED="true" />
<FIELD NAME="commentsnotify" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" UNSIGNED="true" />
</FIELDS>
<KEYS>
<KEY NAME="blogpk" TYPE="primary" FIELDS="blog" />
<KEY NAME="blogfk" TYPE="foreign" FIELDS="blog" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<!-- This table is supposed to have a 1-1 relation with every row in the
artefact table with artefacttype = 'blogpost'. It contains additional data
that isn't in the artefact table. -->
<TABLE NAME="artefact_blog_blogpost">
<FIELDS>
<FIELD NAME="blogpost" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="published" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" UNSIGNED="true" />
</FIELDS>
<KEYS>
<KEY NAME="blogpostpk" TYPE="primary" FIELDS="blogpost" />
<KEY NAME="blogpostfk" TYPE="foreign" FIELDS="blogpost" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<!-- This table relates artefacts of type 'blogpost' to artefacts of type
'file'. This is a many-many relation. -->
<TABLE NAME="artefact_blog_blogpost_file">
<FIELDS>
<FIELD NAME="blogpost" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="file" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="blogpost_filepk" TYPE="primary" FIELDS="blogpost,file" />
<KEY NAME="blogpostfk" TYPE="foreign" FIELDS="blogpost" REFTABLE="artefact" REFFIELDS="id" />
<KEY NAME="filefk" TYPE="foreign" FIELDS="file" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
<?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
*
*/
defined('INTERNAL') || die();
function xmldb_artefact_blog_upgrade($oldversion=0) {
$status = true;
// There was no database prior to this version.
if ($oldversion < 2006120501) {
$status = $status && install_from_xmldb_file(
get_config('docroot') .
'artefact/blog/db/install.xml'
);
}
return $status;
}
?>
......@@ -66,19 +66,69 @@ class ArtefactTypeBlog extends ArtefactType {
*/
const pagination = 10;
/**
* Whether comments are allowed on this blog or not.
*/
protected $commentsallowed = false;
/**
* Whether the blog owner will be notified of comments or not.
*/
protected $commentsnotify = false;
/**
* Just the basic commit.
* This function updates or inserts the artefact. This involves putting
* some data in the artefact table (handled by parent::commit()), and then
* some data in the artefact_blog_blog table.
*/
public function commit() {
$this->commit_basic();
// Just forget the whole thing when we're clean.
if (empty($this->dirty)) {
return;
}
// We need to keep track of newness before and after.
$new = empty($this->id);
// Commit to the artefact table.
parent::commit();
// Reset dirtyness for the time being.
$this->dirty = true;
$data = array(
'blog' => $this->get('id'),
'commentsallowed' => ($this->get('commentsallowed') ? 1 : 0),
'commentsnotify' => ($this->get('commentsnotify') ? 1 : 0)
);
if ($new) {
insert_record('artefact_blog_blog', $data);
}
else {
update_record('artefact_blog_blog', $data, 'blog');
}
$this->dirty = false;
}
/**
* Just the basic delete. FIXME - needs to delete posts too.
* This function extends ArtefactType::delete() by deleting blog-specific
* data.
*/
public function delete() {
$this->delete_basic();
if (empty($this->id)) {
return;
}
log_debug('Deleting blog:'.$this->id);
// Delete the blog-specific data.
delete_records('artefact_blog_blog', 'blog', $this->id);
// Delete the artefact and all children.
parent::delete();
}
/**
......@@ -133,6 +183,8 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$artefact->set('owner', $user->get('id'));
$artefact->set('commentsallowed', $values['commentsallowed'] ? true : false);
$artefact->set('commentsnotify', $values['commentsnotify'] ? true : false);
$artefact->commit();
}
}
......@@ -146,13 +198,21 @@ class ArtefactTypeBlogPost extends ArtefactType {
* This gives the number of blog posts to display at a time.
*/
const pagination = 10;
/**
* Just the basic commit.
*/
public function commit() {
$this->commit_basic();
}
/**
* @todo
*/
public function delete() {
log_debug('Deleting blogpost:'.$this->id);
$this->delete_basic();
}
public function render($format, $options) {
......@@ -211,3 +271,5 @@ class ArtefactTypeBlogPost extends ArtefactType {
$artefact->commit();
}
}
?>
<?php
/**
* This program is part of Mahara
*
......
......@@ -51,7 +51,25 @@ $form = pieform(array(
'title' => get_string('blogdesc', 'artefact.blog'),
'description' => get_string('blogdescdesc', 'artefact.blog'),
'rules' => array(
'required' => true
'required' => false
)
),
'commentsallowed' => array(
'type' => 'radio',
'title' => get_string('commentsallowed', 'artefact.blog'),
'description' => get_string('commentsalloweddesc', 'artefact.blog'),
'options' => array(
0 => get_string('commentsallowedno', 'artefact.blog'),
1 => get_string('commentsallowedyes', 'artefact.blog')
)
),
'commentsnotify' => array(
'type' => 'radio',
'title' => get_string('commentsnotify', 'artefact.blog'),
'description' => get_string('commentsnotifydesc', 'artefact.blog'),
'options' => array(
0 => get_string('commentsnotifyno', 'artefact.blog'),
1 => get_string('commentsnotifyyes', 'artefact.blog')
)
),
'submit' => array(
......
......@@ -8,8 +8,6 @@
<div class="content">
<h2>{str section="artefact.blog" tag="newblog"}</h2>
{$newblogform}
ADD RADIO BUTTONS
</div>
{include file="footer.tpl"}
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2006112700;
$config->version = 2006120501;
$config->release = '0.1';
?>
......@@ -33,6 +33,7 @@ safe_require('artefact', 'blog');
$id = param_integer('id');
$enc_id = json_encode($id);
// This javascript is used to generate a list of blog posts.
$js = <<<EOJAVASCRIPT
var postlist = new TableRenderer(
......@@ -55,7 +56,6 @@ postlist.updateOnLoad();
EOJAVASCRIPT;
$blog = new ArtefactTypeBlog($id);
$smarty = smarty(array('tablerenderer'));
......
......@@ -70,14 +70,6 @@ class PluginArtefactFile extends PluginArtefact {
class ArtefactTypeFileBase extends ArtefactType {
public function commit() {
$this->commit_basic();
}
public function delete() {
$this->delete_basic();
}
public function render($format, $options) {
if ($format == FORMAT_ARTEFACT_LISTSELF) {
return $this->title;
......
......@@ -46,8 +46,7 @@ $filedata = get_records_sql_array('SELECT a.id, a.artefacttype, a.mtime, f.size,
FROM ' . $prefix . 'artefact a
INNER JOIN ' . $prefix . 'artefact_file_files f ON f.artefact = a.id
WHERE a.owner = ' . $userid . '
AND a.parent' . $infolder . '
ORDER BY a.artefacttype DESC', '');
AND a.parent' . $infolder, '');
if (!$filedata) {
$filedata = array();
......@@ -58,6 +57,13 @@ else {
}
}
// Sort folders before files; then use nat sort order on title.
function fileobjcmp ($a, $b) {
return strnatcasecmp(($a->artefacttype == 'folder') . $a->title,
($b->artefacttype == 'folder') . $b->title);
}
usort($filedata, "fileobjcmp");
$result = array(
'count' => count($filedata),
'limit' => $limit,
......
......@@ -2,6 +2,9 @@
{include file="adminmenu.tpl"}
<div class="content">
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span
class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str section="artefact.file" tag="myfiles"}</h2>
<div id="uploader"></div>
<div id="foldernav"></div>
......@@ -14,6 +17,9 @@
</tr></thead>
<tbody><tr><th></th></tr></tbody>
</table>
</div>
</span></span></span></span></div>
</div>
{include file="footer.tpl"}
......@@ -105,14 +105,6 @@ class ArtefactTypeProfile extends ArtefactType {
$this->artefacttype = $type;
}
public function commit() {
$this->commit_basic();
}
public function delete() {
$this->delete_basic();
}
public function render($format, $options) {
if ($format == FORMAT_ARTEFACT_LISTSELF && $this->title) {
return $this->title;
......@@ -347,13 +339,13 @@ class ArtefactTypeProfileField extends ArtefactTypeProfile {
class ArtefactTypeCachedProfileField extends ArtefactTypeProfileField {
public function commit() {
$this->commit_basic();
parent::commit();
$field = $this->get_artefact_type();
set_field('usr', $field, $this->title, 'id', $this->owner);
}
public function delete() {
$this->delete_basic();
parent::delete();
$field = $this->get_artefact_type();
set_field('usr', $field, null, 'id', $this->owner);
}
......@@ -366,7 +358,7 @@ class ArtefactTypePreferredname extends ArtefactTypeCachedProfileField {}
class ArtefactTypeEmail extends ArtefactTypeProfileField {
public function commit() {
$this->commit_basic();
parent::commit();
$email_record = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'email', $this->title);
// we've created a new artefact that doesn't have a profile email thingy.
......
......@@ -2,8 +2,14 @@
{include file="adminmenu.tpl"}
<div class="content">
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span
class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str section="artefact.internal" tag="profile"}</h2>
{$profileform}
</div>
</span></span></span></span></div>
</div>
{include file="footer.tpl"}
......@@ -98,6 +98,7 @@ abstract class ArtefactType {
protected $dirty;
protected $parentdirty;
protected $deleted = false;
protected $id;
protected $artefacttype;
protected $owner;
......@@ -306,8 +307,15 @@ abstract class ArtefactType {
/**
* Artefact destructor. Calls commit and marks the
* artefact cache as dirty if necessary.
*
* A special case is when the object has just been deleted. In this case,
* we do nothing.
*/
public function __destruct() {
if ($this->deleted) {
return;
}
if (!empty($this->dirty)) {
$this->commit();
}
......@@ -329,12 +337,11 @@ abstract class ArtefactType {
}
/**
* As commit is abstract, subclasses
* can use this as a helper to update
* the contents of the artefact table
* This method updates the contents of the artefact table only. If your
* artefact has extra information in other tables, you need to override
* this method, and call parent::commit() in your own function.
*/
protected function commit_basic() {
public function commit() {
if (empty($this->dirty)) {
return;
}
......@@ -352,38 +359,44 @@ abstract class ArtefactType {
update_record('artefact', $fordb, 'id');
}
$this->dirty = false;
$this->deleted = false;
}
/**
* Saves any changes to the database
* for basic commits, use {@link commit_basic}
* @abstract
*/
public abstract function commit();
/**
* As delete is abstract, subclasses
* can use this to clear out the artefact
* table and set the parentdirty flag
* This function provides basic delete functionality. It gets rid of the
* artefact's row in the artefact table, and the tables that reference the
* artefact table. It also recursively deletes child artefacts.
*
* If your artefact has additional data in another table, you should
* override this function, but you MUST call parent::delete() after you
* have done your own thing.
*/
public function delete() {
if (empty($this->id)) {
return;
}
// Call delete() on children (if there are any)
if ($children = $this->get_children_instances()) {
foreach ($children as $child) {
$child->delete();
}
}
protected function delete_basic() {
// Delete any references to this artefact from non-artefact places.
delete_records_select('artefact_parent_cache', 'artefact = ? OR parent = ?', array($this->id, $this->id));
delete_records('view_artefact', 'artefact', $this->id);
delete_records('usr_watchlist_artefact', 'artefact', $this->id);
// Delete the record itself.
delete_records('artefact', 'id', $this->id);
// Set flags.
$this->dirty = false;
$this->parentdirty = true;
$this->deleted = true;
}
/**
* Deletes current instance
* you MUST set $this->parentdirty to true
* when delete is called.
* for basic delete, use {@link delete_basic}
* @abstract
*/
public abstract function delete();
/**
* render instance to given format
* @param int $format format type (constant)
......
<?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 core
* @author Richard Mansfield <richard.mansfield@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);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('artefact.php');
$id = param_integer('id');
$artefact = artefact_instance_from_id($id);
$renderedartefact = $artefact->render(FORMAT_ARTEFACT_LISTSELF, null);
log_debug($renderedartefact);
if (!$renderedartefact) {
json_reply('local', 'artefactnotrendered');
}
$result = array(
'data' => $renderedartefact,
'error' => false,
'message' => 'artefactrendered',
);
json_headers();
print json_encode($result);
?>
......@@ -73,6 +73,15 @@ function handle_activity($activitytype, $data) {
if (empty($data->message)) {
throw new InvalidArgumentException("message was empty for $activitytype!");
}
if (is_string($activitytype)) {
$activitytype = get_record('activity_type', 'name', $activitytype);