Exemple #1
0
 public function addBlock($bt, $a, $data)
 {
     $db = Loader::db();
     // first we add the block to the system
     $nb = $bt->add($data, $this, $a);
     // now that we have a block, we add it to the collectionversions table
     $arHandle = is_object($a) ? $a->getAreaHandle() : $a;
     $cID = $this->getCollectionID();
     $vObj = $this->getVersionObject();
     if ($bt->includeAll()) {
         // normally, display order is dependant on a per area, per version basis. However, since this block
         // is not aliased across versions, then we want to get display order simply based on area, NOT based
         // on area + version
         $newBlockDisplayOrder = $this->getCollectionAreaDisplayOrder($arHandle, true);
         // second argument is "ignoreVersions"
     } else {
         $newBlockDisplayOrder = $this->getCollectionAreaDisplayOrder($arHandle);
     }
     $v = array($cID, $vObj->getVersionID(), $nb->getBlockID(), $arHandle, $newBlockDisplayOrder, 1, intval($bt->includeAll()));
     $q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbDisplayOrder, isOriginal, cbIncludeAll) values (?, ?, ?, ?, ?, ?, ?)';
     $res = $db->Execute($q, $v);
     $controller = $nb->getController();
     $features = $controller->getBlockTypeFeatureObjects();
     if (count($features) > 0) {
         foreach ($features as $fe) {
             $fd = $fe->getFeatureDetailObject($controller);
             $fa = CollectionVersionFeatureAssignment::add($fe, $fd, $this);
             $db->Execute('insert into BlockFeatureAssignments (cID, cvID, bID, faID) values (?, ?, ?, ?)', array($this->getCollectionID(), $this->getVersionID(), $nb->getBlockID(), $fa->getFeatureAssignmentID()));
         }
     }
     return Block::getByID($nb->getBlockID(), $this, $a);
 }
Exemple #2
0
 function delete()
 {
     $db = Loader::db();
     $cvID = $this->cvID;
     $c = Page::getByID($this->cID, $cvID);
     $cID = $c->getCollectionID();
     $q = "select bID, arHandle from CollectionVersionBlocks where cID = ? and cvID = ?";
     $r = $db->query($q, array($cID, $cvID));
     if ($r) {
         while ($row = $r->fetchRow()) {
             if ($row['bID']) {
                 $b = Block::getByID($row['bID'], $c, $row['arHandle']);
                 if (is_object($b)) {
                     $b->deleteBlock();
                 }
             }
             unset($b);
         }
     }
     $features = CollectionVersionFeatureAssignment::getList($this);
     foreach ($features as $fa) {
         $fa->delete();
     }
     $r = $db->Execute('select avID, akID from CollectionAttributeValues where cID = ? and cvID = ?', array($cID, $cvID));
     while ($row = $r->FetchRow()) {
         $cak = CollectionAttributeKey::getByID($row['akID']);
         $cav = $c->getAttributeValueObject($cak);
         if (is_object($cav)) {
             $cav->delete();
         }
     }
     $db->Execute('delete from CollectionVersionBlockStyles where cID = ? and cvID = ?', array($cID, $cvID));
     $db->Execute('delete from CollectionVersionThemeCustomStyles where cID = ? and cvID = ?', array($cID, $cvID));
     $db->Execute('delete from CollectionVersionRelatedEdits where cID = ? and cvID = ?', array($cID, $cvID));
     $db->Execute('delete from CollectionVersionAreaStyles where cID = ? and cvID = ?', array($cID, $cvID));
     $q = "delete from CollectionVersions where cID = '{$cID}' and cvID='{$cvID}'";
     $r = $db->query($q);
     $this->refreshCache();
 }
Exemple #3
0
 public function duplicate($nc, $isCopyFromMasterCollectionPropagation = false)
 {
     // duplicate takes a new collection as its argument, and duplicates the existing block
     // to that collection
     $db = Loader::db();
     $dh = Loader::helper('date');
     $bt = BlockType::getByID($this->getBlockTypeID());
     $blockTypeClass = $bt->getBlockTypeClass();
     $bc = new $blockTypeClass($this);
     if (!$bc) {
         return false;
     }
     $bDate = $dh->getOverridableNow();
     $v = array($this->bName, $bDate, $bDate, $this->bFilename, $this->btID, $this->uID);
     $q = "insert into Blocks (bName, bDateAdded, bDateModified, bFilename, btID, uID) values (?, ?, ?, ?, ?, ?)";
     $r = $db->prepare($q);
     $res = $db->execute($r, $v);
     $newBID = $db->Insert_ID();
     // this is the latest inserted block ID
     // now, we duplicate the block-specific permissions
     $oc = $this->getBlockCollectionObject();
     $ocID = $oc->getCollectionID();
     $ovID = $oc->getVersionID();
     $ncID = $nc->getCollectionID();
     $nvID = $nc->getVersionID();
     // Composer specific
     $row = $db->GetRow('select cID, arHandle, cbDisplayOrder, ptComposerFormLayoutSetControlID from PageTypeComposerOutputBlocks where cID = ? and bID = ? and arHandle = ?', array($ocID, $this->bID, $this->arHandle));
     if ($row && is_array($row) && $row['cID']) {
         $db->insert('PageTypeComposerOutputBlocks', array('cID' => $ncID, 'arHandle' => $this->arHandle, 'cbDisplayOrder' => $row['cbDisplayOrder'], 'ptComposerFormLayoutSetControlID' => $row['ptComposerFormLayoutSetControlID'], 'bID' => $newBID));
     }
     $q = "select paID, pkID from BlockPermissionAssignments where cID = '{$ocID}' and bID = ? and cvID = ?";
     $r = $db->query($q, array($this->bID, $ovID));
     if ($r) {
         while ($row = $r->fetchRow()) {
             $db->Replace('BlockPermissionAssignments', array('cID' => $ncID, 'cvID' => $nvID, 'bID' => $newBID, 'paID' => $row['paID'], 'pkID' => $row['pkID']), array('cID', 'cvID', 'bID', 'paID', 'pkID'), true);
         }
         $r->free();
     }
     // we duplicate block-specific sub-content
     if ($isCopyFromMasterCollectionPropagation && method_exists($bc, 'duplicate_master')) {
         $bc->duplicate_master($newBID, $nc);
     } else {
         $bc->duplicate($newBID);
     }
     $features = $bc->getBlockTypeFeatureObjects();
     if (count($features) > 0) {
         foreach ($features as $fe) {
             $fd = $fe->getFeatureDetailObject($bc);
             $fa = CollectionVersionFeatureAssignment::add($fe, $fd, $nc);
             $db->Execute('insert into BlockFeatureAssignments (cID, cvID, bID, faID) values (?, ?, ?, ?)', array($ncID, $nvID, $newBID, $fa->getFeatureAssignmentID()));
         }
     }
     // finally, we insert into the CollectionVersionBlocks table
     if (!is_numeric($this->cbDisplayOrder)) {
         $newBlockDisplayOrder = $nc->getCollectionAreaDisplayOrder($this->arHandle);
     } else {
         $newBlockDisplayOrder = $this->cbDisplayOrder;
     }
     //$v = array($ncID, $nvID, $newBID, $this->areaName, $newBlockDisplayOrder, 1);
     $v = array($ncID, $nvID, $newBID, $this->arHandle, $newBlockDisplayOrder, 1, $this->overrideAreaPermissions(), $this->overrideBlockTypeCacheSettings(), $this->overrideBlockTypeContainerSettings(), $this->enableBlockContainer());
     $q = "insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbDisplayOrder, isOriginal, cbOverrideAreaPermissions, cbOverrideBlockTypeCacheSettings,cbOverrideBlockTypeContainerSettings, cbEnableBlockContainer) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $r = $db->prepare($q);
     $res = $db->execute($r, $v);
     // now we make a DUPLICATE entry in the BlockRelations table, so that we know that the blocks are chained together
     $v2 = array($this->bID, $newBID, "DUPLICATE");
     $q2 = "insert into BlockRelations (originalBID, bID, relationType) values (?, ?, ?)";
     $r2 = $db->prepare($q2);
     $res2 = $db->execute($r2, $v2);
     $nb = self::getByID($newBID, $nc, $this->arHandle);
     $issID = $this->getCustomStyleSetID();
     if ($issID > 0) {
         $v = array($ncID, $nvID, $newBID, $this->arHandle, $issID);
         $db->Execute('insert into CollectionVersionBlockStyles (cID, cvID, bID, arHandle, issID) values (?, ?, ?, ?, ?)', $v);
     }
     return $nb;
 }
Exemple #4
0
 public function delete()
 {
     $app = Facade::getFacadeApplication();
     $db = $app->make('database')->connection();
     $cvID = $this->cvID;
     $c = Page::getByID($this->cID, $cvID);
     $cID = $c->getCollectionID();
     $q = "select bID, arHandle from CollectionVersionBlocks where cID = ? and cvID = ?";
     $r = $db->executeQuery($q, array($cID, $cvID));
     while ($row = $r->fetch()) {
         if ($row['bID']) {
             $b = Block::getByID($row['bID'], $c, $row['arHandle']);
             if (is_object($b)) {
                 $b->deleteBlock();
             }
             unset($b);
         }
     }
     $features = CollectionVersionFeatureAssignment::getList($this);
     foreach ($features as $fa) {
         $fa->delete();
     }
     $category = $app->make('Concrete\\Core\\Attribute\\Category\\PageCategory');
     $attributes = $category->getAttributeValues($this);
     foreach ($attributes as $attribute) {
         $category->deleteValue($attribute);
     }
     $db->executeQuery('delete from CollectionVersionBlockStyles where cID = ? and cvID = ?', array($cID, $cvID));
     $db->executeQuery('delete from CollectionVersionThemeCustomStyles where cID = ? and cvID = ?', array($cID, $cvID));
     $db->executeQuery('delete from CollectionVersionRelatedEdits where cID = ? and cvID = ?', array($cID, $cvID));
     $db->executeQuery('delete from CollectionVersionAreaStyles where cID = ? and cvID = ?', array($cID, $cvID));
     $q = "delete from CollectionVersions where cID = '{$cID}' and cvID='{$cvID}'";
     $db->executeQuery($q);
     $this->refreshCache();
 }