本文整理汇总了PHP中DataObjectInterface::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectInterface::exists方法的具体用法?PHP DataObjectInterface::exists怎么用?PHP DataObjectInterface::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObjectInterface
的用法示例。
在下文中一共展示了DataObjectInterface::exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveInto
public function saveInto(DataObjectInterface $record)
{
$isNew = !$record->exists();
parent::saveInto($record);
// if we're dealing with an unsaved record, we have to rebuild the relation list
// with the proper meny_many_extraFields attributes (eg. the sort order)
if ($isNew) {
// we have to grab the raw post data as the data is in the right order there.
// this is kind of a hack, but we simply lack the information about the client-side sorting otherwise
if (isset($_POST[$this->name]) && isset($_POST[$this->name]['Files']) && is_array($_POST[$this->name]['Files'])) {
$idList = $_POST[$this->name]['Files'];
} else {
// take the ItemIDs as a fallback
$idList = $this->getItemIDs();
}
$sortColumn = $this->getSortColumn();
$relationName = $this->getName();
if ($relationName && $record->many_many($relationName) !== null && ($list = $record->{$relationName}())) {
$arrayList = $list->toArray();
foreach ($arrayList as $item) {
$list->remove($item);
$list->add($item, array($sortColumn => array_search($item->ID, $idList) + 1));
}
}
}
}
示例2: saveInto
public function saveInto(DataObjectInterface $record)
{
$isNew = !$record->exists();
parent::saveInto($record);
// if we're dealing with an unsaved record, we have to rebuild the relation list
// with the proper many_many_extraFields attributes (eg. the sort order)
if ($isNew) {
// we have to grab the raw post data as the data is in the right order there.
// this is kind of a hack, but we simply lack the information about the client-side sorting otherwise
if (isset($_POST[$this->name]) && isset($_POST[$this->name]['Files']) && is_array($_POST[$this->name]['Files'])) {
$idList = $_POST[$this->name]['Files'];
} else {
// take the ItemIDs as a fallback
$idList = $this->getItemIDs();
}
// Get general info about this relation (if possible)
$sortColumn = $this->getSortColumn();
$relationName = $this->getName();
if ($relationName) {
// Get relation type.
$isManyMany = $record->many_many($relationName) !== null;
// Using "null" here since we know it will properly return null if there is no many_many component by this name.
$isHasMany = (bool) $record->has_many($relationName);
// TODO: Return to more strict check of === null here when SS framework issue is mainstream: https://github.com/silverstripe/silverstripe-framework/pull/4130
if ($isManyMany || $isHasMany) {
// Get list from that relation and begin to manipulate it.
$list = $record->{$relationName}();
$arrayList = $list->toArray();
foreach ($arrayList as $item) {
// Get the specified sort order for this item (offset from posted 0 index).
$sortOrder = array_search($item->ID, $idList) + 1;
// The method by which we update this relation varies depending on the relationship type...
if ($isManyMany) {
// Alter data in the pivot table.
$list->remove($item);
$list->add($item, array($sortColumn => $sortOrder));
} elseif ($isHasMany) {
// Just update information in the sort field directly on the item itself.
$item->{$sortColumn} = $sortOrder;
$item->write();
}
}
}
}
}
}
示例3: setElementalContent
/**
* Write an ElementContent block with $Content.
*
* @return boolean
*/
public function setElementalContent(DataObjectInterface $record, $post_content)
{
if (!isset($this->_classes_using_wordpress_extension['ElementContent'])) {
throw new WordpressImportException('Must put "WordpressImportDataExtension" on BaseElement.');
}
if (!isset($this->_classes_using_elemental[$record->class])) {
if ($record instanceof SiteTree) {
throw new WordpressImportException('Must put "WordpressImportDataExtension" on SiteTree.');
} else {
throw new WordpressImportException('Must put "WordpressImportDataExtension" on ' . $record->class . '.');
}
}
$post_content = trim($this->_db->process('post_content', $post_content));
$elementBlocks = $record->ElementArea()->Elements();
if (!$record->exists()) {
$subRecord = ElementContent::create();
$subRecord->HTML = $post_content;
$subRecord->WordpressData = $record->WordpressData;
$elementBlocks->add($subRecord);
// note(Jake): when page $record is written, the rest will write into it. 3.2+ at least.
} else {
$subRecord = $elementBlocks->filter(array('WordpressID' => $record->WordpressID, 'ClassName' => 'ElementContent'))->first();
$isNew = false;
if (!$subRecord) {
$subRecord = ElementContent::create();
$isNew = true;
}
if ($subRecord->HTML !== $post_content) {
// Avoid getChangedFields triggering below by checking equality first.
$subRecord->HTML = $post_content;
}
$subRecord->WordpressData = $record->WordpressData;
$changedFields = $subRecord->getChangedFields(true, DataObject::CHANGE_VALUE);
if ($changedFields) {
try {
$isPublished = $subRecord->isPublished();
$this->writeAndPublishRecord($subRecord);
return true;
} catch (Exception $e) {
$this->log($subRecord, 'error', $e, 1);
throw $e;
}
}
if ($isNew) {
$elementBlocks->add($subRecord);
}
}
}
开发者ID:silbinarywolf,项目名称:silverstripe-wordpressmigrationtools,代码行数:53,代码来源:WordpressImportService.php