eZContentOperationCollection::changeSortOrder PHP Method

changeSortOrder() public static method

Changes the sort order for a node
public static changeSortOrder ( integer $nodeID, string $sortingField, boolean $sortingOrder = false ) : array
$nodeID integer
$sortingField string
$sortingOrder boolean
return array An array with operation status, always true
    public static function changeSortOrder($nodeID, $sortingField, $sortingOrder = false)
    {
        $curNode = eZContentObjectTreeNode::fetch($nodeID);
        if (is_object($curNode)) {
            $db = eZDB::instance();
            $db->begin();
            $curNode->setAttribute('sort_field', $sortingField);
            $curNode->setAttribute('sort_order', $sortingOrder);
            $curNode->store();
            $db->commit();
            $object = $curNode->object();
            eZContentCacheManager::clearContentCacheIfNeeded($object->attribute('id'));
        }
        return array('status' => true);
    }

Usage Example

Esempio n. 1
0
            }
            eZContentBrowse::browse(array('action_name' => 'NewObjectAddNodeAssignment', 'description_template' => 'design:content/browse_first_placement.tpl', 'keys' => array('class' => $class->attribute('id'), 'classgroup' => $class->attribute('ingroup_id_list')), 'persistent_data' => array('ClassID' => $class->attribute('id'), 'ContentLanguageCode' => $languageCode), 'content' => array('class_id' => $class->attribute('id')), 'cancel_page' => $module->redirectionURIForModule($module, 'view', array('full', 2)), 'from_page' => "/content/action"), $module);
        }
    }
} else {
    if ($http->hasPostVariable('SetSorting') && $http->hasPostVariable('ContentObjectID') && $http->hasPostVariable('ContentNodeID') && $http->hasPostVariable('SortingField') && $http->hasPostVariable('SortingOrder')) {
        $nodeID = $http->postVariable('ContentNodeID');
        $contentObjectID = $http->postVariable('ContentObjectID');
        $sortingField = $http->postVariable('SortingField');
        $sortingOrder = $http->postVariable('SortingOrder');
        $node = eZContentObjectTreeNode::fetch($nodeID);
        $contentObject = eZContentObject::fetch($contentObjectID);
        if (eZOperationHandler::operationIsAvailable('content_sort')) {
            $operationResult = eZOperationHandler::execute('content', 'sort', array('node_id' => $nodeID, 'sorting_field' => $sortingField, 'sorting_order' => $sortingOrder), null, true);
        } else {
            eZContentOperationCollection::changeSortOrder($nodeID, $sortingField, $sortingOrder);
        }
        if ($http->hasPostVariable('RedirectURIAfterSorting')) {
            return $module->redirectTo($http->postVariable('RedirectURIAfterSorting'));
        }
        return $module->redirectToView('view', array('full', $nodeID, $languageCode));
    } else {
        if ($module->isCurrentAction('MoveNode')) {
            /* This action is used through the admin interface with the "Move" button,
             * or in the pop-up menu and will move a node to a different location. */
            if (!$module->hasActionParameter('NodeID')) {
                eZDebug::writeError("Missing NodeID parameter for action " . $module->currentAction(), 'content/action');
                return $module->redirectToView('view', array('full', 2));
            }
            if ($module->hasActionParameter('NewParentNode')) {
                $selectedNodeID = $module->actionParameter('NewParentNode');