[eluser]trope[/eluser]
I am trying to write a helper in which will return an array.
$task_progress["users"]["percentage_complete"]
$task_progress["users"]["icon"]
$task_progress["users"]["total_blank"]
Essentially, this corresponds to the users table.
I am stuck in my function which calculates the information I want to return. In my array there are fields that I do not want to count against the user.
I have my code below, but am totally stuck. Can anyone help me finish this?
I really would appreciate a nudge. I am new to CI, and sure do need help calculating this percentage thing!
Thank you!
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* MyResume
*
* Online Resume Development Tool
*
* @package MyResume
* @author John Tropeano
* @copyright (c) 2011
* @link http://www.johntropeano.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* MyResume Progress Helpers
*
* @package MyResume
* @subpackage Helpers
* @category Helpers
* @author John Tropeano
* @link http://myresume.johntropeano.com/user_guide/helpers/myresume_helper.html
*/
// Given a user id which is stored in the session, this function will return an array
// containing the progress percentage of each section (table). This will show the user their progress
// in a percentage as to how they are doing filling out the fields in the table. However, there are certain
// fields in which we don't want to count against the users progress. We need to ignore these fields
//
// If the users progress is 100% => return icon complete
// 80% => return warning icon
// other => return incomplete icon
// ------------------------------------------------------------------------
/**
* Get Task Percentage
*
* @access public
* @return array task_progress array holding info on each section
* [total_blank]
* [percent_completed]
* [icon]
*/
function progress()
{
$CI =& get_instance();
$CI->load->library('session','database');
$task_progress = array();
// Should go into a config somewhere?
$icon_error = "/images/icons/fugue/cross-circle.png";
$icon_warning = "/images/icons/web-app/48/warning.png";
$icon_complete = "/images/icons/task_completed.png";
$ignore_fields = array ("users" => array("id",
"last_login_date",
"number_of_logins",
"ip_address",
"password_reset"
),
"work_history" => array("id","user_id"),
"skills" => array("id","user_id"),
"education" => array("id","user_id"),
"projects" => array("id","user_id")
);
// Get User ID
$id = $CI->session->userdata("my_resume_id");
foreach($ignore_fields as $table_name => $ignore_me)
{
// Get an array of field names for the table name
$fields = $CI->db->list_fields($table_name);
// Loop through $fields
foreach($fields as $current_field_name)
{
// Get value for field name in this table
$CI->db->where('id', $CI->session->userdata("my_resume_id"));
$CI->db->select($current_field_name);
$query = $CI->db->get($table_name);
$row=$query->row();
}
}
die();
return $task_progress;
}
//* End of file progress_helper.php */
/* Location: ./application/helpers/progress_helper.php */