Pods::last_id PHP 메소드

last_id() 공개 메소드

Return the last item ID
부터: 2.3
public last_id ( array $params_override = null ) : integer
$params_override array
리턴 integer
    public function last_id($params_override = null)
    {
        $params = array('select' => "`t`.`{$this->data->field_id}`", 'orderby' => "`t`.`{$this->data->field_id}` DESC", 'limit' => 1);
        if (!empty($params_override) || !empty($this->params)) {
            if (!empty($params_override)) {
                $params = $params_override;
            } elseif (!empty($this->params)) {
                $params = $this->params;
            }
            if (is_object($params)) {
                $params = get_object_vars($params);
            }
            if (isset($params['total_found'])) {
                $params['offset'] = $params['total_found'] - 1;
            } else {
                $params['offset'] = $this->total_found() - 1;
            }
            if (isset($params['orderby']) && !empty($params['orderby'])) {
                if (is_array($params['orderby'])) {
                    foreach ($params['orderby'] as $orderby => $dir) {
                        $dir = strtoupper($dir);
                        if (!in_array($dir, array('ASC', 'DESC'))) {
                            continue;
                        }
                        if ('ASC' == $dir) {
                            $params['orderby'][$orderby] = 'DESC';
                        } else {
                            $params['orderby'][$orderby] = 'ASC';
                        }
                    }
                    $params['orderby'][$this->data->field_id] = 'DESC';
                } elseif ("`t`.`{$this->data->field_id}` DESC" != $params['orderby']) {
                    $params['orderby'] .= ", `t`.`{$this->data->field_id}` DESC";
                }
            }
            $params['select'] = "`t`.`{$this->data->field_id}`";
            $params['limit'] = 1;
        }
        $pod = pods($this->pod, $params);
        $new_id = 0;
        if ($pod->fetch()) {
            $new_id = $pod->id();
        }
        $new_id = $this->do_hook('last_id', $new_id, $pod, $params_override);
        return $new_id;
    }