Conflicts:
	application/core/FHC_Model.php
This commit is contained in:
Paminger
2016-06-10 15:41:09 +02:00
48 changed files with 990 additions and 1253 deletions
-170
View File
@@ -1,170 +0,0 @@
<?php
/**
* FH-Complete
*
* @package FHC-Helper
* @author FHC-Team
* @copyright Copyright (c) 2016 fhcomplete.org
* @license GPLv3
* @link https://fhcomplete.org
* @since Version 1.0.0
* @filesource
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* FHC-Seed Library
*
* @package FH-Complete
* @subpackage DB
* @category Library
* @author FHC-Team
* @link http://fhcomplete.org/user_guide/libraries/fhc_seed.html
*/
// ------------------------------------------------------------------------
class FHC_Seed
{
/**
* Path to seed classes
*
* @var string
*/
protected $_seed_path = NULL;
/**
* Seed basename regex
*
* @var string
*/
protected $_seed_regex = '/^\d{3}_(\w+)$/';
/**
* Initialize Seed Class
*
* @param array $config
* @return void
*/
public function __construct($config = array())
{
// Only run this constructor on main library load
if ( ! in_array(get_class($this), array('FHC_Seed', config_item('subclass_prefix').'Seed'), TRUE))
{
return;
}
foreach ($config as $key => $val)
{
$this->{'_'.$key} = $val;
}
log_message('info', 'Seed Class Initialized');
// If not set, set it
$this->_seed_path !== '' OR $this->_seed_path = APPPATH.'seeds/';
// Add trailing slash if not set
$this->_seed_path = rtrim($this->_seed_path, '/').'/';
// Load seed language
$this->lang->load('seed');
}
/**
* Seeds DB with Testdata
*
* @param string $name
* @return bool
*/
function seed($name = null)
{
$seeds = $this->find_seeds();
if (empty($seeds))
{
$this->_error_string = $this->lang->line('seed_none_found');
return FALSE;
}
$method = 'seed';
$pending = array();
foreach ($seeds as $number => $file)
{
include_once($file);
$class = 'Seed_'.ucfirst(strtolower($this->_get_seed_name(basename($file, '.php'))));
// Validate the seed file structure
if ( ! class_exists($class, FALSE))
{
$this->_error_string = sprintf($this->lang->line('seed_class_doesnt_exist'), $class);
return FALSE;
}
// method_exists() returns true for non-public methods,
// while is_callable() can't be used without instantiating.
// Only get_class_methods() satisfies both conditions.
elseif ( ! in_array($method, array_map('strtolower', get_class_methods($class))))
{
$this->_error_string = sprintf($this->lang->line('seed_missing_'.$method.'_method'), $class);
return FALSE;
}
$pending[$number] = array($class, $method);
}
// Now just run the necessary seeds
foreach ($pending as $number => $seed)
{
log_message('debug', 'Seeding '.$method);
$seed[0] = new $seed[0];
call_user_func($seed);
}
}
/**
* Retrieves list of available seed files
*
* @return array list of seed file paths sorted by version
*/
public function find_seeds()
{
$seeds = array();
// Load all *_*.php files in the seeds path
foreach (glob($this->_seed_path.'*_*.php') as $file)
{
$name = basename($file, '.php');
// Filter out non-seed files
if (preg_match($this->_seed_regex, $name))
{
$number = $this->_get_seed_number($name);
// There cannot be duplicate seed numbers
if (isset($seeds[$number]))
{
$this->_error_string = sprintf($this->lang->line('seed_multiple_version'), $number);
show_error($this->_error_string);
}
$seeds[$number] = $file;
}
}
ksort($seeds);
return $seeds;
}
/**
* Extracts the seed number from a filename
*
* @param string $seed
* @return string Numeric portion of a seed filename
*/
protected function _get_seed_number($seed)
{
return sscanf($seed, '%[0-9]+', $number)
? $number : '0';
}
}
-448
View File
@@ -1,448 +0,0 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name: Messaging Library for CodeIgniter
*
*
*/
class Messaging
{
public function __construct()
{
require_once APPPATH.'config/message.php';
$this->ci =& get_instance();
$this->ci->load->model('message/message_model');
$this->ci->load->helper('language');
$this->ci->lang->load('message');
}
// ------------------------------------------------------------------------
/**
* get_message() - will return a single message, including the status for specified user.
*
* @param integer $msg_id EQUIRED
* @param integer $user_id REQUIRED
* @return array
*/
function get_message($msg_id, $user_id)
{
if (empty($msg_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
}
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if ($message = $this->ci->message_model->get_message($msg_id, $user_id))
{
return $this->_success($message);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* get_full_thread() - will return a entire thread, including the status for specified user.
*
* @param integer $thread_id REQUIRED
* @param integer $user_id REQUIRED
* @param boolean $full_thread OPTIONAL - If true, user will also see messages from thread posted BEFORE user became participant
* @param string $order_by OPTIONAL
* @return array
*/
function get_full_thread($thread_id, $user_id, $full_thread = FALSE, $order_by = 'ASC')
{
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if ($message = $this->ci->message_model->get_full_thread($thread_id, $user_id, $full_thread, $order_by))
{
return $this->_success($message);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* get_all_threads() - will return all threads for user, including the status for specified user.
*
* @param integer $user_id REQUIRED
* @param boolean $full_thread OPTIONAL - If true, user will also see messages from thread posted BEFORE user became participant
* @param string $order_by OPTIONAL
* @return array
*/
function get_all_threads($user_id, $full_thread = FALSE, $order_by = 'ASC')
{
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
$message = $this->ci->message_model->get_all_threads($user_id, $full_thread, $order_by);
if (is_array($message))
{
return $this->_success($message);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* get_all_threads_grouped() - will return all threads for user, including the status for specified user.
* - messages are grouped in threads.
*
* @param integer $user_id REQUIRED
* @param boolean $full_thread OPTIONAL - If true, user will also see messages from thread posted BEFORE user became participant
* @param string $order_by OPTIONAL
* @return array
*/
function get_all_threads_grouped($user_id, $full_thread = FALSE, $order_by = 'ASC')
{
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
$message = $this->ci->message_model->get_all_threads($user_id, $full_thread, $order_by);
if (is_array($message))
{
$threads = array();
foreach ($message as $msg)
{
if ( ! isset($threads[$msg['thread_id']]))
{
$threads[$msg['thread_id']]['thread_id'] = $msg['thread_id'];
$threads[$msg['thread_id']]['messages'] = array($msg);
}
else
{
$threads[$msg['thread_id']]['messages'][] = $msg;
}
}
return $this->_success($threads);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* update_message_status() - will change status on message for particular user
*
* @param integer $msg_id REQUIRED
* @param integer $user_id REQUIRED
* @param integer $status_id REQUIRED - should come from config/message.php list of constants
* @return array
*/
function update_message_status($msg_id, $user_id, $status_id )
{
if (empty($msg_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
}
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if (empty($status_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_STATUS_ID);
}
if ($this->ci->message_model->update_message_status($msg_id, $user_id, $status_id))
{
return $this->_success(NULL, MSG_STATUS_UPDATE);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* add_participant() - adds user to existing thread
*
* @param integer $thread_id REQUIRED
* @param integer $user_id REQUIRED
* @return array
*/
function add_participant($thread_id, $user_id)
{
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if ( ! $this->ci->message_model->valid_new_participant($thread_id, $user_id))
{
$this->_participant_error(MSG_ERR_PARTICIPANT_EXISTS);
}
if ( ! $this->ci->message_model->application_user($user_id))
{
$this->_participant_error(MSG_ERR_PARTICIPANT_NONSYSTEM);
}
if ($this->ci->message_model->add_participant($thread_id, $user_id ))
{
return $this->_success(NULL, MSG_PARTICIPANT_ADDED);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* remove_participant() - removes user from existing thread
*
* @param integer $thread_id REQUIRED
* @param integer $user_id REQUIRED
* @return array
*/
function remove_participant($thread_id, $user_id)
{
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if ($this->ci->message_model->remove_participant($thread_id, $user_id))
{
return $this->_success(NULL, MSG_PARTICIPANT_REMOVED);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* send_new_message() - sends new internal message. This function will create a new thread
*
* @param integer $sender_id REQUIRED
* @param mixed $recipients REQUIRED - a single integer or an array of integers, representing user_ids
* @param string $subject
* @param string $body
* @param integer $priority
* @return array
*/
function send_new_message($sender_id, $recipients, $subject = '', $body = '', $priority = PRIORITY_NORMAL)
{
if (empty($sender_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_SENDER_ID);
}
if (empty($recipients))
{
return array(
'err' => 1,
'code' => MSG_ERR_INVALID_RECIPIENTS,
'msg' => lang('mahana_'.MSG_ERR_INVALID_RECIPIENTS)
);
}
if ($thread_id = $this->ci->message_model->send_new_message($sender_id, $recipients, $subject, $body, $priority))
{
return $this->_success($thread_id, MSG_MESSAGE_SENT);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* reply_to_message() - replies to internal message. This function will NOT create a new thread or participant list
*
* @param integer $msg_id REQUIRED
* @param integer $sender_id REQUIRED
* @param string $subject
* @param string $body
* @param integer $priority
* @return array
*/
function reply_to_message($msg_id, $sender_id, $subject = '', $body = '', $priority = PRIORITY_NORMAL)
{
if (empty($sender_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_SENDER_ID);
}
if (empty($msg_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_MSG_ID);
}
if ($new_msg_id = $this->ci->message_model->reply_to_message($msg_id, $sender_id, $body, $priority))
{
return $this->_success($new_msg_id, MSG_MESSAGE_SENT);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* get_participant_list() - returns list of participants on given thread. If sender_id set, sender_id will be left off list
*
* @param integer $thread_id REQUIRED
* @param integer $sender_id REQUIRED
* @return array
*/
function get_participant_list($thread_id, $sender_id = 0)
{
if (empty($thread_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_THREAD_ID);
}
if ($participants = $this->ci->message_model-> get_participant_list($thread_id, $sender_id))
{
return $this->_success($participants);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
/**
* get_msg_count() - returns integer with count of message for user, by status. defaults to new messages
*
* @param integer $user_id REQUIRED
* @param integer $status_id OPTIONAL - defaults to "Unread"
* @return array
*/
function get_msg_count($user_id, $status_id = MSG_STATUS_UNREAD)
{
if (empty($user_id))
{
return $this->_invalid_id(MSG_ERR_INVALID_USER_ID);
}
if (is_numeric($message = $this->ci->message_model->get_msg_count($user_id, $status_id)))
{
return $this->_success($message);
}
// General Error Occurred
return $this->_general_error();
}
// ------------------------------------------------------------------------
// Private Functions from here out!
// ------------------------------------------------------------------------
/**
* Success
*
* @param mixed $retval
* @return array
*/
private function _success($retval = '', $message = MSG_SUCCESS)
{
return array(
'err' => 0,
'code' => MSG_SUCCESS,
'msg' => lang('mahana_' . $message),
'retval' => $retval
);
}
// ------------------------------------------------------------------------
/**
* Invalid ID
*
* @param integer config.php error code numbers
* @return array
*/
private function _invalid_id($error = '')
{
return array(
'err' => 1,
'code' => $error,
'msg' => lang('mahana_'.$error)
);
}
// ------------------------------------------------------------------------
/**
* Error Particpant Exists
*
* @return array
*/
private function _participant_error($error = '')
{
return array(
'err' => 1,
'code' => 1,
'msg' => lang('mahana_' . $error)
);
}
// ------------------------------------------------------------------------
/**
* General Error
*
* @return array
*/
private function _general_error()
{
return array(
'err' => 1,
'code' => MSG_ERR_GENERAL,
'msg' => lang('mahana_'.MSG_ERR_GENERAL)
);
}
}