Inheritance: extends CommonDBTM
示例#1
0
 /**
  * The function shows edit form and saves data on submit.
  * 
  * @access private
  * @param object $Page The Content Page object.
  * @return string The HTML code.
  */
 protected function initForm(Content_Page $Page)
 {
     if (isset($_POST['submit'])) {
         $Page->setPost($_POST);
         $fields = Error::test($Page);
         if (count($fields)) {
             $this->getView()->set('Error', 'Неверно заполены поля: ' . implode(', ', $fields));
         } else {
             if ($Page->save()) {
                 if ($Page->Module && $Page->Link) {
                     Router::attachPage($Page);
                 } else {
                     Router::detachPage($Page);
                 }
                 return $this->halt('', true);
             } else {
                 $this->getView()->set('Error', 'Ошибка записи данных: ' . $Page->getError() . "\n" . Database::getInstance()->getLastQuery());
             }
         }
     }
     $Document = new Document();
     $this->getView()->set('Documents', $Document->findList(array(), 'Position asc'));
     $this->getView()->set('Page', $Page);
     return $this->getView()->render();
 }
示例#2
0
 function testDocumentPdf()
 {
     $o = new Document();
     $o->slug = 'imagick-pdf';
     $o->suffixe = 'pdf';
     $o->storeFile(dirname(__FILE__) . '/images/multipage.pdf');
 }
 function saveFile($document, $portal = false)
 {
     global $sugar_config;
     $focus = new Document();
     if (!empty($document['id'])) {
         $focus->retrieve($document['id']);
     } else {
         return '-1';
     }
     if (!empty($document['file'])) {
         $decodedFile = base64_decode($document['file']);
         $this->upload_file->set_for_soap($document['filename'], $decodedFile);
         $ext_pos = strrpos($this->upload_file->stored_file_name, ".");
         $this->upload_file->file_ext = substr($this->upload_file->stored_file_name, $ext_pos + 1);
         if (in_array($this->upload_file->file_ext, $sugar_config['upload_badext'])) {
             $this->upload_file->stored_file_name .= ".txt";
             $this->upload_file->file_ext = "txt";
         }
         $revision = new DocumentRevision();
         $revision->filename = $this->upload_file->get_stored_file_name();
         $revision->file_mime_type = $this->upload_file->getMimeSoap($revision->filename);
         $revision->file_ext = $this->upload_file->file_ext;
         //$revision->document_name = ;
         $revision->revision = $document['revision'];
         $revision->document_id = $document['id'];
         $revision->save();
         $focus->document_revision_id = $revision->id;
         $focus->save();
         $return_id = $revision->id;
         $this->upload_file->final_move($revision->id);
     } else {
         return '-1';
     }
     return $return_id;
 }
示例#4
0
 function testRevisionSave()
 {
     $ret = $GLOBALS['db']->query("SELECT COUNT(*) AS rowcount1 FROM document_revisions WHERE document_id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['rowcount1'], 0, 'We created an empty revision');
     $ret = $GLOBALS['db']->query("SELECT document_revision_id FROM documents WHERE id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertTrue(empty($row['document_revision_id']), 'We linked the document to a fake document_revision');
     $ds = new DocumentSoap();
     $revision_stuff = array('file' => base64_encode('Pickles has an extravagant beard of pine fur.'), 'filename' => 'a_file_about_pickles.txt', 'id' => $this->doc->id, 'revision' => '1');
     $revisionId = $ds->saveFile($revision_stuff);
     $ret = $GLOBALS['db']->query("SELECT COUNT(*) AS rowcount1 FROM document_revisions WHERE document_id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['rowcount1'], 1, 'We didn\'t create a revision when we should have');
     $ret = $GLOBALS['db']->query("SELECT document_revision_id FROM documents WHERE id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['document_revision_id'], $revisionId, 'We didn\'t link the newly created document revision to the document');
     // Double saving doesn't work because save doesn't reset the new_with_id
     $newDoc = new Document();
     $newDoc->retrieve($this->doc->id);
     $newDoc->document_revision_id = $revisionId;
     $newDoc->save(FALSE);
     $ret = $GLOBALS['db']->query("SELECT COUNT(*) AS rowcount1 FROM document_revisions WHERE document_id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['rowcount1'], 1, 'We didn\'t create a revision when we should have');
     $ret = $GLOBALS['db']->query("SELECT document_revision_id FROM documents WHERE id = '{$this->doc->id}'");
     $row = $GLOBALS['db']->fetchByAssoc($ret);
     $this->assertEquals($row['document_revision_id'], $revisionId, 'We didn\'t link the newly created document revision to the document');
 }
示例#5
0
 /**
  * Generates document using specified data
  *
  * @param array  $data data for template
  * @return Document generated document
  */
 public function generate($data)
 {
     $document = new Document();
     $document->setFilename("document." . $this->template->getExtension());
     $document->setContents($this->replace($this->template->getContents(), $data));
     return $document;
 }
示例#6
0
 public function getList($order = "didascalia")
 {
     $order = trim(filter_var($order, FILTER_SANITIZE_STRING));
     //interrogazione tabella
     $sql = "SELECT * FROM upload ORDER BY {$order}";
     $auth = $this->connector->query($sql);
     $list = array();
     // controllo sul risultato dell'interrogazione
     if (mysql_num_rows($auth) > 0) {
         $doc = new Document();
         $doc->setConnector($this->connector);
         $course = new Course();
         $course->setConnector($this->connector);
         while ($res = $this->connector->getObjectResult($auth)) {
             $doc = new Document($res->id, $res->path, $res->tipo, $res->didascalia);
             //Calcolo le informazioni di servizio
             if ($res->tipo == 1) {
                 $doc->course_name = "TUTTI";
             } else {
                 $doc->course_name = $course->getById($res->tipo)->name;
             }
             $list[] = $doc;
         }
     }
     return $list;
 }
示例#7
0
 function sendForBilling()
 {
     $response = new Response();
     try {
         $projectId = $this->input->post("project-id");
         $amount = $this->input->post("project-bill-amount");
         $billDoc = $this->input->post("bill-doc");
         $project = $this->findById("Project", $projectId);
         if ($project == null) {
             throw new RuntimeException("Invalid Project..!");
         }
         $project->setStatus(Project::PROJECT_BILL);
         $project->getWorkOrder()->setStatus(Workorder::STATUS_COMPLETED);
         $project->getWorkOrder()->setApprovedBy($this->getLoggedInUser());
         $bill = new Bill();
         $bill->setAmount($amount);
         $bill->setProject($project);
         $bill->setCreated(new DateTime());
         $bill->setStatus(Bill::STATUS_PENDING);
         if ($billDoc != null && $billDoc != "") {
             foreach ($billDoc as $file) {
                 $doc = new Document();
                 $doc->setName($file);
                 $doc->setCreated(new DateTime());
                 $bill->getBillDoc()->add($doc);
             }
         }
         $this->save($bill);
         $response->setData(Project::PROJECT_BILL);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
示例#8
0
 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                   $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query  Query to filter the percolator queries which
  *                                                                      are executed.
  * @param  string                                               $type
  * @param  array                                                $params Supports setting additional request body options to the percolate request.
  *                                                                      [ Percolator::EXTRA_FILTER,
  *                                                                      Percolator::EXTRA_QUERY,
  *                                                                      Percolator::EXTRA_SIZE,
  *                                                                      Percolator::EXTRA_TRACK_SCORES,
  *                                                                      Percolator::EXTRA_SORT,
  *                                                                      Percolator::EXTRA_FACETS,
  *                                                                      Percolator::EXTRA_AGGS,
  *                                                                      Percolator::EXTRA_HIGHLIGHT ]
  * @return array                                                With matching registered queries.
  */
 public function matchDoc(Document $doc, $query = null, $type = 'type', $params = array())
 {
     $path = $this->_index->getName() . '/' . $type . '/_percolate';
     $data = array('doc' => $doc->getData());
     $this->_applyAdditionalRequestBodyOptions($params, $data);
     return $this->_percolate($path, $query, $data, $params);
 }
示例#9
0
 static function create_from_pptxn($pptxn_id)
 {
     $t = new PayPalTxn($pptxn_id);
     # if it already has a payment_id, stop here and just return that id
     if ($t->payment_id() > 0) {
         return $t->payment_id();
     }
     $student_id = $t->student_id();
     if ($student_id === false) {
         return false;
     }
     $set = array('student_id' => $student_id, 'created_at' => 'NOW()');
     $money = $t->money();
     $set['currency'] = $money->code;
     $set['millicents'] = $money->millicents;
     $info = $t->infoarray();
     if (!isset($info['item_number'])) {
         return false;
     }
     $d = new Document($info['item_number']);
     if ($d->failed()) {
         return false;
     }
     $set['document_id'] = $d->id;
     $p = new Payment(false);
     $payment_id = $p->add($set);
     $t->set(array('payment_id' => $payment_id));
     return $payment_id;
 }
function findEntity()
{
    $document = new Document();
    // Dokument wiederfinden -> Todo: anhand der field_defs generisch suchen
    $result = $document->get_list('', 'document_name = "' . $_REQUEST['document_name'] . '"');
    return $result['list'][0];
}
示例#11
0
 /**
  * @param mixed $accessor
  * @param bool  $retrieve
  * @return Document|null
  */
 public function getDocument($accessor = null, $retrieve = false)
 {
     if ($accessor === null) {
         $accessor = static::DEFAULT_ACCESSOR;
     }
     if ($accessor === null) {
         // the value contains the document itself
         $doc = $this->value;
         // if the view didn't emit the actual doc as value but was called with include_docs=true
         if (!$doc || !isset($doc->_id) && !isset($doc['_id'])) {
             $doc = $this->doc;
         }
     } elseif (is_callable($accessor)) {
         // an anonymous function or another kind of callback that will grab the value for us
         $doc = call_user_func($accessor, $this);
     } elseif (is_array($this->value) && isset($this->value[$accessor])) {
         // value is an array
         $doc = $this->value[$accessor];
     } elseif (isset($this->value->{$accessor})) {
         // it's the name of a property
         $doc = $this->value->{$accessor};
     } else {
         // exception
     }
     if ($doc) {
         $retval = new Document($this->getViewResult()->getDatabase());
         $retval->hydrate($doc);
         return $retval;
     } elseif ($retrieve) {
         // the view didn't emit the actual doc as value and the view wasn't called with include_docs=true
         return $this->viewResult->getDatabase()->retrieveDocument($this->id);
     } else {
         return null;
     }
 }
示例#12
0
 function getTokenIssues($tokenID)
 {
     $paraID = false;
     $context = false;
     $place = false;
     $db = $this->startDB();
     $sql = "SELECT * FROM gap_issues WHERE tokenID = {$tokenID}  AND active = 1 ORDER BY updated DESC;";
     $result = $db->fetchAll($sql, 2);
     $sql = "SELECT * FROM gap_issues WHERE tokenID = {$tokenID}  AND active = 0 ORDER BY updated DESC;";
     $resultOld = $db->fetchAll($sql, 2);
     $tokensObj = new Tokens();
     $tokenData = $tokensObj->getTokenByID($tokenID);
     $tokensObj->highlightToken = $tokenID;
     if (is_array($tokenData)) {
         $token = $tokenData["token"];
         $paraID = $tokenData["paraID"];
         $pageID = $tokenData["pageID"];
         $docID = $tokenData["docID"];
         $context = $tokensObj->getGapVisDocPage($docID, $pageID, $paraID, $tokenID);
         $place = $tokensObj->getPlaceByTokensID($tokenID);
         $related = false;
         $relatedPlaceTokens = false;
         if (is_array($place)) {
             $related = $tokensObj->getTokenIDsBySharedPlaceURIid($tokenID, $place["uriID"], $token);
             $relatedPlaceTokens = $tokensObj->getUniqueTokensFromPlaceURI($place["uri"]);
         }
         $docObj = new Document();
         $document = $docObj->getByID($docID);
     }
     $output = array("tokenID" => $tokenID, "token" => $token, "docID" => $docID, "document" => $document, "pageID" => $pageID, "context" => $context, "place" => $place, "related" => $related, "relatedPlaceTokens" => $relatedPlaceTokens, "issues" => $result, "oldIssues" => $resultOld, "oldPlaces" => $tokensObj->getTokenDeactivatedPlaceRefs($tokenID));
     return $output;
 }
function get_all_linked_attachment_revisions($attachmentsequence)
{
    $attachmentIds = explode(' ', trim($attachmentsequence));
    $attachments = array();
    foreach ($attachmentIds as $id) {
        $revision = new DocumentRevision();
        if (!$revision->retrieve($id)) {
            // if in old format try to recover by document id
            $attachment = new Document();
            if ($attachment->retrieve($id)) {
                $attachment->revision = '';
                $attachment->doc_rev_id = '';
                $attachments[] = $attachment;
            }
        } else {
            $attachment = new Document();
            if ($attachment->retrieve($revision->document_id)) {
                $attachment->revision = $revision->revision;
                $attachment->doc_rev_id = $revision->id;
                $attachments[] = $attachment;
            }
        }
    }
    return $attachments;
}
示例#14
0
文件: list.php 项目: AliEksi/DokuDok
 public function addNews()
 {
     foreach ($this->fileArray as $file) {
         $title = explode(".", $file)[0];
         $book = new Document($this->path, $file, $title);
         $book->save();
     }
 }
示例#15
0
 public static function export(Document $document)
 {
     $json = db::query('SELECT creation_date, data FROM snapshots WHERE document = ' . db::value($document->getId()) . ' ORDER BY creation_date DESC');
     foreach ($json as $i => $row) {
         $json[$i]['data'] = json_decode($row['data']);
     }
     return $json;
 }
示例#16
0
 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                  $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Not implemented yet
  * @return \Elastica\Response
  */
 public function matchDoc(Document $doc, $query = null)
 {
     $path = $this->_index->getName() . '/type/_percolate';
     $data = array('doc' => $doc->getData());
     $response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
示例#17
0
 public function newWordsAction($data = array())
 {
     $req = new Request();
     $doc = -1;
     $doc = new Document(-1);
     $data = array('docId' => $doc->getId(), 'docWords' => $doc->getWords(), 'prevWords' => '');
     return json_encode($data);
 }
示例#18
0
 function delete($id = FALSE)
 {
     if ($id) {
         $document = new Document($id);
         $document->delete();
         set_notify('success', lang('delete_data_complete'));
     }
     redirect('documents');
 }
示例#19
0
 function index()
 {
     $document = new Document();
     if (@$_GET['search']) {
         $document->like('title', '%' . $_GET['search'] . '%');
     }
     $data['documents'] = $document->order_by('id', 'desc')->get_page();
     $this->template->build('document_public', $data);
 }
示例#20
0
 public function testGoodValue()
 {
     $obj = new Document();
     $obj->setMyState('s1');
     $accessor = $this->newAccessor();
     $accessor->doTransition($obj, 't2')->doTransition($obj, 't3')->doTransition($obj, 't1')->doTransition($obj, 't4');
     $this->assertTrue($accessor->isFinalState($obj));
     $this->assertFalse($accessor->isInitialState($obj));
 }
示例#21
0
 public function compress()
 {
     // Set default $project
     if (!isset($this->original[0]['$project'])) {
         $project = array();
         foreach ($this->collection->schema_reverse_index as $short => $long) {
             $project[$long] = 1;
             $this->mappings[$long] = $short;
         }
     }
     // Build pipline
     $pipeline = array();
     foreach ($this->original as $index => $section) {
         $pipeline[$index] = array();
         foreach ($section as $pipeline_key => $data) {
             // Sort out Projections
             if ($pipeline_key === '$project') {
                 foreach ($data as $key => $value) {
                     $short_key = array_search($key, $this->collection->schema_reverse_index);
                     if ($short_key) {
                         $this->mappings[$key] = $short_key;
                         unset($data[$key]);
                         $data[$short_key] = 1;
                     }
                 }
             } elseif ($pipeline_key === '$match') {
                 // Match
                 $document = new Document($data, $this->collection);
                 $document->compress();
                 $data = $document->compressed;
             } else {
                 // Grouping
                 $schema_keys = array();
                 foreach ($this->collection->schema_reverse_index as $schema_key => $schema_value) {
                     $schema_keys['$' . $schema_key] = '$' . $schema_value;
                 }
                 $json_data = json_encode($data);
                 $json_data = str_replace(array_values($schema_keys), array_keys($schema_keys), $json_data);
                 $data = json_decode($json_data, true);
             }
             // Iterate over each section
             if (is_array($data)) {
                 $pipeline[$index][$pipeline_key] = array();
                 foreach ($data as $key => $value) {
                     $pipeline[$index][$pipeline_key][$key] = $value;
                 }
             } else {
                 // String values such as..
                 $pipeline[$index][$pipeline_key] = $data;
             }
         }
     }
     // Assign to internal variable
     $this->compressed = $pipeline;
     return $pipeline;
 }
示例#22
0
 public function testConvert()
 {
     $a = new Document();
     $a['b'] = 'foo';
     $a['c']['d'] = 'bar';
     $a['c']['e'] = 'baz';
     $a['f']['g']['h'] = 'foobar';
     $b = $a->toDocument();
     $this->assertEquals($a->toArray(), $b->toArray());
 }
示例#23
0
 function testDocTagless()
 {
     $x = new Document(2);
     $x->remove_tag(1);
     $y = Document::tagless();
     $this->assertEquals(1, count($y));
     $z = array_shift($y);
     $this->assertType('Document', $z);
     $this->assertEquals(2, $z->id);
 }
示例#24
0
function showForm($name = '', $error = '')
{
    $doc = new Document('base');
    $doc->title = 'Login';
    if ($error != '') {
        $error = "<p id='error'>{$error}</p>";
    }
    $doc->content = "\r\n        <h1>Authorization form</h1>\r\n        <form method='post' action='login.php'>\r\n        {$error}\r\n        <div class='fieldset'>\r\n        <label>User name:<br>\r\n        <input type='text' name='user' value='{$name}' id='name'/>\r\n        </label><br>\r\n        <label>Password:<br>\r\n        <input type='password' name='password' />\r\n        </label>\r\n        </div>\r\n        <input type='submit' value='Enter' />\r\n        </form>\r\n        <script>\$(function() {\$('#name').focus();});</script>\r\n    ";
    echo $doc->render();
}
 function fill_in_relationship_fields()
 {
     parent::fill_in_relationship_fields();
     if (!empty($this->signedcontractdocument_id)) {
         $document = new Document();
         if ($document->retrieve($this->signedcontractdocument_id)) {
             $this->signedcontractdocument = $document->document_name;
         }
     }
 }
 /**
  * @param  Document $parentDocument
  * @param  Pimcore_Navigation_Page_Uri $parentPage
  * @return void
  */
 protected function buildNextLevel($parentDocument, $parentPage = null, $isRoot = false)
 {
     $pages = array();
     $childs = $parentDocument->getChilds();
     if (is_array($childs)) {
         foreach ($childs as $child) {
             if (($child instanceof Document_Page or $child instanceof Document_Link or $child instanceof Document_Hardlink) and $child->getProperty("navigation_name")) {
                 $active = false;
                 if (strpos($this->_activeDocument->getFullPath(), $child->getFullPath() . "/") === 0 || $this->_activeDocument->getFullPath() == $child->getFullPath()) {
                     $active = true;
                 }
                 $path = $child->getFullPath();
                 if ($child instanceof Document_Link) {
                     $path = $child->getHref();
                 }
                 $page = new $this->_pageClass();
                 $page->setUri($path . $child->getProperty("navigation_parameters") . $child->getProperty("navigation_anchor"));
                 $page->setLabel($child->getProperty("navigation_name"));
                 $page->setActive($active);
                 $page->setId($this->_htmlMenuIdPrefix . $child->getId());
                 $page->setClass($child->getProperty("navigation_class"));
                 $page->setTarget($child->getProperty("navigation_target"));
                 $page->setTitle($child->getProperty("navigation_title"));
                 $page->setAccesskey($child->getProperty("navigation_accesskey"));
                 $page->setTabindex($child->getProperty("navigation_tabindex"));
                 $page->setRelation($child->getProperty("navigation_relation"));
                 $page->setDocument($child);
                 if ($child->getProperty("navigation_exclude")) {
                     $page->setVisible(false);
                 }
                 if ($active and !$isRoot) {
                     $page->setClass($page->getClass() . " active");
                 } else {
                     if ($active and $isRoot) {
                         $page->setClass($page->getClass() . " main mainactive");
                     } else {
                         if ($isRoot) {
                             $page->setClass($page->getClass() . " main");
                         }
                     }
                 }
                 if ($child->hasChilds()) {
                     $childPages = $this->buildNextLevel($child, $page, false);
                     $page->setPages($childPages);
                 }
                 $pages[] = $page;
                 if ($isRoot) {
                     $this->_navigationContainer->addPage($page);
                 }
             }
         }
     }
     return $pages;
 }
示例#27
0
 /**
  * @static
  * @param Document $doc
  * @return Document
  */
 public static function upperCastDocument(Document $doc)
 {
     $to_class = "Document_Hardlink_Wrapper_" . ucfirst($doc->getType());
     $old_serialized_prefix = "O:" . strlen(get_class($doc));
     $old_serialized_prefix .= ":\"" . get_class($doc) . "\":";
     $old_serialized_object = serialize($doc);
     $new_serialized_object = 'O:' . strlen($to_class) . ':"' . $to_class . '":';
     $new_serialized_object .= substr($old_serialized_object, strlen($old_serialized_prefix));
     $document = unserialize($new_serialized_object);
     return $document;
 }
 public function testToString()
 {
     $segment = new Segment();
     $segment->addField(new Field(array('length' => 2, 'type' => new IntegerType(), 'value' => 1)));
     $segment->addField(new Field(array('length' => 3, 'type' => new IntegerType(), 'value' => 10)));
     $segments = new ArrayCollection(array($segment));
     $this->object->setSegments($segments);
     $this->assertCount(1, $this->object->getSegments());
     $this->assertEquals('01010', $this->object->toString());
     $this->assertEquals('01;010', $this->object->toString(';'));
 }
 public function create()
 {
     $d = new Document();
     /* loop variables and set to Document */
     foreach ($this->post as $key => $value) {
         $d->set($key, $value);
     }
     /* save document in collection */
     $id = $this->documentHandler->save(COLLECTION_NAME, $d);
     echo json_encode(["result" => $id]);
 }
示例#30
0
 public function setUp()
 {
     global $current_user, $currentModule;
     $mod_strings = return_module_language($GLOBALS['current_language'], "Documents");
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     $document = new Document();
     $document->id = uniqid();
     $document->name = 'Test Document';
     $document->save();
     $this->doc = $document;
 }