Example #1
0
 public function CLIenroll($semester, $course, $section, $id = null, $name = null, $email = null, $year = null, $major = null)
 {
     $doc = new Document("data/{$semester}");
     $section = (new \DomXpath($doc))->query("//courses/section[@id='{$section}' and @course='{$course}']");
     if ($section->length < 1) {
         throw new \RuntimeException("No section {$section} for {$course} in {$semester}", 1);
     }
     $student = $section->item(0)->appendChild($doc->createElement('student'));
     if ($name === null) {
         echo "\nName: ";
         $name = trim(fgets(STDIN));
     }
     if ($id === null) {
         echo "\nOasis ID: ";
         $id = trim(fgets(STDIN));
     }
     if ($email === null) {
         echo "\nEmail: ";
         $email = trim(fgets(STDIN));
     }
     if ($year === null) {
         echo "\nYear: ";
         $year = trim(fgets(STDIN));
     }
     if ($major === null) {
         echo "\nMajor: ";
         $major = trim(fgets(STDIN));
     }
     $student->setAttribute('name', $name);
     $student->setAttribute('email', $email);
     $key = substr($email, 0, strpos($email, '@'));
     $student->setAttribute('url', "http://iam.colum.edu/students/{$key}/{$course}");
     $student->setAttribute('id', \models\Student::BLEAR($id));
     $student->setAttribute('year', $year);
     $student->setAttribute('major', $major);
     echo $student->write() . "\nCreate Account (Y/n): ";
     if (strtoupper(trim(fgets(STDIN))) === 'Y') {
         return $this->save($doc);
     }
 }