当前位置: 首页>>代码示例>>PHP>>正文


PHP PhrictionDocument::establishConnection方法代码示例

本文整理汇总了PHP中PhrictionDocument::establishConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP PhrictionDocument::establishConnection方法的具体用法?PHP PhrictionDocument::establishConnection怎么用?PHP PhrictionDocument::establishConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhrictionDocument的用法示例。


在下文中一共展示了PhrictionDocument::establishConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadDocuments

 private function loadDocuments(AphrontPagerView $pager)
 {
     // TODO: Do we want/need a query object for this?
     $document_dao = new PhrictionDocument();
     $content_dao = new PhrictionContent();
     $conn = $document_dao->establishConnection('r');
     switch ($this->view) {
         case 'all':
             $data = queryfx_all($conn, 'SELECT * FROM %T ORDER BY id DESC LIMIT %d, %d', $document_dao->getTableName(), $pager->getOffset(), $pager->getPageSize() + 1);
             break;
         case 'updates':
             // TODO: This query is a little suspicious, verify we don't need to key
             // or change it once we get more data.
             $data = queryfx_all($conn, 'SELECT d.* FROM %T d JOIN %T c ON c.documentID = d.id
         GROUP BY c.documentID
         ORDER BY MAX(c.id) DESC LIMIT %d, %d', $document_dao->getTableName(), $content_dao->getTableName(), $pager->getOffset(), $pager->getPageSize() + 1);
             break;
         default:
             throw new Exception("Unknown view '{$this->view}'!");
     }
     $data = $pager->sliceResults($data);
     $documents = $document_dao->loadAllFromArray($data);
     if ($documents) {
         $content = $content_dao->loadAllWhere('documentID IN (%Ld)', mpull($documents, 'getID'));
         $content = mpull($content, null, 'getDocumentID');
         foreach ($documents as $document) {
             $document->attachContent($content[$document->getID()]);
         }
     }
     return $documents;
 }
开发者ID:rudimk,项目名称:phabricator,代码行数:31,代码来源:PhrictionListController.php

示例2: loadPage

 protected function loadPage()
 {
     $table = new PhrictionDocument();
     $conn_r = $table->establishConnection('r');
     $rows = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     $documents = $table->loadAllFromArray($rows);
     if ($documents) {
         $ancestor_slugs = array();
         foreach ($documents as $key => $document) {
             $document_slug = $document->getSlug();
             foreach (PhabricatorSlug::getAncestry($document_slug) as $ancestor) {
                 $ancestor_slugs[$ancestor][] = $key;
             }
         }
         if ($ancestor_slugs) {
             $ancestors = queryfx_all($conn_r, 'SELECT * FROM %T WHERE slug IN (%Ls)', $document->getTableName(), array_keys($ancestor_slugs));
             $ancestors = $table->loadAllFromArray($ancestors);
             $ancestors = mpull($ancestors, null, 'getSlug');
             foreach ($ancestor_slugs as $ancestor_slug => $document_keys) {
                 $ancestor = idx($ancestors, $ancestor_slug);
                 foreach ($document_keys as $document_key) {
                     $documents[$document_key]->attachAncestor($ancestor_slug, $ancestor);
                 }
             }
         }
     }
     return $documents;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:28,代码来源:PhrictionDocumentQuery.php

示例3: renderChildren

 private function renderChildren($slug)
 {
     $document_dao = new PhrictionDocument();
     $content_dao = new PhrictionContent();
     $conn = $document_dao->establishConnection('r');
     $limit = 50;
     $d_child = PhrictionDocument::getSlugDepth($slug) + 1;
     $d_grandchild = PhrictionDocument::getSlugDepth($slug) + 2;
     // Select children and grandchildren.
     $children = queryfx_all($conn, 'SELECT d.slug, d.depth, c.title FROM %T d JOIN %T c
     ON d.contentID = c.id
     WHERE d.slug LIKE %> AND d.depth IN (%d, %d)
       AND d.status = %d
     ORDER BY d.depth, c.title LIMIT %d', $document_dao->getTableName(), $content_dao->getTableName(), $slug == '/' ? '' : $slug, $d_child, $d_grandchild, PhrictionDocumentStatus::STATUS_EXISTS, $limit);
     if (!$children) {
         return;
     }
     // We're going to render in one of three modes to try to accommodate
     // different information scales:
     //
     //  - If we found fewer than $limit rows, we know we have all the children
     //    and grandchildren and there aren't all that many. We can just render
     //    everything.
     //  - If we found $limit rows but the results included some grandchildren,
     //    we just throw them out and render only the children, as we know we
     //    have them all.
     //  - If we found $limit rows and the results have no grandchildren, we
     //    have a ton of children. Render them and then let the user know that
     //    this is not an exhaustive list.
     if (count($children) == $limit) {
         $more_children = true;
         foreach ($children as $child) {
             if ($child['depth'] == $d_grandchild) {
                 $more_children = false;
             }
         }
         $show_grandchildren = false;
     } else {
         $show_grandchildren = true;
         $more_children = false;
     }
     $grandchildren = array();
     foreach ($children as $key => $child) {
         if ($child['depth'] == $d_child) {
             continue;
         } else {
             unset($children[$key]);
             if ($show_grandchildren) {
                 $ancestors = PhrictionDocument::getSlugAncestry($child['slug']);
                 $grandchildren[end($ancestors)][] = $child;
             }
         }
     }
     // Fill in any missing children.
     $known_slugs = ipull($children, null, 'slug');
     foreach ($grandchildren as $slug => $ignored) {
         if (empty($known_slugs[$slug])) {
             $children[] = array('slug' => $slug, 'depth' => $d_child, 'title' => PhrictionDocument::getDefaultSlugTitle($slug), 'empty' => true);
         }
     }
     $list = array();
     $list[] = '<ul>';
     foreach ($children as $child) {
         $list[] = $this->renderChildDocumentLink($child);
         $grand = idx($grandchildren, $child['slug'], array());
         if ($grand) {
             $list[] = '<ul>';
             foreach ($grand as $grandchild) {
                 $list[] = $this->renderChildDocumentLink($grandchild);
             }
             $list[] = '</ul>';
         }
     }
     if ($more_children) {
         $list[] = '<li>More...</li>';
     }
     $list[] = '</ul>';
     $list = implode("\n", $list);
     return '<div class="phriction-children">' . '<div class="phriction-children-header">Document Hierarchy</div>' . $list . '</div>';
 }
开发者ID:netcomtec,项目名称:phabricator,代码行数:80,代码来源:PhrictionDocumentController.php

示例4: pht

<?php

$table = new PhrictionDocument();
$conn_w = $table->establishConnection('w');
echo pht('Populating Phriction policies.') . "\n";
$default_view_policy = PhabricatorPolicies::POLICY_USER;
$default_edit_policy = PhabricatorPolicies::POLICY_USER;
foreach (new LiskMigrationIterator($table) as $doc) {
    $id = $doc->getID();
    if ($doc->getViewPolicy() && $doc->getEditPolicy()) {
        echo pht('Skipping document %d; already has policy set.', $id) . "\n";
        continue;
    }
    // If this was previously a magical project wiki page (under projects/, but
    // not projects/ itself) we need to apply the project policies. Otherwise,
    // apply the default policies.
    $slug = $doc->getSlug();
    $slug = PhabricatorSlug::normalize($slug);
    $prefix = 'projects/';
    if ($slug != $prefix && strncmp($slug, $prefix, strlen($prefix)) === 0) {
        $parts = explode('/', $slug);
        $project_slug = $parts[1];
        $project_slug = PhabricatorSlug::normalizeProjectSlug($project_slug);
        $project_slugs = array($project_slug);
        $project = id(new PhabricatorProjectQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withSlugs($project_slugs)->executeOne();
        if ($project) {
            $view_policy = nonempty($project->getViewPolicy(), $default_view_policy);
            $edit_policy = nonempty($project->getEditPolicy(), $default_edit_policy);
            $project_name = $project->getName();
            echo pht("Migrating document %d to project policy %s...\n", $id, $project_name);
            $doc->setViewPolicy($view_policy);
开发者ID:truSense,项目名称:phabricator,代码行数:31,代码来源:20141107.phriction.policy.2.php

示例5: loadHandles


//.........这里部分代码省略.........
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($repositories[$phid])) {
                         $handle->setName('Unknown Repository');
                     } else {
                         $repository = $repositories[$phid];
                         $handle->setName($repository->getCallsign());
                         $handle->setURI('/diffusion/' . $repository->getCallsign() . '/');
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
                 $object = new PhabricatorOwnersPackage();
                 $packages = $object->loadAllWhere('phid in (%Ls)', $phids);
                 $packages = mpull($packages, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($packages[$phid])) {
                         $handle->setName('Unknown Package');
                     } else {
                         $package = $packages[$phid];
                         $handle->setName($package->getName());
                         $handle->setURI('/owners/package/' . $package->getID() . '/');
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_APRJ:
                 $project_dao = new PhabricatorRepositoryArcanistProject();
                 $projects = $project_dao->loadAllWhere('phid IN (%Ls)', $phids);
                 $projects = mpull($projects, null, 'getPHID');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($projects[$phid])) {
                         $handle->setName('Unknown Arcanist Project');
                     } else {
                         $project = $projects[$phid];
                         $handle->setName($project->getName());
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
                 $document_dao = new PhrictionDocument();
                 $content_dao = new PhrictionContent();
                 $conn = $document_dao->establishConnection('r');
                 $documents = queryfx_all($conn, 'SELECT * FROM %T document JOIN %T content
           ON document.contentID = content.id
           WHERE document.phid IN (%Ls)', $document_dao->getTableName(), $content_dao->getTableName(), $phids);
                 $documents = ipull($documents, null, 'phid');
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setPHID($phid);
                     $handle->setType($type);
                     if (empty($documents[$phid])) {
                         $handle->setName('Unknown Document');
                     } else {
                         $info = $documents[$phid];
                         $handle->setName($info['title']);
                         $handle->setURI(PhrictionDocument::getSlugURI($info['slug']));
                         $handle->setComplete(true);
                     }
                     $handles[$phid] = $handle;
                 }
                 break;
             default:
                 $loader = null;
                 if (isset($external_loaders[$type])) {
                     $loader = $external_loaders[$type];
                 } else {
                     if (isset($external_loaders['*'])) {
                         $loader = $external_loaders['*'];
                     }
                 }
                 if ($loader) {
                     $object = newv($loader, array());
                     $handles += $object->loadHandles($phids);
                     break;
                 }
                 foreach ($phids as $phid) {
                     $handle = new PhabricatorObjectHandle();
                     $handle->setType($type);
                     $handle->setPHID($phid);
                     $handle->setName('Unknown Object');
                     $handle->setFullName('An Unknown Object');
                     $handles[$phid] = $handle;
                 }
                 break;
         }
     }
     return $handles;
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:101,代码来源:PhabricatorObjectHandleData.php

示例6: renderDocumentChildren

 private function renderDocumentChildren($slug)
 {
     $document_dao = new PhrictionDocument();
     $content_dao = new PhrictionContent();
     $conn = $document_dao->establishConnection('r');
     $limit = 250;
     $d_child = PhabricatorSlug::getDepth($slug) + 1;
     $d_grandchild = PhabricatorSlug::getDepth($slug) + 2;
     // Select children and grandchildren.
     $children = queryfx_all($conn, 'SELECT d.slug, d.depth, c.title FROM %T d JOIN %T c
     ON d.contentID = c.id
     WHERE d.slug LIKE %> AND d.depth IN (%d, %d)
       AND d.status IN (%Ld)
     ORDER BY d.depth, c.title LIMIT %d', $document_dao->getTableName(), $content_dao->getTableName(), $slug == '/' ? '' : $slug, $d_child, $d_grandchild, array(PhrictionDocumentStatus::STATUS_EXISTS, PhrictionDocumentStatus::STATUS_STUB), $limit);
     if (!$children) {
         return;
     }
     // We're going to render in one of three modes to try to accommodate
     // different information scales:
     //
     //  - If we found fewer than $limit rows, we know we have all the children
     //    and grandchildren and there aren't all that many. We can just render
     //    everything.
     //  - If we found $limit rows but the results included some grandchildren,
     //    we just throw them out and render only the children, as we know we
     //    have them all.
     //  - If we found $limit rows and the results have no grandchildren, we
     //    have a ton of children. Render them and then let the user know that
     //    this is not an exhaustive list.
     if (count($children) == $limit) {
         $more_children = true;
         foreach ($children as $child) {
             if ($child['depth'] == $d_grandchild) {
                 $more_children = false;
             }
         }
         $show_grandchildren = false;
     } else {
         $show_grandchildren = true;
         $more_children = false;
     }
     $grandchildren = array();
     foreach ($children as $key => $child) {
         if ($child['depth'] == $d_child) {
             continue;
         } else {
             unset($children[$key]);
             if ($show_grandchildren) {
                 $ancestors = PhabricatorSlug::getAncestry($child['slug']);
                 $grandchildren[end($ancestors)][] = $child;
             }
         }
     }
     // Fill in any missing children.
     $known_slugs = ipull($children, null, 'slug');
     foreach ($grandchildren as $slug => $ignored) {
         if (empty($known_slugs[$slug])) {
             $children[] = array('slug' => $slug, 'depth' => $d_child, 'title' => PhabricatorSlug::getDefaultTitle($slug), 'empty' => true);
         }
     }
     $children = isort($children, 'title');
     $list = array();
     foreach ($children as $child) {
         $list[] = hsprintf('<li>');
         $list[] = $this->renderChildDocumentLink($child);
         $grand = idx($grandchildren, $child['slug'], array());
         if ($grand) {
             $list[] = hsprintf('<ul>');
             foreach ($grand as $grandchild) {
                 $list[] = hsprintf('<li>');
                 $list[] = $this->renderChildDocumentLink($grandchild);
                 $list[] = hsprintf('</li>');
             }
             $list[] = hsprintf('</ul>');
         }
         $list[] = hsprintf('</li>');
     }
     if ($more_children) {
         $list[] = phutil_tag('li', array(), pht('More...'));
     }
     $content = array(phutil_tag('div', array('class' => 'phriction-children-header ' . 'sprite-gradient gradient-lightblue-header'), pht('Document Hierarchy')), phutil_tag('div', array('class' => 'phriction-children'), phutil_tag('ul', array(), $list)));
     return id(new PHUIDocumentView())->setOffset(true)->appendChild($content);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:83,代码来源:PhrictionDocumentController.php

示例7: willFilterPage

 protected function willFilterPage(array $documents)
 {
     if ($documents) {
         $ancestor_slugs = array();
         foreach ($documents as $key => $document) {
             $document_slug = $document->getSlug();
             foreach (PhabricatorSlug::getAncestry($document_slug) as $ancestor) {
                 $ancestor_slugs[$ancestor][] = $key;
             }
         }
         if ($ancestor_slugs) {
             $table = new PhrictionDocument();
             $conn_r = $table->establishConnection('r');
             $ancestors = queryfx_all($conn_r, 'SELECT * FROM %T WHERE slug IN (%Ls)', $document->getTableName(), array_keys($ancestor_slugs));
             $ancestors = $table->loadAllFromArray($ancestors);
             $ancestors = mpull($ancestors, null, 'getSlug');
             foreach ($ancestor_slugs as $ancestor_slug => $document_keys) {
                 $ancestor = idx($ancestors, $ancestor_slug);
                 foreach ($document_keys as $document_key) {
                     $documents[$document_key]->attachAncestor($ancestor_slug, $ancestor);
                 }
             }
         }
     }
     // To view a Phriction document, you must also be able to view all of the
     // ancestor documents. Filter out documents which have ancestors that are
     // not visible.
     $document_map = array();
     foreach ($documents as $document) {
         $document_map[$document->getSlug()] = $document;
         foreach ($document->getAncestors() as $key => $ancestor) {
             if ($ancestor) {
                 $document_map[$key] = $ancestor;
             }
         }
     }
     $filtered_map = $this->applyPolicyFilter($document_map, array(PhabricatorPolicyCapability::CAN_VIEW));
     // Filter all of the documents where a parent is not visible.
     foreach ($documents as $document_key => $document) {
         // If the document itself is not visible, filter it.
         if (!isset($filtered_map[$document->getSlug()])) {
             $this->didRejectResult($documents[$document_key]);
             unset($documents[$document_key]);
             continue;
         }
         // If an ancestor exists but is not visible, filter the document.
         foreach ($document->getAncestors() as $ancestor_key => $ancestor) {
             if (!$ancestor) {
                 continue;
             }
             if (!isset($filtered_map[$ancestor_key])) {
                 $this->didRejectResult($documents[$document_key]);
                 unset($documents[$document_key]);
                 break;
             }
         }
     }
     if (!$documents) {
         return $documents;
     }
     if ($this->needContent) {
         $contents = id(new PhrictionContent())->loadAllWhere('id IN (%Ld)', mpull($documents, 'getContentID'));
         foreach ($documents as $key => $document) {
             $content_id = $document->getContentID();
             if (empty($contents[$content_id])) {
                 unset($documents[$key]);
                 continue;
             }
             $document->attachContent($contents[$content_id]);
         }
     }
     return $documents;
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:73,代码来源:PhrictionDocumentQuery.php


注:本文中的PhrictionDocument::establishConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。