/**
  * Сохраняет расписание передач в заданном интервале в БД
  * @param \DateTime $fromTime
  * @param \DateTime $toTime
  */
 public function saveSchedules(\DateTime $fromTime, \DateTime $toTime)
 {
     try {
         $programs = $this->scheduleSoapClient->getInfoByTime($fromTime->format('Y-m-d H:i:s'), $toTime->format('Y-m-d H:i:s'));
         $programsArray = json_decode($programs, true);
     } catch (\Exception $e) {
         // TODO: Залогировать ошибку
         return;
     }
     foreach ($programsArray as $startTime => $program) {
         $this->db->insertArray('programs', ['time' => $startTime, 'program' => $program]);
     }
 }
Example #2
0
 /**
  * 启动程序
  * @return [type] [description]
  */
 public function start()
 {
     $this->init();
     //数据库初使化
     DB::init();
     //路由初使化
     Router::init();
     //TODO:: 还需要支持自定义的路由
     if (file_exists(APP_PATH . 'config/Router.php')) {
     }
     //调用控制器
     $controllerFile = APP_PATH . MODULE . 'controller/' . CONTROLLER . CLASS_EXT;
     if (file_exists($controllerFile)) {
         include_once $controllerFile;
         $controller = MODULE ? MODULE : "Controller" . '\\' . CONTROLLER;
         $action = ACTION;
         $obj = new $controller();
         if (method_exists($obj, $action)) {
             $obj->{$action}();
         } else {
             throw new \Exception("非法操作: " . ACTION);
         }
     } else {
         throw new \Exception("无法加载控制器: " . CONTROLLER);
     }
 }
Example #3
0
 /**
  * Update last activity time
  * 
  * @param int $idUser
  * @param string $sessionHash
  */
 public function updateSession($idUser, $sessionHash = null)
 {
     if (!empty($idUser)) {
         $update = array('lastActivityTime' => DB::sqlEval('NOW()'));
         if ($sessionHash !== null) {
             $update['lastSession'] = $sessionHash;
         }
         $this->db->update($this->table, $update, $this->primary_key . ' = %i', $idUser);
     }
 }
Example #4
0
 public function index()
 {
     $info = DB::fetch_first('select * from %t where openid = %s', array('online', session('openid')));
     if (!$info['uid']) {
         $this->redirect('Login/index');
     }
     $member = DB::fetch_first("select * from %t where id = %d", array('member', $info['uid']));
     $info['avatar'] = $member['figureurl'] ? $member['figureurl'] : 'http://tp3.sinaimg.cn/1221788390/180/1289279591/0';
     include template();
 }
Example #5
0
 protected function __construct()
 {
     parent::__construct();
     $this->db = \Core\DB::getInstance();
     $words = preg_split("/(?=[A-Z]+)/", get_class($this), -1, PREG_SPLIT_NO_EMPTY);
     $words = array_slice($words, 1);
     foreach ($words as $i => $word) {
         $words[$i] = strtolower($word);
     }
     $this->table = str_replace("model\\", "", join("_", $words));
 }
Example #6
0
 private static function insert(&$set)
 {
     \Core\DB::$db->beginTransaction();
     $PK = \Core\DB::nextPK(static::table(), static::PK());
     $SQL = 'INSERT INTO ' . static::table() . ' ';
     $columns = [static::PK()];
     $params = [':' . static::PK() => $PK];
     foreach ($set as $col => $val) {
         $columns[] = $col;
         $params[':' . $col] = $val;
     }
     $SQL .= '(' . implode(',', $columns) . ') ' . 'VALUES (' . implode(',', array_keys($params)) . ')';
     $sInsert = \Core\DB::$db->prepare($SQL);
     if (!$sInsert->execute($params)) {
         http_response_code(500) && exit('Failed to create object :/');
     }
     $sInsert->closeCursor();
     \Core\DB::$db->commit();
     return $PK;
 }
Example #7
0
 /**
  * @param $filePath
  * @param \DateTime $videoStartTime
  * @param \DateTime $videoEndTime
  */
 private function saveVideoInfo($filePath, \DateTime $videoStartTime, \DateTime $videoEndTime)
 {
     $this->db->insertArray('video', ['start_time' => $videoStartTime->format('Y-m-d H:i:s'), 'end_time' => $videoEndTime->format('Y-m-d H:i:s'), 'url' => str_replace($this->storagePath, '', $filePath)]);
 }
Example #8
0
<?php

\Core\DI::bind("App\\Models\\Game\\GameModelInterface", function () {
    $db = \Core\DB::getInstance();
    return new \App\Models\Game\GameModel(new \App\Domain\Logic\GameLogic(new \App\Domain\Factories\ShipFactory()), new \App\Domain\Repository\Game\GameRepository(new App\Persistence\Database\GamePersistence($db), new App\Persistence\Database\ShotPersistence($db)), \Core\Session::getInstance());
});
Example #9
0
 public function __construct()
 {
     $this->db = DB::getInstance();
     $this->redis = new Redis();
 }
Example #10
0
 public function dispatchLoopStartup(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
 {
     \Core\DB::initialize(get_config('application.db'));
 }
Example #11
0
<?php

namespace Test;

require_once 'Core/DB.class.php';
use Core\DB;
$a = DB::getDb();
$b = $a->table('album')->where(array('album_id<10'))->order(array('artist_id DESC'))->select();
var_dump($b);
Example #12
0
 /**
  * Construct
  */
 public function __construct()
 {
     $this->db = DB::getMDB();
 }
Example #13
0
 /**
  * Custom production database error handlers
  */
 private function setDatabaseErrorHandlers()
 {
     DB::$error_handler = function ($params) {
         /* @var $e Exception */
         $e = new Exception();
         $backtrace = preg_split("/[\r\n]+/", $e->getTraceAsString());
         //remove core traces
         foreach ($backtrace as $key => $line) {
             if (strpos($line, 'internal function') || strpos($line, 'DB.php')) {
                 unset($backtrace[$key]);
             } else {
                 break;
             }
         }
         //remove trace auto increment
         foreach ($backtrace as &$line) {
             $line = preg_replace("/^#\\d+ /", '', $line);
         }
         $backtrace = array_slice($backtrace, 0, -2);
         trigger_error(implode(PHP_EOL, $params) . PHP_EOL . implode(PHP_EOL, $backtrace), E_USER_WARNING);
     };
     DB::$nonsql_error_handler = function ($params) {
         trigger_error(implode(PHP_EOL, $params), E_USER_WARNING);
         header("HTTP/1.1 500 Internal Server Error");
         readfile(BASE_PATH . DS . '500.html');
         exit;
     };
 }
Example #14
0
 /**
  * QQ登陆回调函数
  */
 public function qqlogin()
 {
     $api = Config::get('global', 'qqconnect');
     if ($_REQUEST['state'] == session('state')) {
         $callback = url('qqlogin', '', '', 1);
         $token_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&" . "client_id=" . $api["appid"] . "&redirect_uri=" . urlencode($callback) . "&client_secret=" . $api["appkey"] . "&code=" . $_REQUEST["code"];
         $response = file_get_contents($token_url);
         if (strpos($response, "callback") !== false) {
             $lpos = strpos($response, "(");
             $rpos = strrpos($response, ")");
             $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
             $msg = json_decode($response);
             if (isset($msg->error)) {
                 echo "<h3>error:</h3>" . $msg->error;
                 echo "<h3>msg  :</h3>" . $msg->error_description;
                 exit;
             }
         }
         $params = array();
         parse_str($response, $params);
         session('access_token', $params["access_token"]);
         $this->get_openid();
         $data = $this->get_user_info();
         $data['openid'] = session('openid');
         if ($info = DB::fetch_first("select * from %t where openid=%s", array('member', $data['openid']))) {
             $id = $info['id'];
         } else {
             $data['figureurl'] = $data['figureurl_1'];
             $id = DB::insert('member', $data);
             $info = $data;
         }
         if ($id) {
             //保存登陆状态
             $this->loginState($info);
             $this->redirect('index', 'openid=' . $info['openid']);
             exit;
         }
         $this->redirect('login');
     } else {
         echo "need login";
     }
 }
Example #15
0
 public function __construct()
 {
     $this->db = DB::getInstance();
 }
Example #16
0
 /**
  * 异步任务
  *
  * @param $serv
  * @param $task_id
  * @param $from_id
  * @param $data
  */
 public function task($serv, $task_id, $from_id, $data)
 {
     static $db = null;
     static $cache = null;
     if (!$db) {
         $db = new DB();
     }
     if (!$cache) {
         $cache = new Cache();
     }
     $d = json_decode($data, true);
     $type = $d['type'];
     unset($d['type']);
     //获取在线用户列表
     $onlines = $db->fetch_all('select * from %t where 1', array('online'));
     $notme = false;
     $message = "";
     switch ($type) {
         //处理消息
         case 'message':
             #1 将用户消息入库
             $db->insert("message", $d);
             $notme = true;
             $message = $d['msg'];
             $type = self::TYPE_NORMAL;
             break;
             //推送在线会员列表
         //推送在线会员列表
         case 'pushOnline':
             $message = $db->fetch_all("select * from %t where 1", array('online'));
             $type = self::TYPE_PUSH_ONLINEMEMBERS;
             //给单独用户推送在线会员列表
             if ($d['sendto']) {
                 $msg = $this->createRecMsg($message, $type);
                 $serv->send((int) $d['sendto'], $this->frame($msg), $from_id);
             }
             break;
         case 'login':
             if ($db->fetch_first("select * from %t where openid=%s", array('online', $d['openid']))) {
                 $db->update('online', array('fd' => $d['fd']), " openid='" . $d['openid'] . "'");
                 $cache->set($d['fd'], $d['openid']);
             } else {
                 $serv->close($d['fd']);
             }
             break;
         case 'logout':
             $cache->delete($d['fd']);
             break;
     }
     //检查登陆授权
     var_dump($cache->get($d['fd']));
     //		if(!$cache->get($d['fd'])) { $serv->close($d['fd']); }
     //将消息发给在线用户
     if ($onlines) {
         echo date("H:i:s") . " : 当前有 " . count($onlines) . " 人在线,开始发送消息 == " . json_encode($message) . " \n";
         foreach ($onlines as $key => $val) {
             if ($notme && $val['fd'] == $d['fd']) {
                 continue;
             }
             $msg = $this->createRecMsg($message, $type, $val['fd']);
             //开始发送消息
             $serv->send((int) $val['fd'], $this->frame($msg), $from_id);
         }
     } else {
         echo "没有在线用户";
     }
 }
Example #17
0
 function __construct()
 {
     parent::__construct();
 }
Example #18
0
require __DIR__ . '/core/DB.PHP';
require __DIR__ . '/core/Config.php';
use core\DB;
//	$redis = new \Redis;
//	$redis -> connect('localhost','6379', 0.0);
//	$arr=$redis->lRange("queue_service_req",0,-1);
//	var_dump($arr);
//
//
//	$arr=$redis->lRange("queue_service_ing",0,-1);
//	var_dump($arr);
//
//
//	$redis->delete("key1");
//	$redis->lPush('key1', 'sam');
//	$redis->lPush('key1', 'luke');
//	$redis->lPush('key1', 'boss');
//	$redis->lPush('key1', 'alex');
//
//var_dump($redis->lRange('key1', 0, -1)); /* array('A', 'A', 'C', 'B', 'A') */
//$redis->lRem('key1', 'luke', 1); /* 2 */
//var_dump($redis->lRange('key1', 0, -1)); /* array('C', 'B', 'A') */
//$redis->lRem('queue_service_ing','sam',1);
$db = DB::getInstance();
$from_name = 'sam';
$sql = "select fd from hx_user as u,(select to_name from hx_service where from_name='{$from_name}' order by add_time desc) as s where u.u_username=s.to_name";
// echo $sql."<br>";
$result = $db->fetch_first($sql);
// $rst=$result->fetch_array(MYSQLI_ASSOC);
var_dump($result['fd']);
Example #19
0
 function commit()
 {
     DB::commit();
     $this->committed = true;
 }
Example #20
0
 /**
  * @return bool
  */
 public function delete()
 {
     $data = [':id' => $this->data['id']];
     $sql = '
         DELETE FROM' . ' ' . static::$schema['table'] . '
         WHERE id = :id
     ';
     $db = DB::getInstance();
     return $db->execute($sql, $data);
 }