Commit ada7221a authored by Richard Mansfield's avatar Richard Mansfield

Mark views as automatically created for new users/groups

parent 12d46d3e
......@@ -247,5 +247,11 @@ $string['copythisview'] = 'Copy this View';
$string['createemptyview'] = 'Create Empty View';
$string['copyaview'] = 'Copy a View';
$string['Untitled'] = 'Untitled';
$string['copyfornewusers'] = 'Copy for new users';
$string['copyfornewusersdescription'] = 'Whenever a new user is created, automatically make a personal copy of this View in the user\'s portfolio.';
$string['copyfornewmembers'] = 'Copy for new institution members';
$string['copyfornewmembersdescription'] = 'Automatically make a personal copy of this View for all new members of %s.';
$string['copyfornewgroups'] = 'Copy for new groups';
$string['copyfornewgroupsdescription'] = 'Make a copy of this view in all new groups with these Group Types:';
?>
......@@ -510,6 +510,7 @@
<FIELD NAME="numcolumns" TYPE="int" LENGTH="2" NOTNULL="true" />
<FIELD NAME="layout" TYPE="int" LENGTH="10"/>
<FIELD NAME="template" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
<FIELD NAME="copynewuser" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......@@ -530,6 +531,17 @@
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_autocreate_grouptype">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="grouptype" TYPE="char" LENGTH="20" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="view,grouptype" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="grouptypefk" TYPE="foreign" FIELDS="grouptype" REFTABLE="grouptype" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="block_instance">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
......
......@@ -1228,6 +1228,14 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql("ALTER TABLE {view} ADD COLUMN template SMALLINT NOT NULL DEFAULT 0;");
}
if ($oldversion < 2008081102) {
execute_sql("ALTER TABLE {view} ADD COLUMN copynewuser SMALLINT NOT NULL DEFAULT 0;");
execute_sql('CREATE TABLE {view_autocreate_grouptype} (
view INTEGER NOT NULL REFERENCES {view}(id),
grouptype VARCHAR(20) NOT NULL REFERENCES {grouptype}(name)
);');
}
return $status;
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008081101;
$config->version = 2008081102;
$config->release = '1.1.0alpha';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
......@@ -56,6 +56,8 @@ class View {
private $tags;
private $editingroles;
private $template;
private $copynewuser;
private $copynewgroups;
public function __construct($id=0, $data=null) {
if (!empty($id)) {
......@@ -170,6 +172,13 @@ class View {
insert_record('view_tag', (object)array( 'view' => $this->get('id'), 'tag' => $tag));
}
if (isset($this->copynewgroups)) {
delete_records('view_autocreate_grouptype', 'view', $this->get('id'));
foreach ($this->copynewgroups as $grouptype) {
insert_record('view_autocreate_grouptype', (object)array( 'view' => $this->get('id'), 'grouptype' => $grouptype));
}
}
db_commit();
$this->dirty = false;
......@@ -387,6 +396,12 @@ class View {
db_commit();
}
public function get_autocreate_grouptypes() {
if (!isset($this->copynewgroups)) {
$this->copynewgroups = get_column('view_autocreate_grouptype', 'grouptype', 'view', $this->id);
}
return $this->copynewgroups;
}
public function release($groupid, $releaseuser=null) {
if ($this->get('submittedto') != $groupid) {
......
......@@ -32,8 +32,8 @@ define('SECTION_PAGE', 'editaccess');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('pieforms/pieform/elements/calendar.php');
require_once(get_config('docroot') . 'lib/view.php');
require_once(get_config('docroot') . 'lib/group.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'group.php');
$view = new View(param_integer('id'));
$group = $view->get('group');
......@@ -91,48 +91,87 @@ $form = array(
'description' => get_string('templatedescription', 'view'),
'defaultvalue' => $view->get('template'),
),
'accesslist' => array(
'type' => 'viewacl',
'defaultvalue' => isset($view) ? $view->get_access() : null
)
);
if ($institution) {
if ($institution == 'mahara') {
$form['elements']['copynewuser'] = array(
'type' => 'checkbox',
'title' => get_string('copyfornewusers', 'view'),
'description' => get_string('copyfornewusersdescription', 'view'),
'defaultvalue' => $view->get('copynewuser'),
);
$form['elements']['copyfornewgroups'] = array(
'type' => 'html',
'value' => '<label>' . get_string('copyfornewgroups', 'view') . '</label>',
);
$form['elements']['copyfornewgroupsdescription'] = array(
'type' => 'html',
'value' => '<div class="description">' . get_string('copyfornewgroupsdescription', 'view') . '</div>',
);
$createfor = $view->get_autocreate_grouptypes();
foreach (group_get_grouptypes() as $grouptype) {
safe_require('grouptype', $grouptype);
$form['elements']['copyfornewgroups_'.$grouptype] = array(
'type' => 'checkbox',
'title' => get_string('name', 'grouptype.' . $grouptype),
'defaultvalue' => in_array($grouptype, $createfor),
);
}
}
else {
$form['elements']['copynewuser'] = array(
'type' => 'checkbox',
'title' => get_string('copyfornewmembers', 'view'),
'description' => get_string('copyfornewmembersdescription', 'view', get_field('institution', 'displayname', 'name', $institution)),
'defaultvalue' => $view->get('copynewuser'),
);
}
}
$form['elements']['accesslist'] = array(
'type' => 'viewacl',
'defaultvalue' => isset($view) ? $view->get_access() : null
);
$form['elements']['overrides'] = array(
'type' => 'fieldset',
'legend' => get_string('overridingstartstopdate', 'view'),
'elements' => array(
'description' => array(
'type' => 'html',
'value' => get_string('overridingstartstopdatesdescription', 'view'),
),
'overrides' => array(
'type' => 'fieldset',
'legend' => get_string('overridingstartstopdate', 'view'),
'elements' => array(
'description' => array(
'type' => 'html',
'value' => get_string('overridingstartstopdatesdescription', 'view'),
),
'startdate' => array(
'type' => 'calendar',
'title' => get_string('startdate','view'),
'defaultvalue' => isset($view) ? strtotime($view->get('startdate')) : null,
'caloptions' => array(
'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M'
),
'help' => true,
),
'stopdate' => array(
'type' => 'calendar',
'title' => get_string('stopdate','view'),
'defaultvalue' => isset($view) ? strtotime($view->get('stopdate')) : null,
'caloptions' => array(
'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M'
),
'help' => true,
),
'startdate' => array(
'type' => 'calendar',
'title' => get_string('startdate','view'),
'defaultvalue' => isset($view) ? strtotime($view->get('startdate')) : null,
'caloptions' => array(
'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M'
),
'help' => true,
),
'submit' => array(
'type' => !empty($new) ? 'cancelbackcreate' : 'submitcancel',
'value' => !empty($new)
? array(get_string('cancel'), get_string('back','view'), get_string('save'))
: array(get_string('save'), get_string('cancel')),
'confirm' => !empty($new) ? array(get_string('confirmcancelcreatingview', 'view'), null, null) : null,
'stopdate' => array(
'type' => 'calendar',
'title' => get_string('stopdate','view'),
'defaultvalue' => isset($view) ? strtotime($view->get('stopdate')) : null,
'caloptions' => array(
'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M'
),
'help' => true,
),
)
),
);
$form['elements']['submit'] = array(
'type' => !empty($new) ? 'cancelbackcreate' : 'submitcancel',
'value' => !empty($new)
? array(get_string('cancel'), get_string('back','view'), get_string('save'))
: array(get_string('save'), get_string('cancel')),
'confirm' => !empty($new) ? array(get_string('confirmcancelcreatingview', 'view'), null, null) : null,
);
function editaccess_validate(Pieform $form, $values) {
......@@ -150,7 +189,7 @@ function editaccess_cancel_submit() {
redirect('/view/groupviews.php?group='.$group);
}
if ($institution) {
redirect('/view/institutionviews.php?group='.$institution);
redirect('/view/institutionviews.php?institution='.$institution);
}
redirect('/view');
}
......@@ -168,6 +207,17 @@ function editaccess_submit(Pieform $form, $values) {
$view->set('startdate', $values['startdate']);
$view->set('stopdate', $values['stopdate']);
$view->set('template', (int) $values['template']);
$view->set('copynewuser', (int) $values['copynewuser']);
if ($institution == 'mahara') {
$createfor = array();
foreach (group_get_grouptypes() as $grouptype) {
if ($values['copyfornewgroups_'.$grouptype]) {
$createfor[] = $grouptype;
}
}
$view->set('copynewgroups', $createfor);
}
$view->commit();
if ($values['new']) {
......
Markdown is supported
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