示例#1
0
 public function __construct()
 {
     $this->feather = \Slim\Slim::getInstance();
     $this->config = $this->feather->config;
     $this->user = $this->feather->user;
     $this->request = $this->feather->request;
     $this->hooks = $this->feather->hooks;
     DB::configure('id_column_overrides', array('pms_data' => array('conversation_id', 'user_id')));
 }
示例#2
0
 public static function init_db(array $config, $log_queries = false)
 {
     $config['db_prefix'] = !empty($config['db_prefix']) ? $config['db_prefix'] : '';
     switch ($config['db_type']) {
         case 'mysql':
             DB::configure('mysql:host=' . $config['db_host'] . ';dbname=' . $config['db_name']);
             DB::configure('driver_options', array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
             break;
         case 'sqlite':
         case 'sqlite3':
             DB::configure('sqlite:./' . $config['db_name']);
             break;
         case 'pgsql':
             DB::configure('pgsql:host=' . $config['db_host'] . 'dbname=' . $config['db_name']);
             break;
     }
     DB::configure('username', $config['db_user']);
     DB::configure('password', $config['db_pass']);
     DB::configure('prefix', $config['db_prefix']);
     if ($log_queries) {
         DB::configure('logging', true);
     }
     DB::configure('id_column_overrides', array($config['db_prefix'] . 'groups' => 'g_id'));
 }
 public function addMessage(array $data = array(), $conv_id = null, array $uid = array())
 {
     $add = DB::for_table('pms_messages')->create()->set($data)->set('conversation_id', $conv_id);
     $add->save();
     $update_data = ['last_post_id' => $add->id()];
     // If it is a new conversation:
     if (!empty($uid)) {
         $update_data['first_post_id'] = $add->id();
     }
     $update = DB::for_table('pms_conversations')->find_one($conv_id)->set($update_data);
     // Increment replies count
     if (empty($uid)) {
         $update->set_expr('num_replies', 'num_replies+1');
     }
     $update = $update->save();
     DB::configure('id_column', array('conversation_id', 'user_id'));
     if (!empty($uid)) {
         // New conversation
         foreach ($uid as $user) {
             $notifs = DB::for_table('pms_data')->create()->set(array('conversation_id' => $conv_id, 'user_id' => $user, 'viewed' => $user == User::get()->id ? '1' : '0'))->save();
         }
     } else {
         // Reply
         $notifs = DB::for_table('pms_data')->where('conversation_id', $conv_id)->where_not_equal('user_id', User::get()->id)->find_result_set();
         $notifs->set('viewed', 0)->save();
     }
     return $add && $update && $notifs ? $add->id() : false;
 }