Jarves\Admin\ObjectCrud::getPosition PHP Method

getPosition() public method

public getPosition ( $pk, $order )
    public function getPosition($pk, $order)
    {
        /*$obj = $this->objects->getClass($this->getObject());
                $primaryKey = $obj->normalizePrimaryKey($pk);
        
                $condition = $this->getCondition();
        
                if ($customCondition = $this->getCustomListingCondition())
                    $condition = $condition ? array_merge($condition, $customCondition) : $customCondition;
        
                $options['permissionCheck'] = $this->permissionCheck;
                */
        $obj = $this->objects->getStorageController($this->getObject());
        $primaryKey = $obj->normalizePrimaryKey($pk);
        $found = $this->getItem($primaryKey, $this->getObjectDefinition()->getPrimaryKeyNames());
        if (!$found) {
            return null;
        }
        $items = $this->getItems(null, 1000, null, null, $this->getObjectDefinition()->getPrimaryKeyNames(), $order);
        $position = 0;
        $singlePrimaryKey = null;
        if (count($primaryKey) == 1) {
            $singlePrimaryKey = key($primaryKey);
            $singlePrimaryValue = current($primaryKey);
        }
        while (true) {
            $item = current($items);
            if ($singlePrimaryKey) {
                if ($item[$singlePrimaryKey] == $singlePrimaryValue) {
                    break;
                }
            } else {
                $isItem = true;
                foreach ($primaryKey as $prim => $val) {
                    if ($item[$prim] != $val) {
                        $isItem = false;
                    }
                }
                if ($isItem) {
                    break;
                }
            }
            if (!next($items)) {
                $items = $this->getItems(null, 1000, $position, null, $this->getObjectDefinition()->getPrimaryKeyNames(), $order);
                if (!$items) {
                    break;
                }
            }
            $position++;
        }
        return $position;
    }
ObjectCrud