本文整理汇总了PHP中Teacher::get_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Teacher::get_by_id方法的具体用法?PHP Teacher::get_by_id怎么用?PHP Teacher::get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Teacher
的用法示例。
在下文中一共展示了Teacher::get_by_id方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: restore_filter
/**
* This method will return data by filter name.
* If the second and third parameters are set, it will check teacher data for his prefered course and
* inject this value into filter by specified conditions, only if these filter data are empty.
* @param string $filter_name name of filter.
* @param integer|Teacher $teacher teacher id or teacher object.
* @param string $course_field field in filter which contain course id in filter.
* @return array<midex> filter data.
*/
public function restore_filter($filter_name, $teacher = NULL, $course_field = NULL)
{
$filters = $this->CI->session->userdata(self::FILTERS_ARRAY);
$filters = empty($filters) || is_null($filters) || !is_array($filters) ? array() : $filters;
$filter = array_key_exists($filter_name, $filters) ? $filters[$filter_name] : array();
if (!is_null($teacher) && !is_null($course_field) && is_string($course_field) && empty($filter)) {
if (!is_object($teacher) || !$teacher instanceof Teacher) {
$teacher_id = $teacher;
$teacher = new Teacher();
$teacher->get_by_id(intval($teacher_id));
}
if ($teacher->exists()) {
$filter[$course_field] = $teacher->prefered_course_id;
}
}
return $filter;
}
示例2: send_group_mail
public function send_group_mail($group_id)
{
$group = new Group();
$group->get_by_id($group_id);
if ($group->exists()) {
$this->load->library('form_validation');
$this->form_validation->set_rules('group_mail[subject]', 'lang:admin_groups_group_email_form_field_subject', 'required');
$this->form_validation->set_rules('group_mail[body]', 'lang:admin_groups_group_email_form_field_body', 'required_no_html');
$this->form_validation->set_rules('group_mail[from]', 'lang:admin_groups_group_email_form_field_from', 'required');
$this->form_validation->set_rules('group_mail[student][]', 'lang:admin_groups_group_email_form_field_students', 'required');
if ($this->form_validation->run()) {
$data = $this->input->post('group_mail');
$students = new Student();
$students->where_related('participant/group', 'id', $group->id);
$students->where_related('participant/course', 'id', $group->course_id);
$students->where_related('participant', 'allowed', 1);
$students->where_in('id', $data['student']);
$students->get();
if ($students->exists()) {
$from = NULL;
$from_name = '';
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
if ($data['from'] == 'me') {
$from = $teacher->email;
$from_name = $teacher->fullname;
}
$sender_copy = isset($data['sender_copy']) && $data['sender_copy'] == 1 ? TRUE : FALSE;
$sender_email = $teacher->email;
if ($this->_send_multiple_emails($students, $data['subject'], '{$data.body|add_base_url}', array('data' => $data), $from, $from_name, $sender_copy, $sender_email)) {
$this->messages->add_message('lang:admin_groups_group_email_success_sent', Messages::MESSAGE_TYPE_SUCCESS);
} else {
$this->messages->add_message('lang:admin_groups_group_email_error_send_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->messages->add_message('lang:admin_groups_group_email_error_no_students_selected', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_groups/group_mail/' . $group_id));
} else {
$this->group_mail($group_id);
}
} else {
$this->messages->add_message('lang:admin_groups_group_email_error_group_not_found', Messages::MESSAGE_TYPE_ERROR);
redirect(create_internal_url('admin_groups/group_mail/' . $group_id));
}
}
示例3: set_columns
public function set_columns()
{
$this->_transaction_isolation();
$this->db->trans_begin();
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
$teacher->widget_columns = (int) $this->input->post('widget_columns');
if ($teacher->widget_columns >= 1 && $teacher->widget_columns <= 4) {
if ($teacher->save()) {
$widget = new Admin_widget();
$widget->where_related('teacher', $teacher);
$widget->where('column >', $teacher->widget_columns);
$widget->limit(1);
$widget->get();
if ($widget->exists()) {
$widget->where('column', $teacher->widget_columns);
$widget->where_related('teacher', $teacher);
$widget->limit(1);
$widget->order_by('position', 'desc');
$widget->get();
$position = 1;
if ($widget->exists()) {
$position += $widget->position;
}
$widget->select('id');
$widget->where('column >', $teacher->widget_columns);
$widget->where_related('teacher', $teacher);
$widget->order_by('column', 'asc');
$widget->order_by('position', 'asc');
$widget->get();
$updates = TRUE;
foreach ($widget->all as $widget_to_update) {
$widget_to_update->column = $teacher->widget_columns;
$widget_to_update->position = $position;
if (!$widget_to_update->save()) {
$updates = FALSE;
} else {
$position++;
}
}
if ($updates) {
$this->db->trans_commit();
$this->messages->add_message($this->lang->line('admin_dashboard_message_columns_saved'), Messages::MESSAGE_TYPE_SUCCESS);
} else {
$this->db->trans_rollback();
$this->messages->add_message($this->lang->line('admin_dashboard_message_columns_save_fail'), Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_commit();
$this->messages->add_message($this->lang->line('admin_dashboard_message_columns_saved'), Messages::MESSAGE_TYPE_SUCCESS);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message($this->lang->line('admin_dashboard_message_columns_save_fail'), Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message($this->lang->line('admin_dashboard_message_columns_save_fail_count'), Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_dashboard'));
}
示例4: _init_teacher_quick_prefered_course_menu
protected function _init_teacher_quick_prefered_course_menu()
{
$menu = array();
$courses = new Course();
$courses->include_related('period', 'name');
$courses->order_by_related('period', 'sorting', 'asc');
$courses->order_by_with_constant('name', 'asc');
$courses->get_iterated();
foreach ($courses as $course) {
$menu[$course->period_name][$course->id] = $course->name;
}
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
$current_course_name = $this->lang->line('admin_teachers_no_prefered_course');
$current_course_id = NULL;
if ($teacher->exists()) {
$prefered_course = $teacher->prefered_course->get();
if ($prefered_course->exists()) {
$current_course_name = $this->lang->text($prefered_course->name);
$current_course_id = $prefered_course->id;
}
}
$this->parser->assign('list_teacher_prefered_course_name', $current_course_name);
$this->parser->assign('list_teacher_prefered_course_id', $current_course_id);
$this->parser->assign('list_teacher_prefered_course_menu', $menu);
}
示例5: set_teacher_language
/**
* Set new default teacher language idiom to database and session. Teacher must be loged in!
* @param string $language the language idiom to be set as default for teacher account.
* @return boolean TRUE, if language is set and session stored, FALSE otherwise.
*/
public function set_teacher_language($language)
{
if ($this->is_teacher_session_valid()) {
$all_langs = $this->CI->lang->get_list_of_languages();
if (array_key_exists($language, $all_langs)) {
$teacher = new Teacher();
$teacher->get_by_id($this->get_teacher_id());
$teacher->language = $language;
if ($teacher->save()) {
$userdata = $this->CI->session->userdata(SESSION_AUTH_LOGIN_TEACHER);
$userdata['language'] = $language;
$this->CI->session->set_userdata(SESSION_AUTH_LOGIN_TEACHER, $userdata);
return TRUE;
}
}
}
return FALSE;
}
示例6: update
public function update()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('task[name]', 'lang:admin_tasks_form_field_name', 'required');
$this->form_validation->set_rules('task[text]', 'lang:admin_tasks_form_field_text', 'required');
$this->form_validation->set_rules('task[categories][]', 'lang:admin_tasks_form_field_categories', 'required');
$this->form_validation->set_rules('task_id', 'id', 'required');
if ($this->form_validation->run()) {
$task_id = $this->input->post('task_id');
$task = new Task();
$task->get_by_id($task_id);
if ($task->exists()) {
$task_data = $this->input->post('task');
$overlay = $this->input->post('overlay');
$task->from_array($task_data, array('name', 'internal_comment'));
$task->text = remove_base_url($task_data['text']);
$author = new Teacher();
if ((int) $task_data['author_id'] > 0) {
$author->get_by_id((int) $task_data['author_id']);
}
$this->_transaction_isolation();
$this->db->trans_begin();
$categories = new Category();
$categories->where_in('id', $task_data['categories']);
$categories->get();
$task->category->get();
$task->delete($task->category->all);
if ($task->save(array('category' => $categories->all, 'author' => $author)) && $this->lang->save_overlay_array(remove_base_url_from_overlay_array($overlay, 'text')) && $this->db->trans_status()) {
$this->db->trans_commit();
$this->messages->add_message('lang:admin_tasks_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS);
$this->_action_success();
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_tasks_flash_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->messages->add_message('lang:admin_tasks_error_message_task_not_found', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_tasks'));
} else {
$this->edit();
}
}
示例7: create_solution
public function create_solution($task_set_id)
{
$this->load->library('form_validation');
$this->form_validation->set_rules('solution[student_id]', 'lang:admin_solutions_list_form_field_student', 'required|exists_in_table[students.id.1.1]');
$this->form_validation->set_rules('solution[points]', 'lang:admin_solutions_list_form_field_points', 'floatpoint');
if ($this->form_validation->run()) {
$this->_transaction_isolation();
$this->db->trans_begin();
$solution_data = $this->input->post('solution');
$task_set = new Task_set();
$task_set->where_related('course/participant/student', 'id', intval($solution_data['student_id']));
$task_set->where_related('course/participant', 'allowed', 1);
$task_set->group_start();
$task_set->or_group_start();
$task_set->group_start();
$task_set->or_where('group_id', NULL);
$task_set->or_where('`course_participants`.`group_id` = `task_sets`.`group_id`');
$task_set->group_end();
$task_set->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)');
$task_set->group_end();
$task_set->or_where_related('task_set_permission', '`group_id` = `course_participants`.`group_id`');
$task_set->group_end();
$task_set->get_by_id($task_set_id);
$created_solution_id = NULL;
if ($task_set->exists()) {
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
$solution = new Solution();
$solution->from_array($solution_data, array('student_id', 'comment'));
if (trim($solution_data['points']) != '' && is_float($solution_data['points'])) {
$solution->points = floatval($solution_data['points']);
} else {
$solution->points = NULL;
}
$solution->revalidate = 0;
$solution->save(array($teacher, $task_set));
$solution->where('task_set_id', $task_set_id);
$solution->where('student_id', intval($solution_data['student_id']));
if ($solution->count() == 1) {
$created_solution_id = $solution->id;
$this->db->trans_commit();
$this->messages->add_message('lang:admin_solutions_list_new_solution_created', Messages::MESSAGE_TYPE_SUCCESS);
$this->_action_success();
$this->output->set_internal_value('student_id', $solution->student_id);
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_solutions_list_new_solution_error_solution_exists', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_solutions_list_new_solution_error_student_not_in_course_or_group', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_solutions/new_solution_form/' . intval($task_set_id) . ($created_solution_id !== NULL ? '/' . intval($created_solution_id) : '')));
} else {
$this->new_solution_form($task_set_id);
}
}
示例8: add_comment
private function add_comment($task_set_id, $reply_at_id = NULL)
{
$comment_data = $this->input->post('comment');
if (isset($comment_data['task_set_id']) && $comment_data['task_set_id'] == $task_set_id) {
$this->_transaction_isolation();
$this->db->trans_begin();
$task_set = new Task_set();
$task_set->get_by_id($task_set_id);
if ($task_set->exists()) {
if ((bool) $task_set->comments_enabled) {
$save_array = array();
$save_array['task_set'] = $task_set;
if (isset($comment_data['reply_at_id']) && $comment_data['reply_at_id'] == $reply_at_id) {
$reply_at = new Comment();
$reply_at->get_by_id($reply_at_id);
if ($reply_at->exists()) {
if ($reply_at->task_set_id == $task_set_id) {
$save_array['reply_at'] = $reply_at;
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_task_sets_comments_error_reply_at_comment_from_different_task_set', Messages::MESSAGE_TYPE_ERROR);
return;
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_task_sets_comments_error_reply_at_comment_not_exists', Messages::MESSAGE_TYPE_ERROR);
return;
}
}
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
$save_array['teacher'] = $teacher;
$comment = new Comment();
$comment->text = strip_tags($comment_data['text'], '<a><strong><em><span>');
$comment->approved = 1;
if ($comment->save($save_array)) {
$this->db->trans_commit();
$this->messages->add_message('lang:admin_task_sets_comments_save_successfully', Messages::MESSAGE_TYPE_SUCCESS);
$all_students = $task_set->comment_subscriber_student;
$all_students->get();
$this->_send_multiple_emails($all_students, 'lang:admin_task_sets_comments_email_subject_new_post', 'file:emails/backend/comments/new_comment_student.tpl', array('task_set' => $task_set, 'teacher' => $teacher, 'comment' => $comment));
$all_teachers = $task_set->comment_subscriber_teacher;
$all_teachers->where('id !=', $this->usermanager->get_teacher_id());
$all_teachers->get();
$this->_send_multiple_emails($all_teachers, 'lang:admin_task_sets_comments_email_subject_new_post', 'file:emails/backend/comments/new_comment_teacher.tpl', array('task_set' => $task_set, 'teacher' => $teacher, 'comment' => $comment));
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_task_sets_comments_error_save_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_task_sets_comments_error_comments_disabled', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_task_sets_error_task_set_not_found', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->messages->add_message('lang:admin_task_sets_error_task_set_not_found', Messages::MESSAGE_TYPE_ERROR);
}
}
示例9: switch_prefered_course
public function switch_prefered_course($course_id, $current_url)
{
$this->usermanager->teacher_login_protected_redirect();
$this->_transaction_isolation();
$this->db->trans_begin();
$teacher = new Teacher();
$teacher->get_by_id($this->usermanager->get_teacher_id());
if ($teacher->exists()) {
$course = new Course();
$course->get_by_id($course_id);
if ($teacher->save(array('prefered_course' => $course))) {
$this->db->trans_commit();
$this->usermanager->refresh_teacher_userdata();
$this->messages->add_message('lang:admin_teachers_prefered_course_quickchange_success', Messages::MESSAGE_TYPE_DEFAULT);
$this->load->library('filter');
$this->filter->set_all_filters_course($teacher->prefered_course_id);
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_teachers_prefered_course_quickchange_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_teachers_prefered_course_quickchange_failed', Messages::MESSAGE_TYPE_ERROR);
}
redirect(decode_from_url($current_url));
}