Esempio n. 1
0
 public function duplicateCollection()
 {
     $db = Loader::db();
     $dh = Loader::helper('date');
     $cDate = $dh->getOverridableNow();
     $v = array($cDate, $cDate, $this->cHandle);
     $r = $db->query('insert into Collections (cDateAdded, cDateModified, cHandle) values (?, ?, ?)', $v);
     $newCID = $db->Insert_ID();
     if ($r) {
         // first, we get the creation date of the active version in this collection
         //$q = "select cvDateCreated from CollectionVersions where cvIsApproved = 1 and cID = {$this->cID}";
         //$dcOriginal = $db->getOne($q);
         // now we create the query that will grab the versions we're going to copy
         $qv = "select * from CollectionVersions where cID = '{$this->cID}' order by cvDateCreated asc";
         // now we grab all of the current versions
         $rv = $db->query($qv);
         $cvList = array();
         while ($row = $rv->fetchRow()) {
             // insert
             $cvList[] = $row['cvID'];
             $cDate = date('Y-m-d H:i:s', strtotime($cDate) + 1);
             $vv = array($newCID, $row['cvID'], $row['cvName'], $row['cvHandle'], $row['cvDescription'], $row['cvDatePublic'], $cDate, $row['cvComments'], $row['cvAuthorUID'], $row['cvIsApproved'], $row['pThemeID'], $row['pTemplateID']);
             $qv = 'insert into CollectionVersions (cID, cvID, cvName, cvHandle, cvDescription, cvDatePublic, cvDateCreated, cvComments, cvAuthorUID, cvIsApproved, pThemeID, pTemplateID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
             $db->query($qv, $vv);
         }
         $ql = "select * from CollectionVersionBlockStyles where cID = '{$this->cID}'";
         $rl = $db->query($ql);
         while ($row = $rl->fetchRow()) {
             $vl = array($newCID, $row['cvID'], $row['bID'], $row['arHandle'], $row['issID']);
             $ql = 'insert into CollectionVersionBlockStyles (cID, cvID, bID, arHandle, issID) values (?, ?, ?, ?, ?)';
             $db->query($ql, $vl);
         }
         $ql = "select * from CollectionVersionAreaStyles where cID = '{$this->cID}'";
         $rl = $db->query($ql);
         while ($row = $rl->fetchRow()) {
             $vl = array($newCID, $row['cvID'], $row['arHandle'], $row['issID']);
             $ql = 'insert into CollectionVersionAreaStyles (cID, cvID, arHandle, issID) values (?, ?, ?, ?)';
             $db->query($ql, $vl);
         }
         $ql = "select * from CollectionVersionThemeCustomStyles where cID = '{$this->cID}'";
         $rl = $db->query($ql);
         while ($row = $rl->fetchRow()) {
             $vl = array($newCID, $row['cvID'], $row['pThemeID'], $row['scvlID'], $row['preset'], $row['sccRecordID']);
             $ql = 'insert into CollectionVersionThemeCustomStyles (cID, cvID, pThemeID, scvlID, preset, sccRecordID) values (?, ?, ?, ?, ?, ?)';
             $db->query($ql, $vl);
         }
         // now we grab all the blocks we're going to need
         $cvList = implode(',', $cvList);
         $q = "select bID, cvID, arHandle, cbDisplayOrder, cbOverrideAreaPermissions, cbIncludeAll, cbRelationID from CollectionVersionBlocks where cID = '{$this->cID}' and cvID in ({$cvList})";
         $r = $db->query($q);
         while ($row = $r->fetchRow()) {
             $v = array($newCID, $row['cvID'], $row['bID'], $row['arHandle'], $row['cbDisplayOrder'], $row['cbRelationID'], 0, $row['cbOverrideAreaPermissions'], $row['cbIncludeAll']);
             $q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbDisplayOrder, cbRelationID, isOriginal, cbOverrideAreaPermissions, cbIncludeAll) values (?, ?, ?, ?, ?, ?, ?, ?, ?)';
             $db->query($q, $v);
             if ($row['cbOverrideAreaPermissions'] != 0) {
                 $q2 = "select paID, pkID from BlockPermissionAssignments where cID = '{$this->cID}' and bID = '{$row['bID']}' and cvID = '{$row['cvID']}'";
                 $r2 = $db->query($q2);
                 while ($row2 = $r2->fetchRow()) {
                     $db->Replace('BlockPermissionAssignments', array('cID' => $newCID, 'cvID' => $row['cvID'], 'bID' => $row['bID'], 'paID' => $row2['paID'], 'pkID' => $row2['pkID']), array('cID', 'cvID', 'bID', 'paID', 'pkID'), true);
                 }
             }
         }
         // duplicate any attributes belonging to the collection
         $list = CollectionKey::getAttributeValues($this->vObj);
         $em = \Database::connection()->getEntityManager();
         foreach ($list as $av) {
             /**
              * @var $av PageValue
              */
             $cav = new PageValue();
             $cav->setPageID($newCID);
             $cav->setGenericValue($av->getGenericValue());
             $cav->setVersionID($this->vObj->getVersionID());
             $cav->setAttributeKey($av->getAttributeKey());
             $em->persist($cav);
         }
         $em->flush();
         return self::getByID($newCID);
     }
 }
Esempio n. 2
0
 public function getAttributeValueObject($ak, $createIfNotExists = false)
 {
     if (!is_object($ak)) {
         $ak = CollectionKey::getByHandle($ak);
     }
     $value = false;
     if (is_object($ak)) {
         $value = $this->getObjectAttributeCategory()->getAttributeValue($ak, $this);
     }
     if ($value) {
         return $value;
     } elseif ($createIfNotExists) {
         $attributeValue = new PageValue();
         $attributeValue->setPageID($this->getCollectionID());
         $attributeValue->setVersionID($this->getVersionID());
         $attributeValue->setAttributeKey($ak);
         return $attributeValue;
     }
 }