aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-03-23 21:04:15 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-03-23 21:04:46 +0100
commit1a93d70c938f3ae2b050f3a102c961cf1cc3cefc (patch)
treeb7ae3dd51fc3008169295d693f320fae901b14af /app/class
parenta7174bb27de46b2f64118181221fad3658f511d3 (diff)
downloadwcms-1a93d70c938f3ae2b050f3a102c961cf1cc3cefc.tar.gz
wcms-1a93d70c938f3ae2b050f3a102c961cf1cc3cefc.zip
filter map and orphans hide
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Controllerhome.php12
-rw-r--r--app/class/Model.php5
-rw-r--r--app/class/Modelhome.php157
-rw-r--r--app/class/Modelpage.php26
4 files changed, 146 insertions, 54 deletions
diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php
index 4fa9a0b..6444ac2 100644
--- a/app/class/Controllerhome.php
+++ b/app/class/Controllerhome.php
@@ -34,7 +34,12 @@ class Controllerhome extends Controllerpage
$deepsearch = $this->deepsearch();
- $vars['table2'] = $this->modelhome->table2($pagelist, $this->opt, $deepsearch['regex'] , $deepsearch['searchopt']);
+ $idlistfilter = $this->modelhome->filter($pagelist, $this->opt);
+ $pagelistfilter = $this->modelhome->pagelistfilter($pagelist, $idlistfilter);
+ $pagelistdeep = $this->modelhome->deepsearch($pagelistfilter, $deepsearch['regex'] , $deepsearch['searchopt']);
+ $pagelistsort = $this->modelhome->sort($pagelistdeep, $this->opt);
+ $vars['pagelistopt'] = $pagelistsort;
+
$vars['columns'] = $this->modelhome->setcolumns($this->user->columns());
@@ -47,9 +52,10 @@ class Controllerhome extends Controllerpage
$vars['searchopt'] = $deepsearch['searchopt'];
$vars['display'] = $_GET['display'] ?? 'list';
- $vars['layout'] = $_GET['layout'] ?? 'random';
if($vars['display'] === 'map') {
- $datas = $this->modelhome->cytodata($vars['table2'], $vars['layout']);
+ $vars['layout'] = $_GET['layout'] ?? 'cose-bilkent';
+ $vars['hideorphans'] = boolval($_GET['hideorphans'] ?? false);
+ $datas = $this->modelhome->cytodata($pagelistsort, $vars['layout'], $vars['hideorphans']);
$vars['json'] = json_encode($datas, JSON_PRETTY_PRINT);
}
diff --git a/app/class/Model.php b/app/class/Model.php
index ae56c2f..9e66af4 100644
--- a/app/class/Model.php
+++ b/app/class/Model.php
@@ -23,9 +23,12 @@ abstract class Model
const MAP_LAYOUTS = [
'cose' => 'cose',
+ 'cose-bilkent' => 'cose-bilkent',
'circle' => 'circle',
+ 'breadthfirst' => 'breadthfirst',
+ 'concentric' => 'concentric',
+ 'grid' => 'grid',
'random' => 'random',
- 'cose-bilkent' => 'cose-bilkent'
];
diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php
index 9aab4f2..ede9179 100644
--- a/app/class/Modelhome.php
+++ b/app/class/Modelhome.php
@@ -40,65 +40,84 @@ class Modelhome extends Modelpage
+
/**
- * @param array $table
+ * Filter the pages list acording to the options and invert
+ *
+ * @param array $pagelist of `Page` objects
* @param Opt $opt
- * @param string $regex
*
- * @return array of `Page` object
+ * @return array of `string` pages id
*/
- public function table2(array $table, Opt $opt, string $regex = "", array $searchopt = []) : array
- {
+ public function filter(array $pagelist, Opt $opt) : array
+ {
- $filtertagfilter = $this->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare());
- $filterauthorfilter = $this->filterauthorfilter($table, $opt->authorfilter(), $opt->authorcompare());
- $filtersecure = $this->filtersecure($table, $opt->secure());
- $filterlinkto = $this->filterlinkto($table, $opt->linkto());
+ $filtertagfilter = $this->filtertagfilter($pagelist, $opt->tagfilter(), $opt->tagcompare());
+ $filterauthorfilter = $this->filterauthorfilter($pagelist, $opt->authorfilter(), $opt->authorcompare());
+ $filtersecure = $this->filtersecure($pagelist, $opt->secure());
+ $filterlinkto = $this->filterlinkto($pagelist, $opt->linkto());
$filter = array_intersect($filtertagfilter, $filtersecure, $filterauthorfilter, $filterlinkto);
- $table2 = [];
- $table2invert = [];
- foreach ($table as $page) {
- if (in_array($page->id(), $filter)) {
- $table2[] = $page;
- } else {
- $table2invert[] = $page;
- }
-
+ if($opt->invert()) {
+ $idlist = array_keys($pagelist);
+ $filter = array_diff($idlist, $filter);
}
- if (!empty($opt->invert())) {
- $table2 = $table2invert;
- }
+ return $filter;
+ }
- if(!empty($regex)) {
- $table2 = $this->deepsearch($regex, $searchopt, $table2);
- }
- $this->pagelistsort($table2, $opt->sortby(), $opt->order());
+
+ /**
+ * Convert list of id into a list of Page objects
+ *
+ * @param array $pagelist
+ * @param array $idlist
+ *
+ * @return array Filtered list of `Page` objects
+ */
+ public function pagelistfilter(array $pagelist, array $fiter) : array
+ {
+ return array_intersect_key($pagelist, array_flip($fiter));
+ }
+
+
+
+
+
+ /**
+ * Sort and limit an array of Pages
+ *
+ * @param array $pagelist of `Page` objects
+ * @param Opt $opt
+ *
+ * @return array associative array of `Page` objects
+ */
+ public function sort(array $pagelist, Opt $opt) : array
+ {
+ $this->pagelistsort($pagelist, $opt->sortby(), $opt->order());
if($opt->limit() !== 0) {
- $table2 = array_slice($table2, 0, $opt->limit());
+ $pagelist = array_slice($pagelist, 0, $opt->limit());
}
-
- return $table2;
+ return $pagelist;
}
/**
* Search for regex and count occurences
*
+ * @param array $page list Array of Pages.
* @param string $regex Regex to match.
* @param array $options Option search, could be `content` `title` `description`.
- * @param array $page list Array of Pages.
*
- * @return array associative array of Pages
+ * @return array associative array of `Page` objects
*/
- public function deepsearch(string $regex, array $options, array $pagelist) : array
+ public function deepsearch(array $pagelist, string $regex, array $options) : array
{
if($options['casesensitive']) {
$case = '';
@@ -128,21 +147,38 @@ class Modelhome extends Modelpage
$count += preg_match($regex, $page->description());
}
if ($count !== 0) {
- $pageselected[] = $page;
+ $pageselected[$page->id()] = $page;
}
}
return $pageselected;
}
+
+
/**
* Transform list of page into list of nodes and edges
+ *
+ * @param array $pagelist associative array of pages as `id => Page`
+ * @param string $layout
+ * @param bool $hideorphans if `true`, remove orphans pages
+ *
+ *
*/
- public function cytodata(array $pagelist, string $layout = 'random')
+ public function cytodata(array $pagelist, string $layout = 'random', bool $hideorphans = false)
{
- $datas['elements'] = $this->mapdata($pagelist);
+ $datas['elements'] = $this->mapdata($pagelist, $hideorphans);
$datas['layout'] = [
'name' => $layout,
+ 'quality' => 'proof',
+ 'fit' => true,
+ 'randomize' => true,
+ 'nodeDimensionsIncludeLabels' => true,
+ 'tile' => false,
+ 'edgeElasticity' => 0.75,
+ 'gravity' => 0.25,
+ 'idealEdgeLength' => 60,
+ 'numIter' => 10000
];
$datas['style'] = [
[
@@ -162,25 +198,54 @@ class Modelhome extends Modelpage
return $datas;
}
- public function mapdata(array $pagelist)
+ /**
+ * Transform list of Pages into cytoscape nodes and edge datas
+ *
+ * @param array $pagelist associative array of pages as `id => Page`
+ * @param bool $hideorphans if `true`, remove orphans pages
+ *
+ * @return array of cytoscape datas
+ */
+ public function mapdata(array $pagelist, bool $hideorphans = false) : array
{
- $nodes = [];
+ $idlist = array_keys($pagelist);
+
$edges = [];
foreach ($pagelist as $page) {
- $node['group'] = 'nodes';
- $node['data']['id'] = $page->id();
- $node['classes'] = [$page->secure('string')];
- $nodes[] = $node;
+ foreach ($page->linkto() as $linkto) {
+ if(in_array($linkto, $idlist)) {
+ $edge['group'] = 'edges';
+ $edge['data']['id'] = $page->id() . '>' . $linkto;
+ $edge['data']['source'] = $page->id();
+ $edge['data']['target'] = $linkto;
+ $edges[] = $edge;
+ $notorphans[] = $linkto;
+ }
+ }
+ if(!empty($page->linkto())) {
+ $notorphans[] = $page->id();
+ }
+ }
+ $notorphans = array_unique($notorphans);
- foreach ($page->linkto() as $linkto) {
- $edge['group'] = 'edges';
- $edge['data']['id'] = $page->id() . '>' . $linkto;
- $edge['data']['source'] = $page->id();
- $edge['data']['target'] = $linkto;
- $edges[] = $edge;
+ $nodes = [];
+ foreach ($pagelist as $id => $page) {
+ if($hideorphans) {
+ if(in_array($id, $notorphans)) {
+ $node['group'] = 'nodes';
+ $node['data']['id'] = $page->id();
+ $node['classes'] = [$page->secure('string')];
+ $nodes[] = $node;
+ }
+ } else {
+ $node['group'] = 'nodes';
+ $node['data']['id'] = $page->id();
+ $node['classes'] = [$page->secure('string')];
+ $nodes[] = $node;
}
}
+
return array_merge($nodes, $edges);
}
diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php
index 9344089..43ba117 100644
--- a/app/class/Modelpage.php
+++ b/app/class/Modelpage.php
@@ -27,7 +27,7 @@ class Modelpage extends Modeldb
/**
* Scan library for all pages as objects
*
- * @return array of Pages objects
+ * @return array of Pages objects as `id => Page`
*/
public function getlister()
{
@@ -232,7 +232,7 @@ class Modelpage extends Modeldb
public function pagelistsort(&$pagelist, $sortby, $order = 1)
{
- return usort($pagelist, $this->buildsorter($sortby, $order));
+ return uasort($pagelist, $this->buildsorter($sortby, $order));
}
@@ -241,7 +241,7 @@ class Modelpage extends Modeldb
* @param array $tagchecked list of tags
* @param string $tagcompare string, can be 'OR' or 'AND', set the tag filter method
*
- * @return array $array
+ * @return array $array of `string` page id
*/
public function filtertagfilter(array $pagelist, array $tagchecked, $tagcompare = 'OR')
@@ -267,6 +267,16 @@ class Modelpage extends Modeldb
return $filteredlist;
}
+
+
+ /**
+ * @param array $pagelist List of Page
+ * @param array $authorchecked list of authors
+ * @param string $authorcompare, can be 'OR' or 'AND', set the author filter method
+ *
+ * @return array $array of `string` page id
+ */
+
public function filterauthorfilter(array $pagelist, array $authorchecked, $authorcompare = 'OR')
{
@@ -290,7 +300,15 @@ class Modelpage extends Modeldb
return $filteredlist;
}
- public function filtersecure(array $pagelist, $secure) : array
+ /**
+ * @param array $pagelist List of Page
+ * @param int $secure secure level
+ * @param string $authorcompare, can be 'OR' or 'AND', set the author filter method
+ *
+ * @return array $array of `string` page id
+ */
+
+ public function filtersecure(array $pagelist, int $secure) : array
{
$filteredlist = [];
foreach ($pagelist as $page) {