Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

User upload #31

Merged
merged 17 commits into from
Commits on Aug 22, 2012
  1. added logic for uploading image in form methods

    Alan Lin authored
  2. added upload form in editing form

    Alan Lin authored
  3. added picture updating

    Alan Lin authored
  4. added image helper to return img src for user

    Alan Lin authored
  5. added path helper to act as a factory

    Alan Lin authored
  6. added directory for user picture uploads

    Alan Lin authored
  7. removed local pictures

    Alan Lin authored
  8. load image helper

    Alan Lin authored
  9. refactored to show local image if exists

    Alan Lin authored
  10. added profile pic to right of student name

    Alan Lin authored
  11. added student image to edit form

    Alan Lin authored
  12. added error for failed update

    Alan Lin authored
  13. added picture deletion

    Alan Lin authored
  14. added picture delete

    Alan Lin authored
  15. added link to remove picture

    Alan Lin authored
  16. added student status to student block

    Alan Lin authored
This page is out of date. Refresh to see the latest.
View
2  application/config/config.php
@@ -15,7 +15,7 @@
|
*/
$config['base_url'] = '';
-
+$config['student_pic_upload_path'] = 'uploads/students/pictures/';
/*
|--------------------------------------------------------------------------
| Index File
View
60 application/controllers/student.php
@@ -5,7 +5,7 @@ class Student extends MY_Controller {
public function __construct(){
parent::__construct();
-
+ $this->load->helper("image_helper");
}
public function index()
@@ -70,6 +70,7 @@ public function edit_form(){
//Create list of schools view
$data["schools"] = $this->student_model->get_schools();
+ $data["upload_errors"] = '';
$this->load->view('student/edit_student_form', $data);
}
@@ -133,7 +134,7 @@ public function edit(){
$data["majors"] = $this->student_model->get_majors();
//Create list of schools view
$data["schools"] = $this->student_model->get_schools();
-
+ $data["upload_errors"] = '';
$this->load->view('student/edit_student_form', $data);
//Else, add student to database
@@ -180,14 +181,65 @@ public function edit(){
endif;
}
-
+
+ public function upload_profile_pic(){
+
+ //set the path to root
+ $config['upload_path'] = './uploads/students/pictures';
+ $config['allowed_types'] = 'gif|jpg|png';
+ //append unix time stamp for unique update
+ $config['file_name'] = "studentpic_" . $this->current_student_id . "_" . time();
+
+ //2000kb and max image width and height
+ $config['max_size'] = '2000';
+ $config['max_width'] = '1024';
+ $config['max_height'] = '768';
+
+ //prevent users from uploading multiple images.
+ $config['overwrite'] = TRUE;
+
+ //load the upload lib with settings
+ $this->load->library('upload', $config);
+ if (!$this->upload->do_upload()):
+ $data["student_logged_in"] = $this->current_student_info;
+ $data["majors"] = $this->student_model->get_majors();
+ $data["schools"] = $this->student_model->get_schools();
+ $data["upload_errors"] = $this->upload->display_errors();
+
+ $this->load->view('student/edit_student_form', $data);
+ else:
+ $uploaded_data = $this->upload->data();
+ $status = $this->student_model->update_profile_picture($this->current_student_id, $uploaded_data['file_name']);
+
+ $this->load->library('message');
+ if ($status):
+ $this->message->set("Picture updated successfully", "success", TRUE);
+ redirect("student/edit_form");
+ else:
+ $this->message->set("Picture update failed", "error", TRUE);
+ redirect("student/edit_form");
+ endif;
+ endif;
+
+ }
+
+ public function remove_profile_pic(){
+ $status = $this->student_model->delete_profile_picture($this->current_student_id);
+ $this->load->library('message');
+ if ($status):
+ $this->message->set("Picture deleted successfully", "success", TRUE);
+ redirect("student/edit_form");
+ else:
+ $this->message->set("Picture delete failed", "error", TRUE);
+ redirect("student/edit_form");
+ endif;
+ }
//View all students
public function view_all()
{
//Retrieve all students information to send to view
$data["students"] = $this->student_model->get_all_students();
-
$this->load->view('student/view_all_students', $data);
}
View
21 application/helpers/image_helper.php
@@ -0,0 +1,21 @@
+<?php
+
+function student_picture_src($student_id, $oauth_uid, $picture){
+
+ $CI =& get_instance();
+ $CI->load->helper("path_helper");
+ $student_pic_url = student_picture_url();
+
+ if($picture):
+ return $student_pic_url . $picture;
+ else:
+ if($oauth_uid):
+ return "https://graph.facebook.com/". $oauth_uid . "/picture?type=large"; //high resolution
+ else:
+ return "http://i0.kym-cdn.com/photos/images/original/000/074/586/tumblr_l7l1nqA5va1qdsweso1_1280.jpg?1318992465"; //dummy image
+ endif;
+ endif;
+
+}
+
+//end of image_helper.php
View
23 application/helpers/path_helper.php
@@ -0,0 +1,23 @@
+<?php
+// application/helpers/path_helper.php
+if (!function_exists('asset_url'))
+{
+ function asset_url()
+ {
+ // the helper function doesn't have access to $this, so we need to get a reference to the
+ // CodeIgniter instance. We'll store that reference as $CI and use it instead of $this
+ $CI =& get_instance();
+ // return the asset_url
+ return base_url() . $CI->config->item('asset_path');
+ }
+
+ function student_picture_url()
+ {
+ $CI =& get_instance();
+ // return the asset_url
+ return base_url() . $CI->config->item('student_pic_upload_path');
+ }
+
+}
+
+/*End of path_helper located in application/helpers*/
View
38 application/models/student_model.php
@@ -113,8 +113,6 @@ public function oauth_authenticate($oauth_id, $email="None", $first_name, $last_
if($rows > 0):
return $result;
else:
- //echo "mufuka he ain't exist";exit(4);
-
$data = array(
'oauth_uid' => $oauth_id,
'first' => $first_name ,
@@ -132,9 +130,41 @@ public function oauth_authenticate($oauth_id, $email="None", $first_name, $last_
$rows = $query->num_rows();
$result = $query->row();
return $result;
- endif;
-
+ endif;
endif;
}
+ public function update_profile_picture($student_id, $file_name){
+ //update student set picture = blah where id = blah
+ $data = array(
+ 'picture' => $file_name,
+ );
+ $this->db->where('student_id', $student_id);
+ $this->db->update('students', $data);
+
+ $rows_affected = $this->db->affected_rows();
+
+ if($rows_affected > 0)
+ return TRUE;
+ else
+ return FALSE;
+
+ }
+
+ public function delete_profile_picture($student_id){
+ $data = array(
+ 'picture' => NULL,
+ );
+
+ $this->db->where('student_id', $student_id);
+ $this->db->update('students', $data, FALSE);
+
+ $rows_affected = $this->db->affected_rows();
+
+ if($rows_affected > 0)
+ return TRUE;
+ else
+ return FALSE;
+ }
+
}
View
18 application/views/student/edit_student_form.php
@@ -22,7 +22,7 @@
endforeach;
//Settings for form elements
-
+
$first = array(
'name' => 'first',
'value' => set_value('first', $student_logged_in->first)
@@ -130,10 +130,22 @@
</hgroup>
<?php $this->message->display(); ?>
-
+ <!--Get the students profile picture source.. Will add helper for this -->
+ <?php $pic_src = student_picture_src($student_logged_in->student_id, $student_logged_in->oauth_uid, $student_logged_in->picture); ?>
+ <img src="<?php echo $pic_src; ?>" width="100px" height="100px"/>
+ <?php echo anchor("student/remove_profile_pic", "Remove Picture"); ?>
+ <!--begin upload form-->
+ <?php echo $upload_errors;?>
+ <?php echo form_open_multipart('student/upload_profile_pic');?>
+ <input type="file" name="userfile" size="20" />
+ <input type="submit" value="upload" />
+ </form>
+ <!--end upload form-->
+
<?php echo form_open('student/edit/' . $student_logged_in->student_id, array("id" => "edit-profile")); ?>
+
<?php echo validation_errors('<p class="error-message">', '</p>'); ?>
-
+
<h2>Personal Information</h2>
<?php echo form_label('First Name:', 'first'); echo form_input($first);?>
<?php echo form_label('Last Name:', 'last'); echo form_input($last); ?>
View
3  application/views/student/student_block.php
@@ -1,7 +1,10 @@
<section class="listing">
<header>
+ <?php $pic_src = student_picture_src($student->student_id, $student->oauth_uid, $student->picture); ?>
+ <img src="<?php echo $pic_src; ?>" width="25px" height="25px"/>
<h2><?php echo $student->first . ' ' . $student->last; ?></h2>
<h3><?php echo $student->school_id . ' ' . $student->year; ?> - <?php echo $student->major_id ?>
+ <h3><?php if($student->status) echo $student->status; ?></h3>
<br />Arts & Sciences 2014 - Computer Science</h3>
</header>
<div class="float-right">
Something went wrong with that request. Please try again.