richdocuments/lib/session.php

61 lines
1.6 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
2013-08-09 18:29:36 +03:00
public static function add($genesis, $hash, $documentPath){
2013-08-09 17:29:18 +03:00
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`, `document_path`) VALUES (?, ?, ?, ?, ?) ');
2013-08-07 02:22:21 +03:00
$data = array(
2013-08-08 18:31:47 +03:00
'es_id' => self::getUniqueSessionId(),
2013-08-08 14:44:13 +03:00
'genesis_url' => $genesis,
'genesis_hash' => $hash,
2013-08-09 17:29:18 +03:00
'owner' => \OCP\User::getUser(),
'document_path' => $documentPath
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;
}
2013-08-09 18:29:36 +03:00
public static function getAll(){
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session`');
$result = $query->execute();
return $result->fetchAll();
}
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();
}
public static function getSessionByOwnerAndGenesis($uid, $url){
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ? AND `owner`= ? ');
$result = $query->execute(array($url, $uid));
return $result->fetchRow();
}
2013-08-08 18:31:47 +03:00
protected static function getUniqueSessionId(){
do {
$id = \OC_Util::generate_random_bytes(30);
} while (self::getSession($id));
return $id;
2013-08-07 02:22:21 +03:00
}
2013-07-19 18:52:52 +03:00
}