X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdraggableviews%2Fsrc%2FDraggableViews.php;fp=web%2Fmodules%2Fcontrib%2Fdraggableviews%2Fsrc%2FDraggableViews.php;h=da5e99dcb4453b1d0676530a02c154082607aafb;hp=0000000000000000000000000000000000000000;hb=1fed477e46533140ff15ce8064f4fbf354419c1c;hpb=58360fba03c880fb30fb0670e485a7a07d028597 diff --git a/web/modules/contrib/draggableviews/src/DraggableViews.php b/web/modules/contrib/draggableviews/src/DraggableViews.php new file mode 100644 index 000000000..da5e99dcb --- /dev/null +++ b/web/modules/contrib/draggableviews/src/DraggableViews.php @@ -0,0 +1,88 @@ +view = $view; + } + + /** + * Get index by name and id. + */ + public function getIndex($name, $id) { + foreach ($this->view->result as $item) { + if ($item->$name == $id) { + return $item->index; + } + } + return FALSE; + } + + /** + * Get depth by index. + */ + public function getDepth($index) { + if (!isset($this->view->result[$index])) { + return FALSE; + } + $row = $this->view->result[$index]; + // If parent is available, set parent's depth +1. + return (!empty($row->draggableviews_structure_parent)) ? $this->getDepth($this->getIndex('nid', $row->draggableviews_structure_parent)) + 1 : 0; + } + + /** + * Get parent by index. + */ + public function getParent($index) { + return isset($this->view->result[$index]->draggableviews_structure_parent) ? $this->view->result[$index]->draggableviews_structure_parent : 0; + } + + /** + * Get ancestor by index. + */ + public function getAncestor($index) { + $row = $this->view->result[$index]; + return !empty($row->draggableviews_structure_parent) ? $this->getAncestor($this->getIndex('nid', $row->draggableviews_structure_parent)) : $index; + } + + /** + * Return value by it's name and index. + */ + public function getValue($name, $index) { + return $this->view->result[$index]->$name; + } + + /** + * Get HTML id for draggableviews table. + */ + public function getHtmlId() { + return Html::getId('draggableviews-table-' . $this->view->id() . '-' . $this->view->current_display); + } + +}