Exemplo n.º 1
0
 /**
  * Adds a new page of a certain type, using a passed associate array to setup value. $data may contain any or all of the following:
  * "uID": User ID of the page's owner
  * "pkgID": Package ID the page belongs to
  * "cName": The name of the page
  * "cHandle": The handle of the page as used in the path
  * "cDatePublic": The date assigned to the page
  * @param collectiontype $ct
  * @param array $data
  * @return page
  **/
 public function add(CollectionType $ct, $data)
 {
     $db = Loader::db();
     $txt = Loader::helper('text');
     // the passed collection is the parent collection
     $cParentID = $this->getCollectionID();
     $u = new User();
     if (isset($data['uID'])) {
         $uID = $data['uID'];
     } else {
         $uID = $u->getUserID();
         $data['uID'] = $uID;
     }
     if (isset($data['pkgID'])) {
         $pkgID = $data['pkgID'];
     } else {
         if ($ct->getPackageID() > 0) {
             $pkgID = $ct->getPackageID();
         } else {
             $pkgID = 0;
         }
     }
     if (isset($data['cName'])) {
         $data['name'] = $data['cName'];
     }
     if (!$data['cHandle']) {
         // make the handle out of the title
         $handle = $txt->urlify($data['name']);
     } else {
         $handle = $txt->urlify($data['cHandle']);
     }
     $handle = str_replace('-', PAGE_PATH_SEPARATOR, $handle);
     $data['handle'] = $handle;
     $dh = Loader::helper('date');
     $cDate = $dh->getSystemDateTime();
     $cDatePublic = $data['cDatePublic'] ? $data['cDatePublic'] : null;
     $data['ctID'] = $ct->getCollectionTypeID();
     if ($ct->getCollectionTypeHandle() == STACKS_PAGE_TYPE) {
         $data['cvIsNew'] = 0;
     }
     $cobj = parent::add($data);
     $cID = $cobj->getCollectionID();
     $ctID = $ct->getCollectionTypeID();
     $masterCID = $ct->getMasterCollectionID();
     $masterCollection = Page::getByID($masterCID);
     //$this->rescanChildrenDisplayOrder();
     $cDisplayOrder = $this->getNextSubPageDisplayOrder();
     $cInheritPermissionsFromCID = $this->overrideTemplatePermissions() ? $this->getPermissionsCollectionID() : $masterCID;
     $cInheritPermissionsFrom = $this->overrideTemplatePermissions() ? "PARENT" : "TEMPLATE";
     // inherit cache settings from collection type
     $cCacheFullPageContent = $masterCollection->getCollectionFullPageCaching();
     $cCacheFullPageContentOverrideLifetime = $masterCollection->getCollectionFullPageCachingLifetime();
     $cCacheFullPageContentLifetimeCustom = $masterCollection->getCollectionFullPageCachingLifetimeCustomValue();
     $v = array($cID, $cParentID, $uID, $cInheritPermissionsFrom, $this->overrideTemplatePermissions(), $cInheritPermissionsFromCID, $cDisplayOrder, $pkgID, $cCacheFullPageContent, $cCacheFullPageContentOverrideLifetime, $cCacheFullPageContentLifetimeCustom);
     $q = "insert into Pages (cID, cParentID, uID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cInheritPermissionsFromCID, cDisplayOrder, pkgID, cCacheFullPageContent, cCacheFullPageContentOverrideLifetime, cCacheFullPageContentLifetimeCustom) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $r = $db->prepare($q);
     $res = $db->execute($r, $v);
     $newCID = $cID;
     if ($res) {
         // Collection added with no problem -- update cChildren on parrent
         Loader::model('page_statistics');
         PageStatistics::incrementParents($newCID);
         if ($r) {
             // now that we know the insert operation was a success, we need to see if the collection type we're adding has a master collection associated with it
             if ($masterCID) {
                 $this->_associateMasterCollectionBlocks($newCID, $masterCID);
                 $this->_associateMasterCollectionAttributes($newCID, $masterCID);
             }
         }
         $pc = Page::getByID($newCID, 'RECENT');
         // run any internal event we have for page addition
         Events::fire('on_page_add', $pc);
         $pc->rescanCollectionPath();
     }
     return $pc;
 }