Created
December 14, 2011 18:16
-
-
Save rmdort/1477785 to your computer and use it in GitHub Desktop.
EE_addon Percentage Complete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment