Methods

  • BrainJS: u.method()
  • BrainXML: <u>method()</u>
function User( ) {
this.setBirthdayByDate = function(str) {
     var words = this.wordCount(str);
     switch (words) {
       case 2:
         str = str + ' 1900';        
         break;
       case 3:
         break;
       default:
         return false;
     }
     
     var d = new Date(Date.parse(str));
     if (words === 2) {
       this.setBirthday(d.getDate(), d.getMonth());
     }
     else {
       this.setBirthday(d.getDate(), d.getMonth(), d.getFullYear());    
     }
     var nd = new Date();
     this.age = nd.getFullYear() - d.getFullYear();
     this.ageDate = nd;
  
};
this.setBirthdayByOffset = function(str) {
     var n = parseFloat(str);
     if (!this.isNumber(n)) {
       return false;
     }
     var today = new Date();
     this.setBirthday(today.getDate() + n, today.getMonth()+1);
  
};
this.setBuddiesOff = function( ) {
  
     this.buddies = {};
     this.buddiesOn = 0;
  
};
this.setBuddiesOn = function( ) {
  
     this.allowBuddies = 1;
  
};
this.setGenderByRelation = function( ) {
    if (!relation) {
       relation = this.relation;
     }
     var gender = relation2Gender(relation);
     if (gender !== '') {
       this.gender = gender;
       
       return true;
     }
     else {
       return false;
     }
  
};
this.setPerson = function(property, value, name, relation) {
     var isNew = false;
     var i = this.getIndex(name, relation);
     if (i === '') {
       i = this.people.length;
       this.people[i] = new Person();
       isNew = true;
     }
     if (relation) {      
       this.people[i].relation = relation;
       var gender = relation2Gender(relation);
       if (gender !== '') {
         this.people[i].gender = gender;
       }
     }
     switch(property) {
       case "age":
         this.people[i].setage(value);
         break;
       case "birthday":
         this.people[i].setBirthday(value);
         break;
       default:
         this.people[i][property] = value;
         break;
     }
     return isNew;
  
};
this.setTime = function( ) {
  
     var d = new Date();
     if (d.getTime() - this.lastSent < 1000){
       return; // ignore if gap < 1 s
     }
     var previousSent = this.lastSent;    
     this.lastSent = d.getTime();   
     
     if (previousSent === 0){
       this.idle = 0;
     }
     else {
       this.idle = Math.round((this.lastSent - previousSent)/1000); // seconds
     }
     
     if (this.idle > 1800){  // this is a new session
       this.sessionStart = d.getTime();
     }
     
  
};
this.setTimedTopic = function(str) {
  var now = Math.round(new Date().getTime()/1000);
  this.timedTopic = {topic: str, time: now};
};
this.speakingQuiz = function(cont) {
  
     var url = 'http://acobot.com/api/speaking/quiz/' + this.uid_key;
     if (cont !== undefined){
       url += '/cont'; 
     }
     return sraix(url);
  
};
this.speakingReport = function( ) {
   
     var to = this.getPageLang();
     if (!to){
       to = 'en';
     }
     var url = 'http://acobot.com/api/speaking/report/' + this.uid_key + '/' + to;
     return this.loadWebPage(url);
  
};

页面