public function getMyVirtualPages() { return VirtualPage::get()->filter(array('CopyContentFromID' => $this->owner->ID)); }
/** * Update the position and parent of a tree node. * Only saves the node if changes were made. * * Required data: * - 'ID': The moved node * - 'ParentID': New parent relation of the moved node (0 for root) * - 'SiblingIDs': Array of all sibling nodes to the moved node (incl. the node itself). * In case of a 'ParentID' change, relates to the new siblings under the new parent. * * @return SS_HTTPResponse JSON string with a */ public function savetreenode($request) { if (!Permission::check('SITETREE_REORGANISE') && !Permission::check('ADMIN')) { $this->response->setStatusCode(403, _t('LeftAndMain.CANT_REORGANISE', "You do not have permission to rearange the site tree. Your change was not saved.")); return; } $className = $this->stat('tree_class'); $statusUpdates = array('modified' => array()); $id = $request->requestVar('ID'); $parentID = $request->requestVar('ParentID'); if ($className == 'SiteTree' && ($page = DataObject::get_by_id('Page', $id))) { $root = $page->getParentType(); if (($parentID == '0' || $root == 'root') && !SiteConfig::current_site_config()->canCreateTopLevel()) { $this->response->setStatusCode(403, _t('LeftAndMain.CANT_REORGANISE', "You do not have permission to alter Top level pages. Your change was not saved.")); return; } } $siblingIDs = $request->requestVar('SiblingIDs'); $statusUpdates = array('modified' => array()); if (!is_numeric($id) || !is_numeric($parentID)) { throw new InvalidArgumentException(); } $node = DataObject::get_by_id($className, $id); if ($node && !$node->canEdit()) { return Security::permissionFailure($this); } if (!$node) { $this->response->setStatusCode(500, _t('LeftAndMain.PLEASESAVE', "Please Save Page: This page could not be updated because it hasn't been saved yet.")); return; } // Update hierarchy (only if ParentID changed) if ($node->ParentID != $parentID) { $node->ParentID = (int) $parentID; $node->write(); $statusUpdates['modified'][$node->ID] = array('TreeTitle' => $node->TreeTitle); // Update all dependent pages if (class_exists('VirtualPage')) { $virtualPages = VirtualPage::get()->filter("CopyContentFromID", $node->ID); foreach ($virtualPages as $virtualPage) { $statusUpdates['modified'][$virtualPage->ID] = array('TreeTitle' => $virtualPage->TreeTitle()); } } $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.'))); } // Update sorting if (is_array($siblingIDs)) { $counter = 0; foreach ($siblingIDs as $id) { if ($id == $node->ID) { $node->Sort = ++$counter; $node->write(); $statusUpdates['modified'][$node->ID] = array('TreeTitle' => $node->TreeTitle); } else { if (is_numeric($id)) { // Nodes that weren't "actually moved" shouldn't be registered as // having been edited; do a direct SQL update instead ++$counter; DB::prepared_query("UPDATE \"{$className}\" SET \"Sort\" = ? WHERE \"ID\" = ?", array($counter, $id)); } } } $this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.'))); } return Convert::raw2json($statusUpdates); }
/** * Return all virtual pages that link to this page. * * @return DataList */ public function VirtualPages() { // Ignore new records if (!$this->ID) { return null; } // Check subsite virtual pages // @todo Refactor out subsite module specific code if (class_exists('Subsite')) { return Subsite::get_from_all_subsites('VirtualPage', array('"VirtualPage"."CopyContentFromID"' => $this->ID)); } // Check existing virtualpages if (class_exists('VirtualPage')) { return VirtualPage::get()->where(array('"VirtualPage"."CopyContentFromID"' => $this->ID)); } return null; }