This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ require_once 'class.tlondata.php'; TlonDocument::$TABLE = new TlonDataTable('tl_document', 'id, title, content, lastmodified, parent'); class TlonDocument { public static $TABLE = null; public static function add($title, $content, $parent = -1) { return TlonData::insert(self::$TABLE, array(null, $title, $content, time(), $parent)); } public static function delete($document_id) { return TlonData::delete(self::$TABLE, TlonDataComparison::equals('id', $document_id)); } public static function getByID($id) { if ($docs = TlonData::select(self::$TABLE, 'id', $id)) { return $docs[0];
private function integrateMessages($document_id) { $dbg = array('docid' => $document_id); if (($msgs = TlonMessage::getUnappliedByDocumentID($document_id)) && ($doc = $this->_get($document_id))) { $dbg['num_messages'] = count($msgs); $wd = new WootDocument(new WootID(0, 0), $doc['title'], array_map(array($this, 'arrToWootChar'), $doc['content'])); $dbg['before'] = $this->unserialize($doc['content']); foreach ($msgs as $msg) { $applied = true; $ops = $this->unserialize($msg['operations']); foreach ($ops as $op) { $r = $op['op'] == WootMessage::OP_DEL ? $wd->integrateDelete($this->arrToWootChar($op['char'])) : $wd->integrateInsert($this->arrToWootChar($op['char']), $this->arrToWootChar($op['prev']), $this->arrToWootChar($op['next'])); if ($r === false) { $applied = false; } } if ($applied) { TlonMessage::setApplied($msg['message_id']); } } $dbg['after'] = array_map(array($this, 'wootCharToArr'), $wd->content()); $doc['content'] = $this->serialize(array_map(array($this, 'wootCharToArr'), $wd->content())); $dbg['res'] = TlonDocument::update($document_id, $doc['title'], $doc['content'], $doc['parent']); } $this->cleanMessages($document_id); return $dbg; }