1 | <?php |
||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * wgGitHub module for xoops |
||
14 | * |
||
15 | * @copyright 2020 XOOPS Project (https://xooops.org) |
||
16 | * @license GPL 2.0 or later |
||
17 | * @package wggithub |
||
18 | * @since 1.0 |
||
19 | * @min_xoops 2.5.10 |
||
20 | * @author Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com> |
||
21 | */ |
||
22 | |||
23 | use XoopsModules\Wggithub; |
||
24 | use XoopsModules\Wggithub\ { |
||
25 | Helper, |
||
26 | Constants |
||
27 | }; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * search callback functions |
||
32 | * |
||
33 | * @param $queryarray |
||
34 | * @param $andor |
||
35 | * @param $limit |
||
36 | * @param $offset |
||
37 | * @param $userid |
||
38 | * @return mixed $itemIds |
||
39 | */ |
||
40 | function wggithub_search($queryarray, $andor, $limit, $offset, $userid) |
||
0 ignored issues
–
show
|
|||
41 | { |
||
42 | $ret = []; |
||
43 | $helper = Helper::getInstance(); |
||
44 | $repositoriesHandler = $helper->getHandler('Repositories'); |
||
45 | $directoriesHandler = $helper->getHandler('Directories'); |
||
46 | |||
47 | // search in table wggithub_repositories |
||
48 | $directories = []; |
||
49 | $directoriesAll = $directoriesHandler->getAll(); |
||
50 | foreach (\array_keys($directoriesAll) as $i) { |
||
51 | $directories[$directoriesAll[$i]->getVar('dir_name')] = $directoriesAll[$i]->getVar('dir_id'); |
||
52 | } |
||
53 | unset ($directoriesAll); |
||
54 | |||
55 | // search keywords |
||
56 | $elementCount = 0; |
||
57 | if (\is_array($queryarray)) { |
||
58 | $elementCount = \count($queryarray); |
||
59 | } |
||
60 | if ($elementCount > 0) { |
||
61 | $crKeywords = new \CriteriaCompo(); |
||
62 | for ($i = 0; $i < $elementCount; $i++) { |
||
63 | $crKeywords->add(new \Criteria('repo_name', '%' . $queryarray[$i] . '%', 'LIKE'), 'OR'); |
||
64 | } |
||
65 | } |
||
66 | // search user(s) |
||
67 | if ($userid && \is_array($userid)) { |
||
68 | $userid = array_map('intval', $userid); |
||
69 | $crUser = new \CriteriaCompo(); |
||
70 | $crUser->add(new \Criteria('repo_submitter', '(' . \implode(',', $userid) . ')', 'IN'), 'OR'); |
||
71 | } elseif (is_numeric($userid) && $userid > 0) { |
||
72 | $crUser = new \CriteriaCompo(); |
||
73 | $crUser->add(new \Criteria('repo_submitter', $userid), 'OR'); |
||
74 | } |
||
75 | $crSearch = new \CriteriaCompo(); |
||
76 | if (isset($crKeywords)) { |
||
77 | $crSearch->add($crKeywords, 'AND'); |
||
78 | } |
||
79 | if (isset($crUser)) { |
||
80 | $crSearch->add($crUser, 'AND'); |
||
81 | } |
||
82 | if (0 === (int)$helper->getConfig('autoapproved')) { |
||
83 | $crSearch->add(new \Criteria('repo_approved', 1)); |
||
84 | } |
||
85 | $crSearch->add(new \Criteria('repo_status', Constants::STATUS_UPTODATE)); |
||
86 | $crSearch->setStart($offset); |
||
87 | $crSearch->setLimit($limit); |
||
88 | $crSearch->setSort('repo_datecreated'); |
||
89 | $crSearch->setOrder('DESC'); |
||
90 | $repositoriesAll = $repositoriesHandler->getAll($crSearch); |
||
91 | foreach (\array_keys($repositoriesAll) as $i) { |
||
92 | $ret[] = [ |
||
93 | 'image' => 'assets/icons/16/github.png', |
||
94 | 'link' => 'index.php?op=show&dir_id=' . $directories[$repositoriesAll[$i]->getVar('repo_user')] . '&repo_id=' . $i, |
||
95 | 'title' => $repositoriesAll[$i]->getVar('repo_name') . ' (' . $repositoriesAll[$i]->getVar('repo_user') . ')', |
||
96 | 'time' => $repositoriesAll[$i]->getVar('repo_datecreated') |
||
97 | ]; |
||
98 | } |
||
99 | unset($crKeywords, $crUser, $crSearch, $repositoriesAll); |
||
100 | |||
101 | return $ret; |
||
102 | |||
103 | } |
||
104 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.