/** * Called when new item creates * Calc position for item and set it */ private function assign_position() { $sql_tail = ''; if (!$this->container->with_positions()) { return; } $pos = $this->get_valid_field('position'); if (isset($pos['space'])) { $sql_tail = ' WHERE ' . $this->make_space_sql($pos['space']); } $sql = "SELECT max(position) as mp FROM " . $this->get_table() . $sql_tail; $row = $this->db->sql_fetchrow($this->db->sql_query($sql)); $this->position = (int) $row['mp'] + 1; }