Example #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 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'], 0, $row['cbOverrideAreaPermissions'], $row['cbIncludeAll']);
             $q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbDisplayOrder, 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
         $v = array($this->getCollectionID());
         $q = 'select akID, cvID, avID from CollectionAttributeValues where cID = ?';
         $r = $db->query($q, $v);
         while ($row = $r->fetchRow()) {
             $v2 = array($row['akID'], $row['cvID'], $row['avID'], $newCID);
             $db->query('insert into CollectionAttributeValues (akID, cvID, avID, cID) values (?, ?, ?, ?)', $v2);
         }
         return Collection::getByID($newCID);
     }
 }