本文整理汇总了PHP中SS_List::getIDList方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_List::getIDList方法的具体用法?PHP SS_List::getIDList怎么用?PHP SS_List::getIDList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SS_List
的用法示例。
在下文中一共展示了SS_List::getIDList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixSortColumn
/**
* Detects and corrects items with a sort column value of 0, by appending them to the bottom of the list
* @param GridField $gridField Grid Field Reference
* @param SS_List $dataList Data List of items to be checked
*/
protected function fixSortColumn($gridField, SS_List $dataList)
{
if (class_exists('UnsavedRelationList') && $dataList instanceof UnsavedRelationList) {
return;
}
$list = clone $dataList;
$list = $list->alterDataQuery(function ($query, SS_List $tmplist) {
$query->limit(array());
return $query;
});
$many_many = $list instanceof ManyManyList;
if (!$many_many) {
$sng = singleton($gridField->getModelClass());
$fieldType = $sng->db($this->sortColumn);
if (!$fieldType || !($fieldType == 'Int' || is_subclass_of('Int', $fieldType))) {
if (is_array($fieldType)) {
user_error('Sort column ' . $this->sortColumn . ' could not be found in ' . $gridField->getModelClass() . '\'s ancestry', E_USER_ERROR);
} else {
user_error('Sort column ' . $this->sortColumn . ' must be an Int, column is of type ' . $fieldType, E_USER_ERROR);
}
exit;
}
}
$max = $list->Max($this->sortColumn);
$list = $list->filter($this->sortColumn, 0)->sort("Created,ID");
if ($list->Count() > 0) {
$owner = $gridField->Form->getRecord();
$sortColumn = $this->sortColumn;
$i = 1;
if ($many_many) {
list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($gridField->getName());
$extraFields = $owner->many_many_extraFields($gridField->getName());
if (!$extraFields || !array_key_exists($this->sortColumn, $extraFields) || !($extraFields[$this->sortColumn] == 'Int' || is_subclass_of('Int', $extraFields[$this->sortColumn]))) {
user_error('Sort column ' . $this->sortColumn . ' must be an Int, column is of type ' . $extraFields[$this->sortColumn], E_USER_ERROR);
exit;
}
} else {
//Find table containing the sort column
$table = false;
$class = $gridField->getModelClass();
$db = Config::inst()->get($class, "db", CONFIG::UNINHERITED);
if (!empty($db) && array_key_exists($sortColumn, $db)) {
$table = $class;
} else {
$classes = ClassInfo::ancestry($class, true);
foreach ($classes as $class) {
$db = Config::inst()->get($class, "db", CONFIG::UNINHERITED);
if (!empty($db) && array_key_exists($sortColumn, $db)) {
$table = $class;
break;
}
}
}
if ($table === false) {
user_error('Sort column ' . $this->sortColumn . ' could not be found in ' . $gridField->getModelClass() . '\'s ancestry', E_USER_ERROR);
exit;
}
$baseDataClass = ClassInfo::baseDataClass($gridField->getModelClass());
}
//Start transaction if supported
if (DB::getConn()->supportsTransactions()) {
DB::getConn()->transactionStart();
}
$idCondition = null;
if ($this->append_to_top && !$list instanceof RelationList) {
$idCondition = '"ID" IN(\'' . implode("','", $dataList->getIDList()) . '\')';
}
if ($this->append_to_top) {
$topIncremented = array();
}
foreach ($list as $obj) {
if ($many_many) {
if ($this->append_to_top) {
//Upgrade all the records (including the last inserted from 0 to 1)
DB::query('UPDATE "' . $table . '" SET "' . $sortColumn . '" = "' . $sortColumn . '"+1' . ' WHERE "' . $parentField . '" = ' . $owner->ID . (!empty($topIncremented) ? ' AND "' . $componentField . '" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
$topIncremented[] = $obj->ID;
} else {
//Append the last record to the bottom
DB::query('UPDATE "' . $table . '" SET "' . $sortColumn . '" = ' . ($max + $i) . ' WHERE "' . $componentField . '" = ' . $obj->ID . ' AND "' . $parentField . '" = ' . $owner->ID);
}
} else {
if ($this->append_to_top) {
//Upgrade all the records (including the last inserted from 0 to 1)
DB::query('UPDATE "' . $table . '" SET "' . $sortColumn . '" = "' . $sortColumn . '"+1' . ' WHERE ' . ($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
//LastEdited
DB::query('UPDATE "' . $baseDataClass . '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\'' . ' WHERE ' . ($list instanceof RelationList ? '"' . $list->foreignKey . '" = ' . $owner->ID : $idCondition) . (!empty($topIncremented) ? ' AND "ID" NOT IN(\'' . implode('\',\'', $topIncremented) . '\')' : ''));
$topIncremented[] = $obj->ID;
} else {
//Append the last record to the bottom
DB::query('UPDATE "' . $table . '" SET "' . $sortColumn . '" = ' . ($max + $i) . ' WHERE "ID" = ' . $obj->ID);
//LastEdited
DB::query('UPDATE "' . $baseDataClass . '" SET "LastEdited" = \'' . date('Y-m-d H:i:s') . '\'' . ' WHERE "ID" = ' . $obj->ID);
}
}
$i++;
//.........这里部分代码省略.........