Beispiel #1
0
 public function doOverrideAreaPermissions()
 {
     $db = Loader::db();
     $c = $this->getBlockCollectionObject();
     $v = array($c->getCollectionID(), $c->getVersionID(), $this->bID, $this->arHandle);
     $db->query("update CollectionVersionBlocks set cbOverrideAreaPermissions = 1 where cID = ? and (cvID = ? or cbIncludeAll = 1) and bID = ? and arHandle = ?", $v);
     $v = array($c->getCollectionID(), $c->getVersionID(), $this->bID);
     $db->query("delete from BlockPermissionAssignments where cID = ? and cvID = ? and bID = ?", $v);
     // copy permissions from the page to the area
     $permissions = PermissionKey::getList('block');
     foreach ($permissions as $pk) {
         $pk->setPermissionObject($this);
         $pk->copyFromPageOrAreaToBlock();
     }
 }
Beispiel #2
0
 public function duplicate($ptHandle, $ptName)
 {
     $data = array('handle' => $ptHandle, 'name' => $ptName, 'defaultTemplate' => $this->getPageTypeDefaultPageTemplateObject(), 'allowedTemplates' => $this->getPageTypeAllowedPageTemplates(), 'templates' => $this->getPageTypeSelectedPageTemplateObjects(), 'ptLaunchInComposer' => $this->doesPageTypeLaunchInComposer(), 'ptIsFrequentlyAdded' => $this->isPageTypeFrequentlyAdded());
     $new = static::add($data);
     // now copy the edit form
     $sets = FormLayoutSet::getList($this);
     foreach ($sets as $set) {
         $set->duplicate($new);
     }
     // now copy the master pages for defaults and attributes
     $db = \Database::get();
     $r = $db->Execute('select cID from Pages where cIsTemplate = 1 and ptID = ?', array($this->getPageTypeID()));
     $home = Page::getByID(HOME_CID);
     while ($row = $r->FetchRow()) {
         $c = Page::getByID($row['cID']);
         if (is_object($c)) {
             $nc = $c->duplicate($home);
             $nc->setPageType($new);
             $db->update('Pages', array('cParentID' => 0, 'cIsTemplate' => 1), array('cID' => $nc->getCollectionID()));
             $db->insert('PageTypePageTemplateDefaultPages', array('pTemplateID' => $nc->getPageTemplateID(), 'ptID' => $new->getPageTypeID(), 'cID' => $nc->getCollectionID()));
             // clear out output control blocks because they will be pointing to the wrong thing
             $composerBlocksIDs = $db->GetAll('select cvb.bID, cvb.arHandle from btCorePageTypeComposerControlOutput o inner join CollectionVersionBlocks cvb on cvb.bID = o.bID inner join Pages p on cvb.cID = p.cID where p.cID = ?', array($nc->getCollectionID()));
             foreach ($composerBlocksIDs as $row) {
                 $b = \Block::getByID($row['bID'], $nc, $row['arHandle']);
                 $b->deleteBlock();
             }
         }
     }
     // copy permissions from the defaults to the page type
     $list = Key::getList('page_type');
     foreach ($list as $pk) {
         $pk->setPermissionObject($this);
         $rpa = $pk->getPermissionAccessObject();
         if (is_object($rpa)) {
             $pk->setPermissionObject($new);
             $pt = $pk->getPermissionAssignmentObject();
             if (is_object($pt)) {
                 $pt->clearPermissionAssignment();
                 $pt->assignPermissionAccess($rpa);
             }
         }
     }
     // copy permissions from the default page to the page type
     $list = Key::getList('page');
     foreach ($list as $pk) {
         $pk->setPermissionObject($this->getPageTypePageTemplateDefaultPageObject());
         $rpa = $pk->getPermissionAccessObject();
         if (is_object($rpa)) {
             $pk->setPermissionObject($new->getPageTypePageTemplateDefaultPageObject());
             $pt = $pk->getPermissionAssignmentObject();
             if (is_object($pt)) {
                 $pt->clearPermissionAssignment();
                 $pt->assignPermissionAccess($rpa);
             }
         }
     }
     // duplicate the target object.
     $target = $this->getPageTypePublishTargetObject();
     $new->setConfiguredPageTypePublishTargetObject($target);
 }