本文整理汇总了PHP中CollectionType类的典型用法代码示例。如果您正苦于以下问题:PHP CollectionType类的具体用法?PHP CollectionType怎么用?PHP CollectionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CollectionType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* Views the composer edit page.
* @param string|int $ctID The collection type
* @param string|int $cPublishParentID The parent page under which to publish
*/
public function view($ctID = false, $cPublishParentID = false)
{
// Load Page objects from their IDs
$ct = $this->setCollectionType($ctID);
$cPublishParent = Page::getByID($cPublishParent);
// If we couldn't load a collection type, send them to the composer menu
if (!is_object($ct)) {
$ctArray = CollectionType::getComposerPageTypes();
// If there's only one collection type, just choose that one
if (count($ctArray) === 1) {
$ct = $ctArray[0];
$this->redirect('/dashboard/composer/write', $ct->getCollectionTypeID());
exit;
}
// Otherwise, they need to choose the CT from this array of types
$this->set('ctArray', $ctArray);
} else {
// CT was set, so create a draft of this type
$entry = ComposerPage::createDraft($ct);
if (is_object($entry)) {
// Check if we have a parent specified to create this draft under
if ($cPublishParentID && is_object($cPublishParent)) {
// Make this draft under the specified parent
$entry->setComposerDraftPublishParentID($cPublishParentID);
}
// New draft is created, so start editing it
$this->redirect('/dashboard/composer/write', 'edit', $entry->getCollectionID());
} else {
// Something failed when trying to create a draft, so send back to drafts folder
$this->redirect('/dashboard/composer/drafts');
}
}
}
示例2: activate_files
public function activate_files($ptID)
{
try {
Loader::model("collection_types");
$pt = PageTheme::getByID($ptID);
$txt = Loader::helper('text');
if (!is_array($this->post('pageTypes'))) {
throw new Exception(t("You must specify at least one template to make into a page type."));
}
$pkg = false;
$pkgHandle = $pt->getPackageHandle();
if ($pkgHandle) {
$pkg = Package::getByHandle($pkgHandle);
}
foreach ($this->post('pageTypes') as $ptHandle) {
$data['ctName'] = $txt->unhandle($ptHandle);
$data['ctHandle'] = $ptHandle;
$ct = CollectionType::add($data, $pkg);
}
$this->set('message', t('Files in the theme were activated successfully.'));
} catch (Exception $e) {
$this->set('error', $e);
}
$this->view($ptID);
}
示例3: do_add
public function do_add()
{
$ctName = $_POST['ctName'];
$ctHandle = $_POST['ctHandle'];
$error = array();
if (!$ctHandle) {
$this->error->add(t("Handle required."));
}
if (!$ctName) {
$this->error->add(t("Name required."));
}
$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());
}
}
}
示例4: 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);
}
示例5: save
public function save()
{
$this->verify($this->post('ctID'));
if ($this->post('ctIncludeInComposer')) {
switch ($this->post('ctComposerPublishPageMethod')) {
case 'PARENT':
$page = Page::getByID($this->post('ctComposerPublishPageParentID'));
if ($page->isError()) {
$this->error->add(t('Parent page not selected'));
} else {
$this->ct->saveComposerPublishTargetPage($page);
}
break;
case 'PAGE_TYPE':
$ct = CollectionType::getByID($this->post('ctComposerPublishPageTypeID'));
$this->ct->saveComposerPublishTargetPageType($ct);
break;
default:
$this->ct->saveComposerPublishTargetAll();
break;
}
if (!$this->error->has()) {
$this->ct->saveComposerAttributeKeys($this->post('composerAKID'));
$this->redirect('/dashboard/pages/types/composer', 'view', $this->ct->getCollectionTypeID(), 'updated');
} else {
$this->view($this->ct->getCollectionTypeID());
}
} else {
$this->ct->resetComposerData();
$this->redirect("/dashboard/pages/types", "clear_composer");
}
}
示例6: createPage
public function createPage()
{
Loader::model('page');
$parent = Page::getByID($this->location);
$ct = CollectionType::getByID($this->ctID);
$data = array('cName' => $this->post->title, 'cHandle' => $this->post->page_title, 'cDescription' => $this->post->description, 'cDatePublic' => $this->post->pubDate);
$p = $parent->add($ct, $data);
return $p;
}
示例7: isValidComposerPage
/**
* Checks to see if the page in question is a valid composer draft for the logged in user
*/
protected static function isValidComposerPage($entry) {
$ct = CollectionType::getByID($entry->getCollectionTypeID());
if (!$ct->isCollectionTypeIncludedInComposer()) {
return false;
}
$cp = new Permissions($entry);
if (!$cp->canEditPageContents()) {
return false;
}
return true;
}
示例8: 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
}
示例9: 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);
}
}
示例10: 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;
}
}
}
示例11: delete
public function delete($ctID, $token = '') {
$db = Loader::db();
$valt = Loader::helper('validation/token');
if (!$valt->validate('delete_page_type', $token)) {
$this->set('message', $valt->getErrorMessage());
} else {
// check to make sure we
$pageCount = $db->getOne("SELECT COUNT(*) FROM Pages WHERE cIsTemplate = 0 and ctID = ?",array($ctID));
if($pageCount == 0) {
$ct = CollectionType::getByID($ctID);
$ct->delete();
$this->redirect("/dashboard/pages/types");
} else {
$this->set("error", array(t("You must delete all pages of this type before deleting this page type.")));
}
}
}
示例12: 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;
}
示例13: 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());
}
}
}
示例14: show
/**
* Gets a list of all pages of the collection type
* specified by $ctID
*
* @param int $ctID ID of collection type
*/
public function show($ctID)
{
$hh = Loader::helper('html');
$th = Loader::helper('text');
$emptyList = false;
$this->view(false);
Loader::model('page_list');
$pl = new PageList();
$pl->filterByCollectionTypeID($ctID);
if (array_key_exists('cvName', $_REQUEST)) {
$cvName = $th->sanitize($_REQUEST['cvName']);
$this->set('cvName', $cvName);
$pl->filterByName($cvName);
if (count($pl->getPage()) <= 0) {
$pl = new PageList();
$emptyList = true;
}
}
if (!$emptyList) {
$pl->addtoQuery('left join Pages parent ON(p1.cParentID = parent.cID)');
$pl->sortByMultiple('parent.cDisplayOrder asc', 'p1.cDisplayOrder asc');
$pages = $pl->getPage();
} else {
$pages = '';
$this->set('emptyList', t('No entries found'));
}
$ct = CollectionType::getByID($ctID);
// add all necessary header items like JavaScript and CSS files
if (!array_key_exists('cvName', $_REQUEST) || $cvName == '') {
$this->addHeaderItem($hh->css('composer.sort.css', 'remo_composer_list'));
$this->addHeaderItem($hh->javascript('composer.sort.js', 'remo_composer_list'));
}
$this->addHeaderItem($hh->javascript('composer.overview.js', 'remo_composer_list'));
// add variables used by view
$this->set('customColumns', $this->loadCustomColumns($ctID));
$this->set('ctID', $ctID);
$this->set('ctPublishMethod', $ct->getCollectionTypeComposerPublishMethod());
$this->set('pages', $pages);
$this->set('displaySearchBox', $this->displaySearchBox());
$this->set('composerListTitel', $ct->getCollectionTypeName());
$this->set('pagesPagination', $pl->displayPaging(false, true));
}
示例15: 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;
}