method order documentation in bbn\Appui\Option

Returns the order of an option. Updates it if a position is given, and cascades

Example

X::dump($opt->items(20)); // [21, 22, 25, 27] X::dump($opt->order(25)); // (int) 3 X::dump($opt->order(25, 2)); // (int) 2 X::dump($opt->items(20)); // [21, 25, 22, 27] X::dump($opt->order(25)); // (int) 2 function($id, int $pos = NULL) { if ($this->check() && ($parent = $this->getIdParent($id)) && $this->isSortable($parent) ) { $cf = $this->class_cfg; $old = $this->db->selectOne( $cf['table'], $this->fields['num'], [ $this->fields['id'] => $id ] ); if ($pos && ($old != $pos)) { $its = $this->items($parent); $past_new = false; $past_old = false; $p = 1; foreach ($its as $id_option){ $upd = false; // Fixing order problem if ($past_old && !$past_new) { $upd = [$this->fields['num'] => $p - 1]; } elseif (!$past_old && $past_new) { $upd = [$this->fields['num'] => $p + 1]; } if ($id === $id_option) { $upd = [$this->fields['num'] => $pos]; $past_old = 1; } elseif ($p === $pos) { $upd = [$this->fields['num'] => $p + ($pos > $old ? -1 : 1)]; $past_new = 1; } if ($upd) { $this->db->update( $cf['table'], $upd, [ $this->fields['id'] => $id_option ] ); } if ($past_new && $past_old) { break; } $p++; } $this->deleteCache($parent, true); $this->deleteCache($id); return $pos; } return $old; } return null; }

Returns the order of an option. Updates it if a position is given, and cascades BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.