richdocuments/lib/session.php

56 lines
1.4 KiB
PHP
Raw Normal View History

2013-07-19 18:52:52 +03:00
<?php
2013-08-08 00:22:21 +03:00
/**
* ownCloud - Office App
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
2013-07-19 18:52:52 +03:00
namespace OCA\Office;
class Session {
2013-08-07 18:02:20 +03:00
public static function getAllSessions(){
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session`');
$result = $query->execute();
return $result->fetchAll();
}
2013-07-19 20:44:18 +03:00
public static function getSession($id){
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `es_id`= ?');
$result = $query->execute(array($id));
return $result->fetchRow();
}
2013-08-07 21:14:36 +03:00
public static function getSessionByPath($url){
2013-08-07 02:22:21 +03:00
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ?');
$result = $query->execute(array($url));
return $result->fetchRow();
}
2013-08-08 00:08:20 +03:00
public static function addSession($genesis, $hash){
2013-07-19 20:44:18 +03:00
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`) VALUES (?, ?, ?, ?) ');
2013-08-07 02:22:21 +03:00
$data = array(
2013-08-08 14:44:13 +03:00
'es_id' => self::getSessionId(),
'genesis_url' => $genesis,
'genesis_hash' => $hash,
'owner' => \OCP\User::getUser()
2013-08-07 02:22:21 +03:00
);
2013-08-08 14:44:13 +03:00
$result = $query->execute(array_values($data));
2013-08-07 02:22:21 +03:00
if ($result){
return $data;
}
return false;
}
protected static function getSessionId(){
2013-08-07 10:38:00 +02:00
return (string) time();
2013-08-07 02:22:21 +03:00
}
2013-07-19 18:52:52 +03:00
}