You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
richdocuments/lib/op.php

69 lines
1.6 KiB
PHTML

11 years ago
<?php
11 years ago
/**
* 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.
*/
11 years ago
namespace OCA\Office;
class Op {
11 years ago
11 years ago
public static function add($esId, $memberId, $opspec){
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_op` (`es_id`, `member`, `opspec`) VALUES (?, ?, ?) ');
$query->execute(array(
$esId,
11 years ago
$memberId,
$opspec,
11 years ago
));
// throw something - if query fails - thats fatal
return \OCP\DB::insertid(`*PREFIX*office_op`);
11 years ago
}
11 years ago
public static function addOpsArray($esId, $memberId, $ops){
$lastSeq = "";
11 years ago
foreach ($ops as $op) {
$lastSeq = self::add($esId, $memberId, json_encode($op));
}
return $lastSeq;
}
/**
* @returns "" when there are no Ops, or the seq of the last Op
*/
11 years ago
public static function getHeadSeq($esId){
$query = \OCP\DB::prepare('SELECT `seq` FROM `*PREFIX*office_op` WHERE `es_id`=? ORDER BY `seq` DESC LIMIT 1');
$result = $query->execute(array(
$esId
))
->fetchOne()
;
11 years ago
return !$result ? "" : $result;
}
public static function getOpsAfterJson($esId, $seq){
$ops = self::getOpsAfter($esId, $seq);
11 years ago
$ops = array_map(
function($x){return json_decode($x['opspec']);},
$ops
11 years ago
);
11 years ago
return $ops;
11 years ago
}
public static function getOpsAfter($esId, $seq){
11 years ago
if ($seq == ""){
$seq = -1;
}
$query = \OCP\DB::prepare('SELECT `opspec` FROM `*PREFIX*office_op` WHERE `es_id`=? AND `seq`>? ORDER BY `seq` ASC');
$result = $query->execute(array($esId, $seq));
return $result->fetchAll();
11 years ago
}
11 years ago
}