/**
* Given a list of tags, finds blocks by the current user that contain those tags
* (Used to determine which ones to check for the view_artefact table)
* @param array $tags
* @return array
*/
public static function find_matching_blocks(array $tags)
{
global $USER;
$taggedblockids = (array) get_column_sql('SELECT bi.id as block
FROM
{blocktype_taggedposts_tags} btt
INNER JOIN {block_instance} bi
ON btt.block_instance = bi.id
INNER JOIN {view} v
ON bi.view = v.id
WHERE
v.owner = ?
AND btt.tagtype = ?
AND btt.tag IN (' . implode(',', db_array_to_ph($tags)) . ')
', array_merge(array($USER->id, PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE), $tags));
if ($taggedblockids) {
return $taggedblockids;
} else {
return array();
}
}
开发者ID:vohung96,项目名称:mahara,代码行数:27,代码来源:lib.php
示例4: dump_export_data
public function dump_export_data()
{
if ($this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_VIEWS && $this->exporter->get('artefactexportmode') == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS) {
// Dont' care about resume in this case
return;
}
$smarty = $this->exporter->get_smarty('../../', 'resume');
$smarty->assign('page_heading', get_string('resumeofuser', 'artefact.resume', full_name($this->exporter->get('user'))));
$smarty->assign('breadcrumbs', array(array('text' => get_string('resume', 'artefact.resume'), 'path' => 'index.html')));
if ($artefacts = get_column_sql("SELECT id\n FROM {artefact}\n WHERE owner = ?\n AND artefacttype IN\n (SELECT name FROM {artefact_installed_type} WHERE plugin = 'resume')", array($this->exporter->get('user')->get('id')))) {
foreach ($artefacts as $id) {
$artefact = artefact_instance_from_id($id);
$rendered = $artefact->render_self(array());
$smarty->assign($artefact->get('artefacttype'), $rendered['html']);
}
}
$content = $smarty->fetch('export:html/resume:index.tpl');
if (false === file_put_contents($this->fileroot . 'index.html', $content)) {
throw new SystemException("Unable to create index.html for resume");
}
}
开发者ID:Br3nda,项目名称:mahara,代码行数:21,代码来源:lib.php
示例5: get_annotation_feedback
/**
* Generates the data object required for displaying annotations on the page.
*
* @param object $options Object of annotation options
* - defaults can be retrieved from get_annotation_feedback_options()
* @return object $result Annotation data object
*/
public static function get_annotation_feedback($options)
{
global $USER;
// set the object's key/val pairs as variables
foreach ($options as $key => $option) {
${$key} = $option;
}
$userid = $USER->get('id');
$canedit = false;
if (!empty($artefact)) {
// This is the artefact that the annotation is linked to.
$artefactobj = artefact_instance_from_id($artefact);
$canedit = $USER->can_edit_artefact($artefactobj);
$owner = $artefactobj->get('owner');
$isowner = $userid && $userid == $owner;
$view = null;
} else {
if (!empty($view)) {
// This is the view that the annotation is linked to.
$viewobj = new View($view);
$canedit = $USER->can_moderate_view($viewobj);
$owner = $viewobj->get('owner');
$isowner = $userid && $userid == $owner;
$artefact = null;
}
}
$result = (object) array('limit' => $limit, 'offset' => $offset, 'annotation' => $annotation, 'view' => $view, 'artefact' => $artefact, 'block' => $block, 'canedit' => $canedit, 'owner' => $owner, 'isowner' => $isowner, 'export' => $export, 'sort' => $sort, 'data' => array());
$wherearray = array();
$wherearray[] = 'a.id = ' . (int) $annotation;
// if artefact and view are not set, this annotation is not linked to anything.
if (!empty($artefact)) {
$wherearray[] = 'an.artefact = ' . (int) $artefact;
} else {
if (!empty($view)) {
$wherearray[] = 'an.view = ' . (int) $view;
} else {
// Something is wrong. Don't show anything.
$wherearray[] = '1 = 2';
}
}
if (!$canedit) {
$wherearray[] = '(f.private = 0 OR af.author = ' . (int) $userid . ')';
}
$where = implode(' AND ', $wherearray);
$sql = 'SELECT COUNT(*)
FROM {artefact} a
INNER JOIN {artefact_annotation} an ON a.id = an.annotation
INNER JOIN {artefact_annotation_feedback} f ON an.annotation = f.onannotation
INNER JOIN {artefact} af ON f.artefact = af.id
INNER JOIN {usr} u ON a.author = u.id
LEFT JOIN {usr} uf ON af.author = uf.id
LEFT JOIN {usr_institution} uif ON uf.id = uif.usr
WHERE ' . $where;
$result->count = count_records_sql($sql);
if ($result->count > 0) {
// If pagination is in use, see if we want to get a page with particular comment
if ($limit) {
if ($showcomment == 'last') {
// If we have limit (pagination is used) ignore $offset and just get the last page of feedback.
$result->forceoffset = $offset = (ceil($result->count / $limit) - 1) * $limit;
} else {
if (is_numeric($showcomment)) {
// Ignore $offset and get the page that has the comment
// with id $showcomment on it.
// Fetch everything up to $showcomment to get its rank
// This will get ugly if there are 1000s of feedback.
$ids = get_column_sql('
SELECT f.artefact
FROM {artefact} a
INNER JOIN {artefact_annotation} an ON a.id = an.annotation
INNER JOIN {artefact_annotation_feedback} f ON an.annotation = f.onannotation
INNER JOIN {artefact} af ON f.artefact = af.id
INNER JOIN {usr} u ON a.author = u.id
LEFT JOIN {usr} uf ON af.author = uf.id
LEFT JOIN {usr_institution} uif ON uf.id = uif.usr
WHERE ' . $where . '
AND f.artefact <= ?
ORDER BY a.ctime', array($showcomment));
$last = end($ids);
if ($last == $showcomment) {
// Add 1 because array index starts from 0 and therefore key value is offset by 1.
$rank = key($ids) + 1;
$result->forceoffset = $offset = (ceil($rank / $limit) - 1) * $limit;
$result->showcomment = $showcomment;
}
}
}
}
$sortorder = !empty($sort) && $sort == 'latest' ? 'af.ctime DESC' : 'af.ctime ASC';
$sql = 'SELECT
af.id, af.author, af.authorname, af.ctime, af.mtime, af.description, af.group,
f.private, f.deletedby, f.requestpublic, f.lastcontentupdate,
uf.username, uf.firstname, uf.lastname, uf.preferredname, uf.email, uf.staff, uf.admin,
//.........这里部分代码省略.........
开发者ID:rboyatt,项目名称:mahara,代码行数:101,代码来源:lib.php
示例6: user_joined_group
/**
* When a user joins a group, subscribe them automatically to all forums
* that should be subscribable
*
* @param array $eventdata
*/
public static function user_joined_group($event, $gm)
{
if ($forumids = get_column_sql("\n SELECT ii.id\n FROM {group} g\n LEFT JOIN {interaction_instance} ii ON g.id = ii.group\n LEFT JOIN {interaction_forum_instance_config} ific ON ific.forum = ii.id\n WHERE \"group\" = ? AND ific.field = 'autosubscribe' and ific.value = '1'", array($gm['group']))) {
db_begin();
foreach ($forumids as $forumid) {
insert_record('interaction_forum_subscription_forum', (object) array('forum' => $forumid, 'user' => $gm['member']));
}
db_commit();
}
}
开发者ID:Br3nda,项目名称:mahara,代码行数:16,代码来源:lib.php
示例7: get_new_file_title
/**
* Return a unique artefact title for a given owner & parent.
*
* Try to add digits before the filename extension: If the desired
* title contains a ".", add "." plus digits before the final ".",
* otherwise append "." and digits.
*
* @param string $desired
* @param integer $parent
* @param integer $owner
* @param integer $group
* @param string $institution
*/
public static function get_new_file_title($desired, $parent, $owner = null, $group = null, $institution = null)
{
$bits = split('\\.', $desired);
if (count($bits) > 1 && preg_match('/[^0-9]/', end($bits))) {
$start = join('.', array_slice($bits, 0, count($bits) - 1));
$end = '.' . end($bits);
} else {
$start = $desired;
$end = '';
}
$where = $parent ? "parent = {$parent}" : 'parent IS NULL';
$where .= ' AND ' . artefact_owner_sql($owner, $group, $institution);
$taken = get_column_sql("\n SELECT title FROM {artefact}\n WHERE artefacttype IN ('" . join("','", array_diff(PluginArtefactFile::get_artefact_types(), array('profileicon'))) . "')\n AND title LIKE ? || '%' || ? AND " . $where, array($start, $end));
$taken = array_flip($taken);
$i = 0;
$newname = $start . $end;
while (isset($taken[$newname])) {
$i++;
$newname = $start . '.' . $i . $end;
}
return $newname;
}
开发者ID:Br3nda,项目名称:mahara,代码行数:35,代码来源:lib.php
示例8: instance_config_form
public static function instance_config_form(BlockInstance $instance)
{
global $USER;
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
if (!empty($configdata['artefactid'])) {
$blog = $instance->get_artefact_instance($configdata['artefactid']);
}
$elements = array();
// If the blog post in this block is owned by the owner of the View,
// then the block can be configured. Otherwise, the blog post was
// copied in from another View. We won't confuse users by asking them to
// choose a blog post to put in this block, when the one that is
// currently in it isn't choosable.
//
// Note: the owner check will have to change when we do group/site
// blogs
if (empty($configdata['artefactid']) || $blog->get('owner') == $USER->get('id')) {
$publishedposts = get_column_sql('
SELECT a.id
FROM {artefact} a
INNER JOIN {artefact_blog_blogpost} p ON p.blogpost = a.id
WHERE p.published = 1 AND a.owner= ?', array($USER->get('id')));
$elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $publishedposts);
$elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost');
} else {
$elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blogpost', 'artefact.blog')) . '</div>');
}
return $elements;
}
开发者ID:agwells,项目名称:Mahara-1,代码行数:30,代码来源:lib.php
示例9: update_locked
public static function update_locked($userid)
{
if (empty($userid)) {
return;
}
$submitted = get_column_sql('
SELECT a.id
FROM {artefact} a
JOIN {view_artefact} va ON a.id = va.artefact
JOIN {view} v ON va.view = v.id
WHERE a.owner = ?
AND v.owner = ?
AND (v.submittedgroup IS NOT NULL OR v.submittedhost IS NOT NULL)', array($userid, $userid));
if ($submitted) {
$submitted = artefact_get_descendants($submitted);
if ($attachments = get_column_sql('
SELECT attachment FROM {artefact_attachment}
WHERE artefact IN (' . join(',', $submitted) . ')', array())) {
$submitted = array_merge($submitted, $attachments);
}
}
db_begin();
if (!empty($submitted)) {
$idstr = '(' . join(',', $submitted) . ')';
set_field_select('artefact', 'locked', 1, "locked = 0 AND id IN {$idstr}", array());
}
// Unlock
$select = 'locked = 1 AND "owner" = ?';
if (isset($idstr)) {
$select .= " AND NOT id IN {$idstr}";
}
set_field_select('artefact', 'locked', 0, $select, array($userid));
db_commit();
}
function xmldb_core_upgrade($oldversion = 0)
{
global $SESSION;
raise_time_limit(120);
raise_memory_limit('256M');
$status = true;
if ($oldversion < 2009022700) {
// Get rid of all blocks with position 0 caused by 'about me' block on profile views
if (count_records('block_instance', 'order', 0) && !count_records_select('block_instance', '"order" < 0')) {
if (is_mysql()) {
$ids = get_column_sql('
SELECT i.id FROM {block_instance} i
INNER JOIN (SELECT view, "column" FROM {block_instance} WHERE "order" = 0) z
ON (z.view = i.view AND z.column = i.column)');
execute_sql('UPDATE {block_instance} SET "order" = -1 * "order" WHERE id IN (' . join(',', $ids) . ')');
} else {
execute_sql('UPDATE {block_instance} SET "order" = -1 * "order" WHERE id IN (
SELECT i.id FROM {block_instance} i
INNER JOIN (SELECT view, "column" FROM {block_instance} WHERE "order" = 0) z
ON (z.view = i.view AND z.column = i.column))');
}
execute_sql('UPDATE {block_instance} SET "order" = 1 WHERE "order" = 0');
execute_sql('UPDATE {block_instance} SET "order" = -1 * ("order" - 1) WHERE "order" < 0');
}
}
if ($oldversion < 2009031000) {
reload_html_filters();
}
if ($oldversion < 2009031300) {
$table = new XMLDBTable('institution');
$expiry = new XMLDBField('expiry');
$expiry->setAttributes(XMLDB_TYPE_DATETIME);
add_field($table, $expiry);
$expirymailsent = new XMLDBField('expirymailsent');
$expirymailsent->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $expirymailsent);
$suspended = new XMLDBField('suspended');
$suspended->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $suspended);
// Insert a cron job to check for soon expiring and expired institutions
if (!record_exists('cron', 'callfunction', 'auth_handle_institution_expiries')) {
$cron = new StdClass();
$cron->callfunction = 'auth_handle_institution_expiries';
$cron->minute = '5';
$cron->hour = '9';
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
}
if ($oldversion < 2009031800) {
// Files can only attach blogpost artefacts, but we would like to be able to attach them
// to other stuff. Rename the existing attachment table artefact_blog_blogpost_file to
// artefact_file_attachment so we don't end up with many tables doing the same thing.
execute_sql("ALTER TABLE {artefact_blog_blogpost_file} RENAME TO {artefact_attachment}");
if (is_postgres()) {
// Ensure all of the indexes and constraints are renamed
execute_sql("\n ALTER TABLE {artefact_attachment} RENAME blogpost TO artefact;\n ALTER TABLE {artefact_attachment} RENAME file TO attachment;\n\n ALTER INDEX {arteblogblogfile_blofil_pk} RENAME TO {arteatta_artatt_pk};\n ALTER INDEX {arteblogblogfile_blo_ix} RENAME TO {arteatta_art_ix};\n ALTER INDEX {arteblogblogfile_fil_ix} RENAME TO {arteatta_att_ix};\n\n ALTER TABLE {artefact_attachment} DROP CONSTRAINT {arteblogblogfile_blo_fk};\n ALTER TABLE {artefact_attachment} ADD CONSTRAINT {arteatta_art_fk} FOREIGN KEY (artefact) REFERENCES {artefact}(id);\n\n ALTER TABLE {artefact_attachment} DROP CONSTRAINT {arteblogblogfile_fil_fk};\n ALTER TABLE {artefact_attachment} ADD CONSTRAINT {arteatta_att_fk} FOREIGN KEY (attachment) REFERENCES {artefact}(id);\n ");
} else {
if (is_mysql()) {
execute_sql("ALTER TABLE {artefact_attachment} DROP FOREIGN KEY {arteblogblogfile_blo_fk}");
execute_sql("ALTER TABLE {artefact_attachment} DROP INDEX {arteblogblogfile_blo_ix}");
execute_sql("ALTER TABLE {artefact_attachment} CHANGE blogpost artefact BIGINT(10) DEFAULT NULL");
execute_sql("ALTER TABLE {artefact_attachment} ADD CONSTRAINT {arteatta_art_fk} FOREIGN KEY {arteatta_art_ix} (artefact) REFERENCES {artefact}(id)");
execute_sql("ALTER TABLE {artefact_attachment} DROP FOREIGN KEY {arteblogblogfile_fil_fk}");
execute_sql("ALTER TABLE {artefact_attachment} DROP INDEX {arteblogblogfile_fil_ix}");
execute_sql("ALTER TABLE {artefact_attachment} CHANGE file attachment BIGINT(10) DEFAULT NULL");
execute_sql("ALTER TABLE {artefact_attachment} ADD CONSTRAINT {arteatta_att_fk} FOREIGN KEY {arteatta_att_ix} (attachment) REFERENCES {artefact}(id)");
}
}
// Drop the _pending table. From now on files uploaded as attachments will become artefacts
// straight away. Hopefully changes to the upload/file browser form will make it clear to
// the user that these attachments sit in his/her files area as soon as they are uploaded.
$table = new XMLDBTable('artefact_blog_blogpost_file_pending');
drop_table($table);
}
if ($oldversion < 2009040900) {
// The view access page has been putting the string 'null' in as a group role in IE.
set_field('view_access_group', 'role', null, 'role', 'null');
}
if ($oldversion < 2009040901) {
$table = new XMLDBTable('import_installed');
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, 255, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('version', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('release', XMLDB_TYPE_TEXT, 'small', XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('active', XMLDB_TYPE_INTEGER, 1, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 1);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('name'));
create_table($table);
$table = new XMLDBTable('import_cron');
$table->addFieldInfo('plugin', XMLDB_TYPE_CHAR, 255, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('callfunction', XMLDB_TYPE_CHAR, 255, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('minute', XMLDB_TYPE_CHAR, 25, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('hour', XMLDB_TYPE_CHAR, 25, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('day', XMLDB_TYPE_CHAR, 25, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('dayofweek', XMLDB_TYPE_CHAR, 25, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('month', XMLDB_TYPE_CHAR, 25, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('nextrun', XMLDB_TYPE_DATETIME, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('plugin', 'callfunction'));
$table->addKeyInfo('pluginfk', XMLDB_KEY_FOREIGN, array('plugin'), 'import_installed', array('name'));
//.........这里部分代码省略.........
function regenerateurls_submit(Pieform $form, $values)
{
global $SESSION, $USER;
require_once 'upgrade.php';
log_debug("Regenerating clean urls...");
db_begin();
// Checking duplicates one by one is too slow, so drop the index,
// generate the urlids in big chunks, remove duplicates in one hit,
// recreate the index.
// Users: set urlid based on username.
$table = new XMLDBTable('usr');
$index = new XMLDBIndex('urliduk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('urlid'));
drop_index($table, $index);
execute_sql('UPDATE {usr} SET urlid = NULL WHERE NOT urlid IS NULL');
$usrcount = count_records_select('usr', 'deleted = 0 AND id > 0');
$sql = 'SELECT id, username FROM {usr} WHERE id > ? AND deleted = 0 ORDER BY id';
$done = 0;
$lastid = 0;
$limit = 1000;
while ($records = get_records_sql_array($sql, array($lastid), 0, $limit)) {
$firstid = $lastid;
$values = array();
foreach ($records as $r) {
$r->urlid = generate_urlid($r->username, get_config('cleanurluserdefault'), 3, 30);
array_push($values, $r->id, $r->urlid);
$lastid = $r->id;
}
$updatesql = "UPDATE {usr} SET urlid = CASE id\n ";
$updatesql .= join("\n ", array_fill(0, count($records), 'WHEN ? THEN ?'));
$updatesql .= "\n ELSE NULL\n END WHERE id > ? AND id <= ? AND deleted = 0";
array_push($values, $firstid, $lastid);
execute_sql($updatesql, $values);
$done += count($records);
log_debug("Generating user urls: {$done}/{$usrcount}");
}
// Fix any duplicates created above
$dupurls = get_records_sql_array('
SELECT id, urlid
FROM {usr}
WHERE urlid IN (
SELECT urlid FROM {usr} WHERE id > 0 AND deleted = 0 GROUP BY urlid HAVING COUNT(id) > 1
)
ORDER BY urlid, id', array());
$last = null;
if ($dupurls) {
log_debug('Fixing ' . count($dupurls) . ' duplicate user urls');
$ids = array();
$values = array();
for ($i = 0; $i < count($dupurls); $i++) {
if ($dupurls[$i]->urlid != $last) {
// The first user with this name can keep it, but get all the taken urlids that are similar
// so we can check against them when appending digits below.
$taken = get_column_sql("SELECT urlid FROM {usr} WHERE urlid LIKE ?", array(substr($dupurls[$i]->urlid, 0, 24) . '%'));
} else {
// Subsequent users need digits appended, while keeping the max length at 30
$suffix = 1;
$try = substr($dupurls[$i]->urlid, 0, 28) . '-1';
while (in_array($try, $taken)) {
$suffix++;
$try = substr($dupurls[$i]->urlid, 0, 29 - strlen($suffix)) . '-' . $suffix;
}
$taken[] = $try;
$ids[] = $dupurls[$i]->id;
array_push($values, $dupurls[$i]->id, $try);
}
$last = $dupurls[$i]->urlid;
}
$updatesql = "UPDATE {usr} SET urlid = CASE id\n ";
$updatesql .= join("\n ", array_fill(0, count($values) / 2, 'WHEN ? THEN ?'));
$updatesql .= "\n ELSE urlid\n END\n WHERE id IN (";
$updatesql .= join(',', array_fill(0, count($ids), '?'));
$updatesql .= ')';
$values = array_merge($values, $ids);
execute_sql($updatesql, $values);
}
$table = new XMLDBTable('usr');
$index = new XMLDBIndex('urliduk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('urlid'));
add_index($table, $index);
// Groups: set urlid based on group name
execute_sql('UPDATE {group} SET urlid = NULL');
$table = new XMLDBTable('group');
$index = new XMLDBIndex('urliduk');
$index->setAttributes(XMLDB_INDEX_UNIQUE, array('urlid'));
drop_index($table, $index);
// Transliteration using iconv is bad if locale is set to C, so set it based on
// the site language.
$lang = $sitelang = get_config('lang');
set_locale_for_language($lang);
$groupcount = count_records('group', 'deleted', 0);
$sql = 'SELECT id, name FROM {group} WHERE deleted = 0 AND id > ? ORDER BY id';
$done = 0;
$lastid = 0;
$limit = 1000;
while ($records = get_records_sql_array($sql, array($lastid), 0, $limit)) {
$firstid = $lastid;
$values = array();
foreach ($records as $r) {
$r->urlid = generate_urlid($r->name, get_config('cleanurlgroupdefault'), 3, 30);
//.........这里部分代码省略.........
public static function instance_config_form(BlockInstance $instance)
{
global $USER;
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
require_once get_config('libroot') . 'view.php';
$view = new View($instance->get('view'));
$institution = $view->get('institution');
$group = $view->get('group');
if (!empty($configdata['artefactid'])) {
$blog = $instance->get_artefact_instance($configdata['artefactid']);
}
$elements = array();
// If the blog in this block is owned by the owner of the View, then
// the block can be configured. Otherwise, the blog was copied in from
// another View. We won't confuse users by asking them to choose a blog
// to put in this block, when the one that is currently in it isn't
// choosable.
//
// Note: the owner check will have to change when we do group/site
// blogs
if (empty($configdata['artefactid']) || ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) {
$where = array('blog');
$sql = "SELECT a.id FROM {artefact} a\n WHERE a.artefacttype = ?";
if ($institution) {
$sql .= " AND a.institution = ?";
$where[] = $institution;
} else {
if ($group) {
$sql .= " AND a.group = ?";
$where[] = $group;
} else {
$sql .= " AND a.owner = ?";
$where[] = $USER->get('id');
}
}
$blogids = get_column_sql($sql, $where);
$elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $blogids);
$elements['count'] = array('type' => 'text', 'title' => get_string('postsperpage', 'blocktype.blog/blog'), 'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 5, 'size' => 3);
$elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blog');
} else {
$elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('Blog', 'artefact.blog')) . '</div>');
}
return $elements;
}
$deleteunread++;
}
}
}
db_begin();
$countdeleted = 0;
foreach ($rawids as $table => $idspertable) {
if ('artefact_multirecipient_notification' === $table) {
delete_messages_mr($idspertable, $USER->get('id'));
} else {
if ('notification_internal_activity' === $table) {
$userid = $USER->get('id');
// Ignore message ids that do not belong to the current user to stop
// hacking of the form allowing the deletion of messages owned by other users.
$rawstrids = join(',', array_map('db_quote', $idspertable));
$ids = get_column_sql("SELECT id FROM {notification_internal_activity}\n WHERE id IN ({$rawstrids}) AND usr = ?", array($userid));
if ($ids) {
$strids = join(',', $ids);
// Remove parent pointers to messages we're about to delete
execute_sql("\n UPDATE {notification_internal_activity}\n SET parent = NULL\n WHERE parent IN ({$strids})");
delete_records_select('notification_internal_activity', "id IN ({$strids})");
if ($deleteunread) {
$newunread = $USER->add_unread(-1 * $deleteunread);
}
}
}
}
$countdeleted += $ids ? count($ids) : count($idspertable);
}
db_commit();
$message = get_string('deletednotifications1', 'activity', $countdeleted);
/**
* Update or create a favourites list for a user
*
* @param $owner integer owner of the favorites list
* @param $shortname string name for the favorites list
* @param $institution string institution with permission to update the favorites list
* @param $userlist array array of userids to add to the list
*/
function update_favorites($owner, $shortname, $institution, $userlist)
{
global $USER;
if (empty($institution)) {
// User-editable favorites lists are not implemented yet.
return;
}
if (!$USER->can_edit_institution($institution)) {
throw new AccessDeniedException("update_favorites: access denied");
}
$owner = (int) $owner;
if ($institution == 'mahara') {
if (!record_exists('usr', 'id', $owner, 'deleted', 0)) {
throw new NotFoundException("update_favorites: user {$owner} not found");
}
} else {
$sql = '
SELECT u.id
FROM {usr} u JOIN {usr_institution} ui ON u.id = ui.usr AND ui.institution = ?
WHERE u.id = ? AND u.deleted = 0';
if (!record_exists_sql($sql, array($institution, $owner))) {
throw new NotFoundException("update_favorites: user {$owner} not found in institution {$institution}");
}
}
$listdata = get_record('favorite', 'owner', $owner, 'shortname', $shortname);
if ($listdata && $listdata->institution != $institution) {
throw new AccessDeniedException("update_favorites: user {$owner} already has a favorites list called {$shortname} which is updated by another institution");
}
if (!is_array($userlist)) {
throw new SystemException("update_favorites: userlist is not an array");
}
if (!empty($userlist)) {
$userids = get_column_sql('
SELECT id FROM {usr} WHERE id IN (' . join(',', array_fill(0, count($userlist), '?')) . ') AND deleted = 0', array_map('intval', $userlist));
}
if (empty($userids)) {
$userids = array();
}
db_begin();
$now = db_format_timestamp(time());
if ($listdata) {
delete_records('favorite_usr', 'favorite', $listdata->id);
$listdata->mtime = $now;
update_record('favorite', $listdata, 'id');
} else {
$listdata = (object) array('owner' => $owner, 'shortname' => $shortname, 'institution' => $institution, 'ctime' => $now, 'mtime' => $now);
$listdata->id = insert_record('favorite', $listdata, 'id', true);
}
foreach ($userids as $userid) {
insert_record('favorite_usr', (object) array('favorite' => $listdata->id, 'usr' => $userid));
}
db_commit();
}
请发表评论