Example #1
0
File: users.php Project: xXLXx/ddc
 public function post_update_profile($id)
 {
     $errors = [];
     $data = null;
     $success = false;
     if (count($errors)) {
         return $this->error($errors);
     }
     $obj = Model_User::find($id);
     if (!$obj) {
         $errors[] = 'Cannot find User with ID: ' . $id;
     } else {
         if (!$obj->profile) {
             if (!Input::post('year_level') || !Input::post('course_id')) {
                 return $this->error('Student has no profile yet, send data for both year_level and course_id');
             } else {
                 $obj->profile = Model_Student::forge(Input::post());
             }
         }
         foreach (Input::post() as $key => $value) {
             if ($key == 'password') {
                 $value = Auth::instance()->hash_password($value);
             }
             $obj->{$key} = $value;
             $obj->profile->{$key} = $value;
         }
         $success = $obj->save();
         if (!$success) {
             $errors[] = 'Could not save User';
         } else {
             $data = $obj;
         }
     }
     return $this->response(['data' => $data, 'success' => $success, 'errors' => $errors]);
 }
Example #2
0
 function init()
 {
     parent::init();
     $this->hasOne('Session_Current', 'session_id');
     $this->addCondition('session_id', $this->add('Model_Session_Current')->dsql()->field('id'));
     $this->join('scholars_master', 'scholar_id');
     $this->_dsql()->order(array('class_id', 'fname'));
 }
Example #3
0
File: site.php Project: xXLXx/ddc
 public function action_register()
 {
     if (Input::method() == 'POST') {
         $val = Model_User::validate('create');
         if ($val->run()) {
             $user = Model_User::forge(array('username' => Input::post('username'), 'password' => Auth::instance()->hash_password(Input::post('password')), 'group' => 1, 'email' => Input::post('email'), 'fname' => Input::post('fname'), 'mname' => Input::post('mname'), 'lname' => Input::post('lname'), 'contact_num' => Input::post('contact_num'), 'address' => Input::post('address'), 'profile_pic' => Input::post('profile_pic'), 'last_login' => Input::post('last_login'), 'login_hash' => Input::post('login_hash'), 'profile_fields' => Input::post('profile_fields')));
             Upload::process(Config::get('upload_profile_picture'));
             $user->profile = Model_Student::forge(['year_level' => 0, 'course_id' => 0]);
             if (Upload::is_valid()) {
                 Upload::save();
                 $value = Upload::get_files();
                 foreach ($value as $files) {
                     $user->profile_pic = $value[0]['saved_as'];
                 }
                 if ($user and $user->save()) {
                     Session::set_flash('success', e('Succesfully Added user #' . $user->id . '.'));
                     Response::redirect('site/login');
                 } else {
                     Session::set_flash('error', e('Could not save user.'));
                 }
             } else {
                 Session::set_flash('error', e('Uploaded photo is invalid.'));
             }
             // if ($user and $user->save())
             // {
             // 	Session::set_flash('success', e('Succesfully Added user #'.$user->id.'.'));
             // 	Response::redirect('site/login');
             // }
             // else
             // {
             // 	Session::set_flash('error', e('Could not save user.'));
             // }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     // $this->template->title = "Users";
     // $this->template->content = View::forge('admin/users/create');
     $this->template->title = 'Register';
     $this->template->content = View::forge('site/register');
 }
Example #4
0
 function init()
 {
     parent::init();
     $this->addCondition('ishostler', true);
     $raj = $this->join('hostel_allotement.student_id', 'id');
     $rj = $raj->join('rooms.id', 'room_id');
     $bj = $rj->join('hostel_master.id', 'hostel_id');
     $rj->addField('room_no');
     $bj->addField('building_name');
     $this->addField('is_present')->type('boolean')->defaultValue(false);
     $this->hasMany('Item_Issue', 'student_id');
     $this->hasMany('Students_Disease', 'student_id');
     // $this->addExpression('father_name')->set(function($m,$q){
     // 	return $m->refSQL('scholar_id')->fieldQuery('father_name');
     // });
     $this->addExpression('attendance_status')->set(function ($m, $q) {
         return $m->refSQL('Students_Movement')->fieldQuery('purpose')->limit(1)->order('date', 'desc')->where('purpose', 'in', array('inward', 'outward'));
     })->display('attendance');
     $this->addExpression('image_url')->set(function ($m, $q) {
         return $m->refSQL('scholar_id')->fieldQuery('image_url');
     })->display('picture');
 }
Example #5
0
 /**
  * 根据查询条件、排序条件获取数据
  * @param $fields String 显示字段列表
  * @param $params Array 查询条件
  * @param $tables Array 多表查询
  * @param $order_by Array 排序字段(array('字段名' => 'ASC|DESC'))
  * @param $limit int 限制条数
  * @param $page int 分页状态(0.不分页 1.分页)
  */
 public static function getItems($fields = '*', $params = array(), $tables = array(), $order_by = array(), $limit = 0, $page = 0)
 {
     $items = Model_Student::query();
     //判断是否多表查询
     if ($tables) {
         $items->related($tables);
     }
     //判断是否有查询条件
     if ($params) {
         foreach ($params as $key => $value) {
             if (is_array($value)) {
                 $items->where($key, $value[0], $value[1]);
             } else {
                 $items->where($key, $value);
             }
         }
     }
     //判断是否有排序条件
     if ($order_by) {
         foreach ($order_by as $key => $value) {
             if (is_numeric($key)) {
                 $items->order_by($value);
             } else {
                 $items->order_by($key, $value);
             }
         }
     }
     if ($limit) {
         $items->limit($limit);
     }
     //判断是否分页
     if ($page) {
         return $items;
     } else {
         return $items->get();
     }
 }
Example #6
0
 public function action_count_not_approved()
 {
     return Format::forge(Model_Student::find(count('id'), array('where' => array('course_id' => 0, 'year_level' => 0))))->to_json();
 }
Example #7
0
 function init()
 {
     parent::init();
     $this->addCondition('session_id', $this->add('Model_Sessions_Current')->tryLoadAny()->get('id'));
 }
Example #8
0
 			<div class="panel panel-danger">
 			 	<div class="panel-heading">Students Not Aprroved</div>
			    <div class="panel-body">
			    	<h1 class="text-danger text-center"><?php 
echo Model_Student::count_not_approved();
?>
</h1>
			    </div>
			</div>
 		</div>
 		<div class="col-md-4">
 			<div class="panel panel-success">
 			 	<div class="panel-heading">Students Aprroved</div>
			    <div class="panel-body">
			    	<h1 class="text-success text-center"><?php 
echo Model_Student::count_approved();
?>
</h1>
			    </div>
			</div>
 		</div>
 		<div class="col-md-4">
 			<div class="panel panel-default">
 			 	<div class="panel-heading">All Students</div>
			    <div class="panel-body">
			    	<h1 class="text-muted text-center"><?php 
echo Model_User::all_students();
?>
</h1>
			    </div>
			</div>
Example #9
0
 function init()
 {
     parent::init();
     $this->hasOne('Session_Current', 'student.session_id', 'session_master.id');
     $this->hasOne('Class', 'student.class_id', 'class_master.id');
 }
Example #10
0
 public static function count_approved()
 {
     $approved = Model_Student::count(array('where' => array('course_id' => 1, 'year_level' => 1)));
     return $approved;
 }