public function add_widget() { $output = new stdClass(); $output->message = ''; $output->status = FALSE; $output->new_id = 0; $this->_transaction_isolation(); $this->db->trans_begin(); $widget_type = $this->input->post('widget_type'); $widget_column = $this->input->post('widget_column'); $output->column = (int) $widget_column; if ($widget_type !== '') { $last_widget = new Admin_widget(); $last_widget->where_related('teacher', 'id', $this->usermanager->get_teacher_id()); $last_widget->where('column', (int) $widget_column); $last_widget->limit(1); $last_widget->order_by('position', 'desc'); $last_widget->get(); $position = 1; if ($last_widget->exists()) { $position += $last_widget->position; } try { $wgt = $this->load->admin_widget($widget_type, 0, array()); $widget = new Admin_widget(); $widget->teacher_id = $this->usermanager->get_teacher_id(); $widget->widget_type = $widget_type; $widget->widget_config = serialize($wgt->defaultConfiguration()); $widget->position = $position; $widget->column = (int) $widget_column; $widget->save(); $this->db->trans_commit(); $output->message = $this->lang->line('admin_dashboard_message_widget_created'); $output->status = TRUE; $output->new_id = (int) $widget->id; } catch (Exception $e) { $this->db->trans_rollback(); $output->message = $this->lang->line('admin_dashboard_message_widget_creation_failed'); } } else { $this->db->trans_rollback(); $output->message = $this->lang->line('admin_dashboard_message_widget_creation_failed'); } $this->output->set_content_type('application/json'); $this->output->set_output(json_encode($output)); }
public function sort() { $columns = $this->input->post('column'); $this->_transaction_isolation(); $this->db->trans_start(); if (count($columns)) { foreach ($columns as $column => $widget_ids) { $position = 1; if (count($widget_ids)) { foreach ($widget_ids as $widget_id) { $widget = new Admin_widget(); $widget->where_related('teacher', 'id', $this->usermanager->get_teacher_id()); $widget->get_by_id((int) $widget_id); if ($widget->exists()) { $widget->column = $column; $widget->position = $position; $widget->save(); $position++; } } } } } $this->db->trans_complete(); }