Skip to content

Commit fa3e94c

Browse files
committed
datatables as usable functions
1 parent cecd200 commit fa3e94c

8 files changed

Lines changed: 563 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
# vim: ts=4 sw=4 et:
3+
/************************************************************************
4+
* This file is part of EspoCRM.
5+
*
6+
* EspoCRM - Open Source CRM application.
7+
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
8+
* Website: https://www.espocrm.com
9+
*
10+
* EspoCRM is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* EspoCRM is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
22+
*
23+
* The interactive user interfaces in modified source and object code versions
24+
* of this program must display Appropriate Legal Notices, as required under
25+
* Section 5 of the GNU General Public License version 3.
26+
*
27+
* In accordance with Section 7(b) of the GNU General Public License version 3,
28+
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
29+
************************************************************************/
30+
31+
namespace Espo\Modules\HookedFormulas\Core\Formula\Functions\TableGroup;
32+
33+
use Espo\Core\Exceptions\Error;
34+
35+
class AddType extends \Espo\Core\Formula\Functions\Base
36+
{
37+
public function process(\StdClass $item)
38+
{
39+
40+
if (count($item->value) < 2) throw new Error("Formula table\\add: needs <table> and <column values> as arguments.");
41+
42+
$var = $item->value[0]->value;
43+
$type = $item->value[0]->type;
44+
45+
$table = $this->evaluate($item->value[0]);
46+
$ncols = count($table->header);
47+
48+
if (count($item->value) != ($ncols + 1)) throw new Error('Formula table\add: needs '.$ncols.' columns as arguments.');
49+
50+
$row = [];
51+
for($i = 1; $i <= $ncols; $i++ ) {
52+
array_push($row, $this->evaluate($item->value[$i]));
53+
}
54+
55+
array_push($table->rows, $row);
56+
array_push($table->styles, '');
57+
58+
$this->getVariables()->$var = $table;
59+
60+
return $table;
61+
}
62+
}
63+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
# vim: ts=4 sw=4 et:
3+
/************************************************************************
4+
* This file is part of EspoCRM.
5+
*
6+
* EspoCRM - Open Source CRM application.
7+
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
8+
* Website: https://www.espocrm.com
9+
*
10+
* EspoCRM is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* EspoCRM is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
22+
*
23+
* The interactive user interfaces in modified source and object code versions
24+
* of this program must display Appropriate Legal Notices, as required under
25+
* Section 5 of the GNU General Public License version 3.
26+
*
27+
* In accordance with Section 7(b) of the GNU General Public License version 3,
28+
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
29+
************************************************************************/
30+
31+
namespace Espo\Modules\HookedFormulas\Core\Formula\Functions\TableGroup;
32+
33+
use Espo\Core\Exceptions\Error;
34+
35+
class FilenameType extends \Espo\Core\Formula\Functions\Base
36+
{
37+
public function process(\StdClass $item)
38+
{
39+
40+
if (count($item->value) != 2) throw new Error("Formula table\\filename: needs <table> <filename> as arguments.");
41+
42+
$var = $item->value[0]->value;
43+
$type = $item->value[0]->type;
44+
45+
$filename = $this->evaluate($item->value[1]);
46+
47+
$table = $this->evaluate($item->value[0]);
48+
49+
$table->filename = $filename;
50+
51+
$this->getVariables()->$var = $table;
52+
53+
return $table;
54+
}
55+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
# vim: ts=4 sw=4 et:
3+
/************************************************************************
4+
* This file is part of EspoCRM.
5+
*
6+
* EspoCRM - Open Source CRM application.
7+
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
8+
* Website: https://www.espocrm.com
9+
*
10+
* EspoCRM is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* EspoCRM is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
22+
*
23+
* The interactive user interfaces in modified source and object code versions
24+
* of this program must display Appropriate Legal Notices, as required under
25+
* Section 5 of the GNU General Public License version 3.
26+
*
27+
* In accordance with Section 7(b) of the GNU General Public License version 3,
28+
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
29+
************************************************************************/
30+
31+
namespace Espo\Modules\HookedFormulas\Core\Formula\Functions\TableGroup;
32+
33+
use Espo\Core\Exceptions\Error;
34+
35+
class LinkType extends \Espo\Core\Formula\Functions\Base
36+
{
37+
public function process(\StdClass $item)
38+
{
39+
40+
$n = count($item->value);
41+
if ($n != 2 && $n != 3) {
42+
throw new Error("Formula table\\LinkPage: needs <href> <value> [<target>] as arguments.");
43+
}
44+
45+
$href = $this->evaluate($item->value[0]);
46+
$val = $this->evaluate($item->value[1]);
47+
48+
$obj = [ 'href' => $href, 'val' => $val ];
49+
50+
if ($n == 3) {
51+
$target = $this->evaluate($item->value[2]);
52+
if ($target) {
53+
$obj['target'] = $target;
54+
}
55+
}
56+
57+
return $obj;
58+
}
59+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
# vim: ts=4 sw=4 et:
3+
/************************************************************************
4+
* This file is part of EspoCRM.
5+
*
6+
* EspoCRM - Open Source CRM application.
7+
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
8+
* Website: https://www.espocrm.com
9+
*
10+
* EspoCRM is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* EspoCRM is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
22+
*
23+
* The interactive user interfaces in modified source and object code versions
24+
* of this program must display Appropriate Legal Notices, as required under
25+
* Section 5 of the GNU General Public License version 3.
26+
*
27+
* In accordance with Section 7(b) of the GNU General Public License version 3,
28+
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
29+
************************************************************************/
30+
31+
namespace Espo\Modules\HookedFormulas\Core\Formula\Functions\TableGroup;
32+
33+
use Espo\Core\Exceptions\Error;
34+
35+
class NewType extends \Espo\Core\Formula\Functions\Base
36+
{
37+
public function process(\StdClass $item)
38+
{
39+
$args = $this->fetchArguments($item);
40+
41+
if (count($args) < 1) throw new Error("Formula table\new: needs columns as arguments.");
42+
43+
$datatable_header = [];
44+
$obj = [];
45+
while(count($args) > 0) {
46+
$arg = array_shift($args);
47+
if (is_int($arg)) { $obj['width'] = $arg; }
48+
else if ($arg == 'asc') { $obj['sort'] = 'asc'; }
49+
else if ($arg == 'desc') { $obj['sort'] = 'desc'; }
50+
else if ($arg == 'ellipsis') { $obj['ellipsis'] = true; }
51+
else if ($arg == 'right' || $arg == 'left' || $arg == 'center') { $obj['align'] = $arg; }
52+
else {
53+
if (isset($obj['column'])) {
54+
array_push($datatable_header, $obj);
55+
}
56+
$obj = [];
57+
$obj['column'] = $arg;
58+
}
59+
}
60+
array_push($datatable_header, $obj);
61+
62+
$datatable = (object)[ 'header' => $datatable_header, 'rows' => [], 'styles' => [], 'rows_per_page' => 15, 'filename' => '' ];
63+
64+
return $datatable;
65+
}
66+
67+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
# vim: ts=4 sw=4 et:
3+
/************************************************************************
4+
* This file is part of EspoCRM.
5+
*
6+
* EspoCRM - Open Source CRM application.
7+
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
8+
* Website: https://www.espocrm.com
9+
*
10+
* EspoCRM is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* EspoCRM is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
22+
*
23+
* The interactive user interfaces in modified source and object code versions
24+
* of this program must display Appropriate Legal Notices, as required under
25+
* Section 5 of the GNU General Public License version 3.
26+
*
27+
* In accordance with Section 7(b) of the GNU General Public License version 3,
28+
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
29+
************************************************************************/
30+
31+
namespace Espo\Modules\HookedFormulas\Core\Formula\Functions\TableGroup;
32+
33+
use Espo\Core\Exceptions\Error;
34+
35+
class RowsPerPageType extends \Espo\Core\Formula\Functions\Base
36+
{
37+
public function process(\StdClass $item)
38+
{
39+
40+
if (count($item->value) != 2) throw new Error("Formula table\\rowsPerPage: needs <table> <rows per page> as arguments.");
41+
42+
$var = $item->value[0]->value;
43+
$type = $item->value[0]->type;
44+
45+
$rows = $this->evaluate($item->value[1]);
46+
47+
$table = $this->evaluate($item->value[0]);
48+
49+
$table->rows_per_page = $rows;
50+
51+
$this->getVariables()->$var = $table;
52+
53+
return $table;
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
# vim: ts=4 sw=4 et:
3+
/************************************************************************
4+
* This file is part of EspoCRM.
5+
*
6+
* EspoCRM - Open Source CRM application.
7+
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
8+
* Website: https://www.espocrm.com
9+
*
10+
* EspoCRM is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* EspoCRM is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
22+
*
23+
* The interactive user interfaces in modified source and object code versions
24+
* of this program must display Appropriate Legal Notices, as required under
25+
* Section 5 of the GNU General Public License version 3.
26+
*
27+
* In accordance with Section 7(b) of the GNU General Public License version 3,
28+
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
29+
************************************************************************/
30+
31+
namespace Espo\Modules\HookedFormulas\Core\Formula\Functions\TableGroup;
32+
33+
use Espo\Core\Exceptions\Error;
34+
35+
class StyleType extends \Espo\Core\Formula\Functions\Base
36+
{
37+
public function process(\StdClass $item)
38+
{
39+
40+
if (count($item->value) != 2) throw new Error("Formula table\\style: needs <table> <style> as arguments.");
41+
42+
$var = $item->value[0]->value;
43+
$type = $item->value[0]->type;
44+
45+
$style = $this->evaluate($item->value[1]);
46+
$table = $this->evaluate($item->value[0]);
47+
48+
$table->styles[count($table->styles) - 1] = $style;
49+
50+
$this->getVariables()->$var = $table;
51+
52+
return $table;
53+
}
54+
}

0 commit comments

Comments
 (0)