public
Created

EE_addon Percentage Complete

  • Download Gist
percentage_complete.ee_addon
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
function percentage_complete(){
$this->EE=& get_instance();
$entry_id = intval($this->_get_param('entry_id'));
$channel_id = intval($this->_get_param('channel_id'));
$site_id = intval($this->_get_param('site_id'));
$field_group_id = intval($this->_get_param('field_group_id'));
$field_array = array();
$result_array = array();
$final_array = array();
// Query All the Fields
$fquery = $this->EE->db->query("SELECT field_id FROM exp_channel_fields WHERE site_id = ".$site_id." AND group_id=".$field_group_id);
if ($fquery->num_rows() > 0)
{
foreach($fquery->result_array() as $row)
{
array_push($field_array, "field_id_".$row['field_id']);
}
}
$results = $this->EE->db->query("SELECT * FROM exp_channel_data WHERE site_id=".$site_id." AND channel_id=".$channel_id." AND entry_id=".$entry_id." LIMIT 1");
if ($results->num_rows() > 0){
foreach($results->result_array() as $r => $key)
{
$result_array = $key;
}
}
//print_r(array_merge($field_array,$result_array));
$s = array_search('field_id_17', $result_array);
 
foreach($field_array as $field => $k)
{
if($k !="field_id_17"){
$final_array[$k] = $result_array[$k];
}
}
//print_r($final_array);
$percentage = sizeof(array_filter($final_array))/sizeof($final_array) * 100;
$percentage = round($percentage/5)*5;
if($percentage > 95){
$this->return_data="";
}else{
$this->return_data = '<p>Your profile is '.(round($percentage/5)*5).'% complete</p>';
}
return $this->return_data;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.