Passed
Pull Request — master (#70)
by Pierre-Henry
03:15
created

class/Tree.php (1 issue)

Labels
Severity
1
<?php namespace XoopsModules\Newbb;
2
3
//
4
// ------------------------------------------------------------------------ //
5
// XOOPS - PHP Content Management System                      //
6
// Copyright (c) 2000-2016 XOOPS.org                           //
7
// <https://xoops.org/>                             //
8
// ------------------------------------------------------------------------ //
9
// This program is free software; you can redistribute it and/or modify     //
10
// it under the terms of the GNU General Public License as published by     //
11
// the Free Software Foundation; either version 2 of the License, or        //
12
// (at your option) any later version.                                      //
13
// //
14
// You may not change or alter any portion of this comment or credits       //
15
// of supporting developers from this source code or any supporting         //
16
// source code which is considered copyrighted (c) material of the          //
17
// original comment or credit authors.                                      //
18
// //
19
// This program is distributed in the hope that it will be useful,          //
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
// GNU General Public License for more details.                             //
23
// //
24
// You should have received a copy of the GNU General Public License        //
25
// along with this program; if not, write to the Free Software              //
26
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
// ------------------------------------------------------------------------ //
28
// Author: phppp (D.J., [email protected])                                  //
29
//  URL: https://xoops.org                                                    //
30
// Project: Article Project                                                 //
31
// ------------------------------------------------------------------------ //
32
33
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
34
require_once $GLOBALS['xoops']->path('class/xoopstree.php');
35
36
/**
37
 * Class Newbbtree
38
 */
39
class Tree extends \XoopsTree
0 ignored issues
show
The type XoopsTree was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
{
41
    /** @var string */
42
    private $prefix = '&nbsp;&nbsp;';
43
44
    /** @var string */
45
    private $increment = '&nbsp;&nbsp;';
46
47
    /** @var array */
48
    private $postArray = [];
49
50
    /**
51
     * @param string $table_name
52
     * @param string $id_name
53
     * @param string $pid_name
54
     */
55
    public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid')
56
    {
57
        parent::__construct($table_name, $id_name, $pid_name);
58
    }
59
60
    /**
61
     * @param string $val
62
     */
63
    public function setPrefix($val = '')
64
    {
65
        $this->prefix    = $val;
66
        $this->increment = $val;
67
    }
68
69
    /**
70
     * @param        $sel_id
71
     * @param string $order
72
     */
73
    public function getAllPostArray($sel_id, $order = '')
74
    {
75
        $this->postArray = $this->getAllChild($sel_id, $order);
76
    }
77
78
    /**
79
     * @param $postArray
80
     */
81
    public function setPostArray($postArray)
82
    {
83
        $this->postArray = $postArray;
84
    }
85
86
    // returns an array of first child objects for a given id($sel_id)
87
88
    /**
89
     * @param         $postTree_array
90
     * @param  int    $pid
91
     * @param  string $prefix
92
     * @return bool
93
     */
94
    public function getPostTree(&$postTree_array, $pid = 0, $prefix = '&nbsp;&nbsp;')
95
    {
96
        if (!is_array($postTree_array)) {
97
            $postTree_array = [];
98
        }
99
100
        $newPostArray = [];
101
        $prefix       .= $this->increment;
102
        foreach ($this->postArray as $post) {
103
            if ($post->getVar('pid') == $pid) {
104
                $postTree_array[] = [
105
                    'prefix'      => $prefix,
106
                    'icon'        => $post->getVar('icon'),
107
                    'post_time'   => $post->getVar('post_time'),
108
                    'post_id'     => $post->getVar('post_id'),
109
                    'forum_id'    => $post->getVar('forum_id'),
110
                    'subject'     => $post->getVar('subject'),
111
                    'poster_name' => $post->getVar('poster_name'),
112
                    'uid'         => $post->getVar('uid')
113
                ];
114
                $this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix);
115
            } else {
116
                $newPostArray[] = $post;
117
            }
118
        }
119
        $this->postArray = $newPostArray;
120
        unset($newPostArray);
121
122
        return true;
123
    }
124
}
125