本文整理汇总了PHP中CollectionType::getByHandle方法的典型用法代码示例。如果您正苦于以下问题:PHP CollectionType::getByHandle方法的具体用法?PHP CollectionType::getByHandle怎么用?PHP CollectionType::getByHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CollectionType
的用法示例。
在下文中一共展示了CollectionType::getByHandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addStack
public static function addStack($stackName, $type = self::ST_TYPE_USER_ADDED) {
$ct = new CollectionType();
$data = array();
$parent = Page::getByPath(STACKS_PAGE_PATH);
$data = array();
$data['name'] = $stackName;
if (!$stackName) {
$data['name'] = t('No Name');
}
$pagetype = CollectionType::getByHandle(STACKS_PAGE_TYPE);
$page = $parent->add($pagetype, $data);
// we have to do this because we need the area to exist before we try and add something to it.
$a = Area::getOrCreate($page, STACKS_AREA_NAME);
// finally we add the row to the stacks table
$db = Loader::db();
$stackCID = $page->getCollectionID();
$v = array($stackName, $stackCID, $type);
$db->Execute('insert into Stacks (stName, cID, stType) values (?, ?, ?)', $v);
//Return the new stack
return self::getByID($stackCID);
}
示例2: testPageOperations
public function testPageOperations()
{
Loader::model('page');
Loader::model('collection_types');
$ct = CollectionType::getByHandle('left_sidebar');
//everything's got a default..
$this->assertInstanceOf('CollectionType', $ct);
//kind of weird to check this but hey
$home = Page::getByID(HOME_CID);
$pageName = "My Cool Page";
$pageHandle = 'page';
//this tests that page handles will be set as the page handle.
//The actual add function does some transforms on the handles if they are not
//set.
$badPage = Page::getByID(42069);
try {
$page = $badPage->add($ct, array('uID' => 1, 'cName' => $pageName, 'cHandle' => $pageHandle));
} catch (Exception $e) {
$caught = true;
}
if (!$caught) {
$this->fail('Added a page to a non-page');
}
$page = self::createPage($pageName, $pageHandle);
$parentID = $page->getCollectionParentID();
$this->assertInstanceOf('Page', $page);
$this->assertEquals($parentID, HOME_CID);
$this->assertSame($pageName, $page->getCollectionName());
$this->assertSame($pageHandle, $page->getCollectionHandle());
$this->assertSame('/' . $pageHandle, $page->getCollectionPath());
//now we know adding pages works.
$destination = self::createPage("Destination");
$parentCID = $destination->getCollectionID();
$page->move($destination);
$parentPath = $destination->getCollectionPath();
$handle = $page->getCollectionHandle();
$path = $page->getCollectionPath();
$this->assertSame($parentPath . '/' . $handle, $path);
$this->assertSame($parentCID, $page->getCollectionParentID());
//now we know that moving pages works
$page->moveToTrash();
$this->assertTrue($page->isInTrash());
//stuff is going to the trash
$cID = $page->getCollectionID();
$page->delete();
$noPage = Page::getByID($cID);
$this->assertEquals(COLLECTION_NOT_FOUND, $noPage->error);
//maybe there is a more certain way to determine this.
//now we know deleting pages works
$destination->delete();
//clean up the destination page
}
示例3: run
public function run()
{
BlockType::installBlockType('tags');
BlockType::installBlockType('next_previous');
BlockType::installBlockType('date_nav');
Loader::model('collection_types');
$blogEntry = CollectionType::getByHandle('blog_entry');
if (!$blogEntry || !intval($blogEntry->getCollectionTypeID())) {
$data['ctHandle'] = 'blog_entry';
$data['ctName'] = t('Blog Entry');
$blogEntry = CollectionType::add($data);
}
}
示例4: install
public function install()
{
Loader::model('collection_types');
$pkg = parent::install();
PageTheme::add('casual', $pkg);
$pagetypearray = array(array("left_sidebar", "Left Sidebar"), array("right_sidebar", "Right Sidebar"), array("full", "One Column"), array("three_column", "Three Column Layout"));
foreach ($pagetypearray as $value) {
$pageType = CollectionType::getByHandle($value[0]);
if (!$pageType) {
$pkg = Package::getByHandle('casual');
$newPageType = CollectionType::add(array('ctHandle' => $value[0], 'ctName' => t($value[1])), $pkg);
} else {
$newPageType = $pageType;
}
}
}
示例5: getUnstartedWalk
/**
* Find the latest unstarted walk, so you don't need to make a new one.
* @param $u The user for whom you're finding their walk
* @return Collection
*/
protected function getUnstartedWalk(User $u, Page $city)
{
// Find all walks for this user, in this city, with no name
$pl = new PageList();
$pl->filterByCollectionTypeHandle('walk');
$pl->filterByUserID($u->getUserID());
$pl->filterByParentID($city->getCollectionID());
$pl->displayUnapprovedPages();
$pl->filterByName('', true);
$pl->filterByAttribute('exclude_page_list', true);
// Arbitrarily use the first; it's blank anyway.
$walk = $pl->get(1)[0];
// If you couldn't find a walk, make a new one in the city
if (!$walk) {
$walk = $city->add(CollectionType::getByHandle('walk'), []);
$walk->setAttribute('exclude_page_list', true);
}
return $walk;
}
示例6: do_add
public function do_add()
{
$ctName = $_POST['ctName'];
$ctHandle = $_POST['ctHandle'];
$vs = Loader::helper('validation/strings');
$error = array();
if (!$ctHandle) {
$this->error->add(t("Handle required."));
} else {
if (!$vs->handle($ctHandle)) {
$this->error->add(t('Handles must contain only letters, numbers or the underscore symbol.'));
}
}
if (CollectionType::getByHandle($ctHandle)) {
$this->error->add(t('Handle already exists.'));
}
if (!$ctName) {
$this->error->add(t("Name required."));
} else {
if (preg_match('/[<>{};?"`]/i', $ctName)) {
$this->error->add(t('Invalid characters in page type name.'));
}
}
$valt = Loader::helper('validation/token');
if (!$valt->validate('add_page_type')) {
$this->error->add($valt->getErrorMessage());
}
$akIDArray = $_POST['akID'];
if (!is_array($akIDArray)) {
$akIDArray = array();
}
if (!$this->error->has()) {
try {
if ($_POST['task'] == 'add') {
$nCT = CollectionType::add($_POST);
$this->redirect('/dashboard/pages/types', 'page_type_added');
}
exit;
} catch (Exception $e1) {
$this->error->add($e1->getMessage());
}
}
}
示例7: add_personal_homepage
private function add_personal_homepage($user_name, $nick_name, $doc_lang)
{
$page = Page::getByPath("/{$doc_lang}/engineer/{$user_name}");
if ($page->getCollectionID() > 0) {
$this->set('error', t('Existed username: %s!', $user_name));
return false;
}
$page_type = CollectionType::getByHandle('personal_homepage');
$parent_page = Page::getByPath("/{$doc_lang}/engineer");
$page = $parent_page->add($page_type, array('cName' => $nick_name, 'cHandle' => $user_name));
if ($page instanceof Page) {
$block_type = BlockType::getByHandle("fse_public_profile");
$area = new Area('Side Bar');
$page->addBlock($block_type, $area, array("fseUsername" => $user_name));
} else {
$this->set('error', t('Failed to create personal homepage!'));
return false;
}
return true;
}
示例8: installPages
private function installPages($pkg)
{
// this could be any handle
$boilerplate = CollectionType::getByHandle("boilerplate");
// we want the user ID of the person installing. Really, you could use
// any user here if you want.
$u = new User();
$uID = $u->getUserID();
// doesn't need to be home, you could install these anywhere
$home = Page::getByID(HOME_CID);
$data = array('cHandle' => "boilerplate-sample", 'cName' => "Boilerplate Sample", 'pkgID' => $pkg->getPackageID(), 'uID' => $uID);
$boilerplateSample = $home->add($boilerplate, $data);
/*
* After you have added the page, you can add blocks with the same
* syntax as was used in the installPageTypes function above
*
* $boilerplateSample->addBlock($bt, 'Area Name', $data);
*/
/*
* It's also useful to assign attributes here, so that you don't have
* to do them from the front end later. There are a lot of different
* things that you can do here, these two are just to show how and where
* to do it.
*/
$boilerplateSample->setAttribute('exclude_page_list', 1);
$boilerplateSample->setAttribute('meta_description', t("A sample page created by the C5 Boilerplate package."));
}
示例9: add_project_pages
protected function add_project_pages($project_id, $name, $short_desc)
{
$homepage = Page::getByPath(ProjectInfo::assemblePath($project_id, 'home'));
if ($homepage->getCollectionID() > 0) {
$this->set('error', t('Existed project: %s!', $project_id));
return false;
}
$doc_lang = substr($project_id, -2);
$page_type = CollectionType::getByHandle('project_homepage');
$parent_page = Page::getByPath("/{$doc_lang}/project");
if ($parent_page->getCollectionID() == false) {
$this->set('error', t('System error (no parent to create project pages)!'));
return false;
}
$homepage = $parent_page->add($page_type, array("cName" => $name, "cHandle" => $project_id, "cDescription" => $short_desc));
if ($homepage instanceof Page) {
$block_type = BlockType::getByHandle("project_banner");
$area = new Area('Banner');
$homepage->addBlock($block_type, $area, array("projectID" => $project_id));
} else {
$this->set('error', t('Failed to create project homepage for %s!', $project_id));
return false;
}
return $this->add_requried_doc_part_pages($project_id, $homepage);
}
示例10: defined
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
defined('C5_EXECUTE') or die('Access Denied.');
exit(0);
require_once 'helpers/fsen/ProjectInfo.php';
$short_cache_pths = array('localized_home', 'personal_homepage');
echo 'Set default cache settings for some page types... <br/>';
foreach ($short_cache_pths as $pth) {
echo "=> Setting: {$pth}...";
$page_type = CollectionType::getByHandle($pth);
if (!$page_type instanceof CollectionType) {
echo "No such page type: {$pth}. <br/>";
continue;
}
$masterCID = $page_type->getMasterCollectionID();
$masterCollection = Page::getByID($masterCID);
$masterCollection->update(array('cCacheFullPageContent' => 1, 'cCacheFullPageContentOverrideLifetime' => 'custom', 'cCacheFullPageContentLifetimeCustom' => 10));
echo "Done. <br/>";
flush();
ob_flush();
}
echo 'Creating blog home pages for FSEs and reset the cache settings for personal homepages... <br/>';
$en_blogs_page = Page::getByPath('/en/blog');
$zh_blogs_page = Page::getByPath('/zh/blog');
$db = Loader::db();
示例11: getChapterPageType
private static function getChapterPageType($project_id, $domain_handle, $volume_handle)
{
if (preg_match("/^sys-[a-z]{2}\$/", $project_id)) {
$page_type_handle = self::$mDomain2ChapterPageTypeMap["sys/{$domain_handle}/{$volume_handle}"];
if (!isset($page_type_handle)) {
$page_type_handle = self::$mDomain2ChapterPageTypeMap["sys/{$domain_handle}"];
}
}
if (!isset($page_type_handle)) {
$page_type_handle = self::$mDomain2ChapterPageTypeMap["{$domain_handle}/{$volume_handle}"];
if (!isset($page_type_handle)) {
$page_type_handle = self::$mDomain2ChapterPageTypeMap[$domain_handle];
}
}
return CollectionType::getByHandle($page_type_handle);
}
示例12: pageTypeControllerPath
/**
* Gets the path to a particular page type controller
*/
public function pageTypeControllerPath($ctHandle)
{
Loader::model('collection_types');
$ct = CollectionType::getByHandle($ctHandle);
if (!is_object($ct)) {
return false;
}
$pkgHandle = $ct->getPackageHandle();
if ($pkgHandle != '') {
$packageDir = is_dir(DIR_PACKAGES . '/' . $pkgHandle) ? DIR_PACKAGES : DIR_PACKAGES_CORE;
}
if (file_exists(DIR_FILES_CONTROLLERS . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php")) {
$path = DIR_FILES_CONTROLLERS . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php";
} else {
if (isset($packageDir) && file_exists($packageDir . '/' . $pkgHandle . '/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php')) {
$path = $packageDir . '/' . $pkgHandle . '/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php';
} else {
if (file_exists(DIR_FILES_CONTROLLERS_REQUIRED . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php")) {
$path = DIR_FILES_CONTROLLERS_REQUIRED . "/" . DIRNAME_PAGE_TYPES . "/{$ctHandle}.php";
}
}
}
return $path;
}
示例13: json_decode
<?php
$importArray = json_decode(file_get_contents(__DIR__ . '/walkexport.json'), true);
foreach ($importArray as $walk) {
$pl = new PageList();
$pl->filterByCollectionTypeHandle('country');
$pl->filterByName($walk['country']);
$country = $pl->get(1)[0];
if (!$country) {
$country = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $walk['country']]);
}
$pl = new PageList();
$pl->filterByCollectionTypeHandle('city');
$pl->filterByName($walk['city']);
$city = $pl->get(1)[0];
if (!$city) {
$city = $country->add(CollectionType::getByHandle('city'), ['cName' => $walk['city']]);
}
$ui = UserInfo::getByEmail($walk['owner']);
if (!$ui) {
$ui = UserInfo::add(['uName' => $walk['owner'], 'uEmail' => $walk['owner']]);
}
$walkPage = $city->add(CollectionType::getByHandle('walk'), ['cName' => $walk['title'], 'uID' => $ui->getUserID()]);
$walkController = Loader::controller($walkPage);
$walkController->setJson(json_encode($walk), true);
}
示例14: getValue
public static function getValue($value) {
if (preg_match('/\{ccm:export:page:(.*)\}|\{ccm:export:file:(.*)\}|\{ccm:export:image:(.*)\}|\{ccm:export:pagetype:(.*)\}/i', $value, $matches)) {
if ($matches[1]) {
$c = Page::getByPath($matches[1]);
return $c->getCollectionID();
}
if ($matches[2]) {
$db = Loader::db();
$fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($matches[2]));
return $fID;
}
if ($matches[3]) {
$db = Loader::db();
$fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($matches[3]));
return $fID;
}
if ($matches[4]) {
$ct = CollectionType::getByHandle($matches[4]);
return $ct->getCollectionTypeID();
}
} else {
return $value;
}
}
示例15: foreach
} else {
echo "creating: {$country->getAttribute('name')}<br/>";
$countryPage = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $country->getAttribute('name')]);
}
foreach ($country->getElementsByTagName('city') as $city) {
$cities = new PageList();
$cities->filterByCollectionTypeHandle('city');
$cities->filterByName($city->getAttribute('name'));
$cityPage = $cities->get(1)[0];
if ($cityPage) {
$ui = UserInfo::getByEmail($city->getAttribute('owner_email'));
echo "exists: {$cityPage->getCollectionName()} new owner: " . ($ui ? $ui->getUserID() : "") . "<br/>";
} else {
echo "creating: {$city->getAttribute('name')}<br/>";
$ui = UserInfo::getByEmail($city->getAttribute('owner_email'));
$cityPage = $countryPage->add(CollectionType::getByHandle('city'), ['cName' => $city->getAttribute('name'), 'uID' => $ui ? $ui->getUserID() : 1]);
}
$ui && $cityPage->update(['uID' => $ui->getUserID()]);
}
}
/* foreach($user->childNodes as $attr) {
if($attr->nodeName == 'social_login') {
foreach($attr->childNodes as $social) {
$newUser['oauth_auths'][$social->nodeName] = $social->nodeValue;
}
}
else {
$newUser[$attr->nodeName] = $attr->nodeValue;
}
}
if(UserInfo::getByEmail($newUser['email'])) {