Jump to content

Merging Functions Together To Work As One


Xtremer360

Recommended Posts

I'm trying to figure out a way I can do this task with dealing with personal messages content on my site. As of right now I'm trying to put my functions together so that all my types of functions can work together to just run the get_messages function. ONly thing I'm having issues with is whte get_last_5_personal_messages function because this is the only one function that exists across my site. All others only appear when the personal messages box is accessed on the site.

 

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Personalmessages extends CI_Controller {

public function __construct()
{
parent::__construct();
}

public function index()
{
redirect('kowmanager/personalmessages/inbox/');
}

public function inbox($display = NULL, $datetime_format = NULL)
{
$message_box_messages = array();
$css_page_addons = '';
$js_page_addons = '';
$meta_tag_addons = '';
$site_title = 'KOW Manager Personal Messages';

$user_data = $this->users_model->is_logged_in($this->session->userdata('xtr'));

if ($user_data === FALSE)
{
redirect('login', 'refresh');
}
else
{
$body_content = $this->config->item('themes_path').'/'.$this->config->item('default_theme').'/cpanel/view_messages';
$body_type = 'full';
$geo_data = $this->functions_model->geo_matching();

/*
* Gets the last 5 messages that were recieved.
*
@param integer $user_data->user_id User ID of the logged in user.
@param integer or empty Represents the number of messages to retrieve. Empty represents getting all messages.
@param integer $geo_data['zipz']['timezone'] The time offset of the user logged in based on his timezone.
@param string inbox or outbox Tells the function which type of messages to retrieve.
@param string d F Y g:i a Tells how to format the datetime_sent in the get_personal_messages functions.
@param empty.
*/
$last_5_personal_messages = $this->messages_model->get_personal_messages($user_data->user_id, 5, $geo_data['zipz']['timezone'], 'inbox', 'd F Y g:i a', '');

/*
* Grabs messages for the logged in user.
*
@param integer $user_data->user_id User ID of the logged in user.
@param integer or empty Represents the number of messages to retrieve. Empty represents getting all messages.
@param integer $geo_data['zipz']['timezone'] The time offset of the user logged in based on his timezone.
@param string inbox or outbox Tells the function which type of messages to retrieve.
@param string $datetime_format Tells how to format the datetime_sent in the get_personal_messages functions. Specified from the type function.
@param array Sends a type of message(today, last_week, this_week, important) and a values to look for.
*/
$personal_messages = $this->messages_model->get_personal_messages($user_data->user_id,'', $geo_data['zipz']['timezone'], 'inbox', $datetime_format, $display);
}

if (count($message_box_messages) !== 0)
{
$message_boxes = $this->functions_model->build_message_boxes_output(array('display' => 'show', 'message' => $message_box_messages));
}
else
{
$message_boxes = array('display' => 'none');
}

$meta_tags = $this->functions_model->meta_tags();

if (isset($site_title) && (empty($site_title)))
{
$site_title = $this->functions_model->site_title();
}

$this->data['user_data'] = $user_data;
$this->data['last_5_personal_messages'] = $last_5_personal_messages;
$this->data['personal_messages'] = $personal_messages;
$this->data['notifications'] = $this->site_model->get_notifications();
$this->data['server_data'] = $this->server_model->get_server_data();
$this->data['site_data'] = $this->site_model->get_site_data();
$this->data['message_boxes'] = $message_boxes;
$this->data['css_page_addons'] = $css_page_addons;
$this->data['js_page_addons'] = $js_page_addons;
$this->data['site_title'] = $site_title;
$this->data['body_content'] = $body_content;
$this->data['body_type'] = $body_type;
$this->data['meta_tags'] = $meta_tags;
$this->data['site_url'] = $this->functions_model->site_url();
$this->load->view($this->config->item('themes_path').'/'.$this->config->item('default_theme').'/cpanel/template/index', $this->data);
}

public function today()
{
$today = date('Y-m-d', time());
$start_range = $today.' 00:00:00';
$end_range = $today. ' 23:59:59';
$this->inbox(array('type' => 'today', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'H:s:i a');
}

public function thisweek()
{

$start_range = $today.' 00:00:00';
$end_range = $today. ' 23:59:59';
$this->inbox(array('type' => 'thisweek', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'M d');
}

public function lastweek()
{
$this->inbox(array('type' => 'lastweek', 'values' => array('start_time' => $start_range, 'end_time' => $end_range)), 'M d');
}

public function important()
{
$this->inbox(array('type' => 'important', 'values' => 0), '')
}

}

/* End of file personalmessages.php */
/* Location: ./application/controllers/personalmessages.php */

 

Messags Model/get_personal_messages

 

/**
* Gets all or last $x number of personal messages of the specified user
*
* @param integer $user_id User ID of the user specified
* @param integer $limit Limit of how many messages to retrieve
* @param integer $timezone The timezone offset of the user's geo location
* @param string $box Loading either the inbox or outbox of messages
* @param string $date_format The format for which the date needs to be ouputted
* @param array $display Tells what kind of messages to retrieve (important or specific datetime or datetime range)
* @return object/NULL
*/
public function get_personal_messages($user_id, $limit = NULL, $timezone, $box, $date_format, $display = NULL)
{
$this->db->select('personal_messages.message_id');
$this->db->select('personal_messages.subject');
$this->db->select('personal_messages.datetime_sent');
$this->db->select('personal_messages.attachments');
$this->db->select('personal_messages.priority');
$this->db->select('personal_messages.message_content');
if ($box == 'inbox')
{
$this->db->select('personal_messages.to_read AS message_read');
}
else
{
$this->db->select('personal_messages.from_read AS message_read');
}
if ($box == 'inbox')
{
$this->db->select('personal_messages.is_inbox_favorite AS is_favorite');
}
else
{
$this->db->select('personal_messages.is_outbox_favorite AS is_favorite');
}
$this->db->select('CONCAT(users.first_name, " ", users.last_name) AS sender_name', FALSE);
$this->db->select('users.email_address AS sender_email_address');
$this->db->select('user_profiles.user_avatar AS sender_avatar');
$this->db->from('personal_messages');
$this->db->join('users', 'users.user_id = personal_messages.from_user_id');
$this->db->join('user_profiles', 'users.user_id = user_profiles.user_id');
if ($display['type'] == 'today')
{
$this->db->where('datetime_sent >', $display['values']['start_time']);
$this->db->where('datetime_sent <', $display['values']['end_time']);
}
elseif ($display['type'] == 'this_week')
{

}
elseif ($display['type'] == 'last_week')
{

}
if ($box == 'inbox')
{
$this->db->where('personal_messages.to_user_id', $user_id);
}
else
{
$this->db->where('personal_messages.from_user_id', $user_id);
}
if ($limit != NULL)
{
if (is_numeric($limit))
{
$this->db->limit($limit);
}
}
$query = $this->db->get();
$personal_messages = array();
$personal_messages['messages'] = $query->result();
if (count($personal_messages['messages']) > 0)
{
for ($x = 0; $x < count($personal_messages['messages']); $x++)
{
$attachments = $personal_messages['messages'][$x]->attachments;
if ($this->functions_model->null_check($attachments) === FALSE)
{
$attachments = json_decode($attachments, TRUE);
for ($i = 0; $i < count($attachments); $i++)
{
$file_name = $attachments[$i];
$attachments[$i] = array();
$attachments[$i]['file_name'] = $file_name;
if ($this->functions_model->is_file('assets/downloads/'.$file_name, FALSE) === TRUE)
{
$attachments[$i]['is_file'] = TRUE;
$file_size = $this->functions_model->bytes_to_size(filesize('assets/downloads/'.$file_name));
$attachments[$i]['file_size'] = $file_size;
$attachments[$i]['file_location'] = 'assets/downloads/'.$file_name;			
}
else
{
		 $attachments[$i]['is_file'] = FALSE;
			 }
		 }
		 $personal_messages['messages'][$x]->attachments = $attachments;
	 }
$personal_messages['messages'][$x]->datetime_sent = $this->functions_model->actual_time('Y-m-d g:i:s', $timezone, strtotime($personal_messages['messages'][$x]->datetime_sent));
echo $date_format;
die();
$personal_messages['messages'][$x]->datetime_sent = date($date_format, strtotime($personal_messages['messages'][$x]->datetime_sent));
print_r($personal_messages);
die();

$personal_messages['messages'][$x]->datetime_sent = $this->functions_model->time_since(strtotime($personal_messages['messages'][$x]->datetime_sent));
$avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
if ($this->functions_model->null_check($personal_messages['messages'][$x]->sender_avatar) === FALSE)
{
if ($this->functions_model->is_file('assets/themes/supr/images/avatars/'.$personal_messages['messages'][$x]->sender_avatar, FALSE) === TRUE)
{
$avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/'.$personal_messages['messages'][$x]->sender_avatar;
}
}
$personal_messages['messages'][$x]->sender_avatar = $avatar;
}
$personal_messages['total_unread_messages'] = $this->get_users_unread_messages($user_id);
}
return $personal_messages;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.