So, my early experiments were this.
ss.addMenu("Administration", menuEntries);
function create_a_site( template_site_name, student_unique_id ){
var domain = "york.ac.uk" ;
var template_site = SitesApp.getSite(domain, template_site_name );
var name = "" + template_site.getName() + "-" + student_unique_id .toLowerCase() ;
var title = name ;
var summary = "Deadline 21st, December 2012" ;
// See the warning in https://developers.google.com/apps-script/class_sitesapp about site creation speed
var site = SitesApp.copySite(domain, name, title, summary, template_site);
var sites_url = site.getUrl();
return sites_url ;
}
function create_sites(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("students");
var result = Browser.inputBox("Which Site is the template Site?", "project-template", Browser.Buttons.OK_CANCEL );
if (result == "cancel"){
//Browser.msgBox("CANCEL: " + result)
}
else{
var range = ss.getDataRange().getValues();
var students = rangeToObjects(range);
var template_site_name = result
try{
for(var i = 0; i < students.length; i++){
var student = students[i];
var site_name = template_site_name +"-" + student.uniquereference.toLowerCase();
var domain = "york.ac.uk" ;
var sites_url = create_a_site(template_site_name, student.uniquereference.toLowerCase() ); //Alter the values
students[i].sites_url = sites_url;
var x = i+2
var cellnum = x.toString().replace("0", "");
//Browser.msgBox(x);
Logger.log( cellnum );
var values = new Array();
values[0] = sites_url
var cellname = "D" + cellnum;
var range = sheet.getRange( cellname )
range.setValue( sites_url );
}
}catch(e){
Logger.log( e.message );
}
// Now write the URLs back to the spreadsheet. Or not.
}
}
function add_students_to_sites(){
//Browser.msgBox("Add Students To Sites!")
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("students");
var range = ss.getDataRange().getValues();
var students = rangeToObjects(range);
for(var i = 0; i < students.length; i++){
student = students[i];
var url = student.siteurl;
var email = student.email;
var examiner = student.examiner;
var site = SitesApp.getSiteByUrl(url);
site.addEditor(email);
site.addViewer(examiner);
}
Browser.msgBox("Added students to sites")
}
function test_create_a_site(){
var x = create_a_site("project-template", "Y63326039" );
Logger.log( "Done! " + x );
//Browser.msgBox(x)
}
function add_people( site_name, student_email, examiner_email ) {
var domain = "york.ac.uk" ;
var site = SitesApp.getSite(domain, site_name );
site.addEditor( student_email ).addViewer(examiner_email);
the_url = site.getUrl();
//email a link to the student
/*MailApp.sendEmail(student_email,
"Your Philosophy Homework Site",
"A Google Site has been created for you to fill in. \n\n " +
the_url + "\n\n",
{name:"Philosophy Course"});*/
Logger.log("Done!");
}
function notify_examiners ( ){
// email a link to the examiner
// https://developers.google.com/apps-script/class_mailapp
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("students");
var range = ss.getDataRange().getValues();
var students = rangeToObjects(range);
for(var i = 0; i < students.length; i++){
student = students[i];
var url = student.siteurl;
var email = student.email;
var examiner = student.examiner;
var site = SitesApp.getSiteByUrl(url);
MailApp.sendEmail(examiner, "TEST: A Philosophy Homework Site To Mark",
"A Google Site has been created for you to mark. \n\n " +
url + "\n\n",
{name:"Philosophy Course"});
//At this point we might want to record that the mail has been sent...
}
Browser.msgBox("Done!");
}