本文整理汇总了PHP中DataObject::delete_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::delete_by_id方法的具体用法?PHP DataObject::delete_by_id怎么用?PHP DataObject::delete_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObject
的用法示例。
在下文中一共展示了DataObject::delete_by_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDelete
/**
* Test deletion of DataObjects
* - Deleting using delete() on the DataObject
* - Deleting using DataObject::delete_by_id()
*/
function testDelete()
{
// Test deleting using delete() on the DataObject
// Get the first page
$page = $this->objFromFixture('Page', 'page1');
$pageID = $page->ID;
// Check the page exists before deleting
$this->assertTrue(is_object($page) && $page->exists());
// Delete the page
$page->delete();
// Check that page does not exist after deleting
$page = DataObject::get_by_id('Page', $pageID);
$this->assertTrue(!$page || !$page->exists());
// Test deleting using DataObject::delete_by_id()
// Get the second page
$page2 = $this->objFromFixture('Page', 'page2');
$page2ID = $page2->ID;
// Check the page exists before deleting
$this->assertTrue(is_object($page2) && $page2->exists());
// Delete the page
DataObject::delete_by_id('Page', $page2->ID);
// Check that page does not exist after deleting
$page2 = DataObject::get_by_id('Page', $page2ID);
$this->assertTrue(!$page2 || !$page2->exists());
}
示例2: testDelete
/**
* Test deletion of DataObjects
* - Deleting using delete() on the DataObject
* - Deleting using DataObject::delete_by_id()
*/
public function testDelete()
{
// Test deleting using delete() on the DataObject
// Get the first page
$obj = $this->objFromFixture('DataObjectTest_Player', 'captain1');
$objID = $obj->ID;
// Check the page exists before deleting
$this->assertTrue(is_object($obj) && $obj->exists());
// Delete the page
$obj->delete();
// Check that page does not exist after deleting
$obj = DataObject::get_by_id('DataObjectTest_Player', $objID);
$this->assertTrue(!$obj || !$obj->exists());
// Test deleting using DataObject::delete_by_id()
// Get the second page
$obj = $this->objFromFixture('DataObjectTest_Player', 'captain2');
$objID = $obj->ID;
// Check the page exists before deleting
$this->assertTrue(is_object($obj) && $obj->exists());
// Delete the page
DataObject::delete_by_id('DataObjectTest_Player', $obj->ID);
// Check that page does not exist after deleting
$obj = DataObject::get_by_id('DataObjectTest_Player', $objID);
$this->assertTrue(!$obj || !$obj->exists());
}
示例3: deleteitems
/**
* Delete a number of items
*/
public function deleteitems() {
$ids = split(' *, *', $_REQUEST['csvIDs']);
$script = "st = \$('sitetree'); \n";
foreach($ids as $id) {
if(is_numeric($id)) {
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
if($record && !$record->canDelete()) return Security::permissionFailure($this);
DataObject::delete_by_id($this->stat('tree_class'), $id);
$script .= "node = st.getTreeNodeByIdx($id); if(node) node.parentTreeNode.removeTreeNode(node); $('Form_EditForm').closeIfSetTo($id); \n";
}
}
FormResponse::add($script);
return FormResponse::respond();
}
示例4: saveInto
function saveInto(DataObjectInterface $record)
{
$relation = $this->getRelation();
if ($relation) {
$submittedTags = explode($this->getDelimiter(), $this->value);
$tagClass = $this->getTagClass();
$tagLabelField = $this->getTagLabelField();
$tagObjects = DataList::create($tagClass)->filter($tagLabelField, $submittedTags);
if ($tagObjects->Count() < count($submittedTags)) {
// filter out the tags that exist already
$tagsAsKeys = array_flip($submittedTags);
foreach ($tagObjects as $tag) {
$label = $tag->{$tagLabelField};
unset($tagsAsKeys[$label]);
}
foreach ($tagsAsKeys as $label => $value) {
$tagObject = new $tagClass();
$tagObject->{$tagLabelField} = $label;
$tagObject->write();
$tagObjects->add($tagObject);
}
}
$relationList = $this->form->record->{$this->name}();
$oldTags = $relationList->map('ID', $tagLabelField)->toArray();
$relationList->removeAll();
$relationList->addMany($tagObjects->toArray());
if ($this->deleteUnusedTags) {
$deletedTags = array_diff($oldTags, $tagObjects->map('ID', $tagLabelField)->toArray());
if (count($deletedTags) > 0) {
$relationTable = $relation[4];
foreach ($deletedTags as $id => $title) {
$query = new SQLQuery();
$query->select = array('ID', $tagLabelField);
$query->from = array($relationTable);
$query->where = array("ID = " . $id);
$count = $query->Count();
if ($count == 0) {
DataObject::delete_by_id($tagClass, $id);
}
}
}
}
} else {
if ($record->hasField($this->name)) {
$record->setCastedField($this->name, $this->dataValue());
} else {
// @TODO: better error handling
}
}
}
示例5: deleteitems
/**
* Delete a number of items
*/
public function deleteitems($request)
{
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$ids = split(' *, *', $_REQUEST['csvIDs']);
$script = "st = \$('sitetree'); \n";
foreach ($ids as $id) {
if (is_numeric($id)) {
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
if ($record && !$record->canDelete()) {
return Security::permissionFailure($this);
}
DataObject::delete_by_id($this->stat('tree_class'), $id);
$script .= "node = st.getTreeNodeByIdx({$id}); if(node) node.parentTreeNode.removeTreeNode(node); \$('Form_EditForm').closeIfSetTo({$id}); \n";
}
}
FormResponse::add($script);
return FormResponse::respond();
}
示例6: deleteitems
/**
* Delete a number of items
*/
public function deleteitems()
{
$ids = split(' *, *', $_REQUEST['csvIDs']);
$script = "st = \$('sitetree'); \n";
foreach ($ids as $id) {
if (is_numeric($id)) {
DataObject::delete_by_id($this->stat('tree_class'), $id);
$script .= "node = st.getTreeNodeByIdx({$id}); if(node) node.parentTreeNode.removeTreeNode(node); \$('Form_EditForm').closeIfSetTo({$id}); \n";
}
}
FormResponse::add($script);
return FormResponse::respond();
}
示例7: siteBuilderDeleteItem
/**
* @return bool
*/
public function siteBuilderDeleteItem()
{
if (Director::is_ajax()) {
$id = (int) $this->getRequest()->getVars()['ItemID'];
$container = DataObject::get_by_id('PageBuilderItem', $id);
if ($container) {
DataObject::delete_by_id('PageBuilderItem', $id);
}
}
return true;
}
示例8: onAfterDelete
protected function onAfterDelete()
{
/**
* Delete all has_many relationships associated with this controller.
*/
$items = $this->Items();
foreach ($items as $key => $item) {
DataObject::delete_by_id('PageBuilderItem', $item->ID);
}
parent::onAfterDelete();
}