protected function GETnotes(Student $student, $topic, $index) { $view = new View(self::layout); $this->evaluation = Data::FACTORY($topic, $student->evaluation($topic, $index)); $this->url = $student->context['@url'] . "/{$topic}/{$index}"; $this->files = \models\Assessment::Links($this->url); $this->template = 'editor'; $view->context = "views/layouts/notes.html"; $view->content = "views/layouts/inspector.html"; return $view->render($this()); }
/** * Generates students * @param int $amount */ protected function _generateStudents($amount) { $emailPrefix = rand(100000, 999999); for ($i = 0, $j = $amount; $i !== $j; $i++) { $name = $this->_getName() . '-' . $i; $data = ['name' => $name, 'birth_date' => date('Y-m-d', rand(0, 946684800)), 'email' => $name . $emailPrefix . '-' . $i . '@generated.com', 'level_id' => Enum::get('language_levels.*')[rand(0, 5)]->id]; $s = new Student($data); try { $s->validate(); $s->save(); } catch (\Exception $e) { // do nothing } } }
public function POSTlogin($request) { $pin = $request->post('pin') ?: 0; $uid = $request->post('uid') ?: false; try { if ($uid && $pin) { // authenticate user based on password (new \models\instructor(\models\Data::ID($uid)))->authenticate($pin); \bloc\Application::instance()->session('COLUM', ['id' => $uid]); \bloc\router::redirect('/records/courses'); } else { // user must be in database based on oasis id, find them: ; $user = \models\Data::ID(\models\Student::BLEAR($pin)); // if found, generate token with sha1 of $email address and token $token = \bloc\types\token::generate($user['@email'], getenv('EMAIL_TOKEN')); // set the token on the user field if ($user->hasAttribute('token') && $user->getAttribute('token') === $token) { throw new \InvalidArgumentException("Token Already Requested", 2); } else { $user->setAttribute('token', $token); \models\Data::instance()->storage->save(); // email the user a link. $template = new \bloc\View('views/layouts/email.html'); $template->content = 'views/layouts/forms/transaction.html'; $output = ['link' => DOMAIN . "/records/token/{$user['@id']}/{$token}", 'title' => $user['@name'], 'message' => 'login to course site']; \models\Message::TRANSACTION('login', $user['@email'], (string) $template->render($output)); } } } catch (\InvalidArgumentException $e) { $type = $e->getCode() == 1 ? 'invalid' : 'duplicate'; $path = sprintf('/%s/login/%s/', $this->template, $type); \bloc\router::redirect($path); } $view = new \bloc\View(self::layout); $view->content = 'views/layouts/forms/transaction.html'; return $view->render(['link' => 'http://www.colum.edu/loopmail', 'title' => 'Email Sent', 'message' => 'check your email']); }
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); } }
$rest->get('/students/search', function () use($app) { $q = addslashes($app['request']->get('query')); $search = strtolower($q) . '%'; $result = DB::select("SELECT `id`\n FROM `students`\n WHERE `name` LIKE '{$search}';\n "); $result = array_map(function ($itm) { return $itm['id']; }, $result); $students = Student::whereIn('id', $result)->get(); return $app->json($students); }); /** * Student creation */ $rest->post('/students', function (Request $req) use($app) { $data = $req->request->all(); $s = new Student($data); try { $s->validate(); $s->save(); return $app->json($s, 201); } catch (\Models\ValidationException $e) { return $app->json(['errors' => $e->getErrors()], 400); } }); /** * Bind teacher to student */ $rest->post('/student-teacher', function (Request $req) use($app) { $data = $req->request->all(); $st = new StudentTeacher($data); try {
protected function POSTevaluate(Admin $instructor, $request, $topic, $index, $sid) { $student = new Student($sid); $item = Data::FACTORY($topic, $student->evaluation($topic, $index), $_POST); if ($item->save()) { \bloc\router::redirect("/records/student/{$sid}"); } else { \bloc\application::instance()->log($item); $view = new View(self::layout); $view->content = "views/layouts/error.html"; return $view->render($this(['message' => "did not save"])); } }