Passed
Branch master (4e30dc)
by Michael
02:20
created

Faq::checkPermission()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 0
1
<?php namespace XoopsModules\Smartfaq;
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
use XoopsModules\Smartfaq;
10
use XoopsModules\Smartfaq\Constants;
11
12
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
13
14
//require_once XOOPS_ROOT_PATH . '/modules/smartfaq/class/category.php';
15
16
17
18
/**
19
 * Class Faq
20
 */
21
class Faq extends \XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject 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...
22
{
23
24
    /**
25
     * @var Smartfaq\Category
26
     * @access private
27
     */
28
    private $category = null;
29
30
    /**
31
     * @var Answer
32
     * @access private
33
     */
34
    private $answer = null;
35
36
    /**
37
     * @var array
38
     * @access private
39
     */
40
    private $_notifications = null;
0 ignored issues
show
introduced by
The private property $_notifications is not used, and could be removed.
Loading history...
41
    // TODO : Create a seperated class for notifications
42
43
    /**
44
     * @var array
45
     * @access private
46
     */
47
    private $groups_read = null;
48
49
    /**
50
     * @var object
51
     * @access private
52
     */
53
    // Is this still usefull??
54
    private $_smartModule = null;
0 ignored issues
show
introduced by
The private property $_smartModule is not used, and could be removed.
Loading history...
55
    private $_smartModuleConfig;
0 ignored issues
show
introduced by
The private property $_smartModuleConfig is not used, and could be removed.
Loading history...
56
57
    /**
58
     * constructor
59
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
60
     */
61
    public function __construct($id = null)
62
    {
63
        $this->db = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug Best Practice introduced by
The property db does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The type XoopsDatabaseFactory 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...
64
        $this->initVar('faqid', XOBJ_DTYPE_INT, -1, false);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Smartfaq\XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
        $this->initVar('categoryid', XOBJ_DTYPE_INT, 0, false);
66
        $this->initVar('question', XOBJ_DTYPE_TXTBOX, null, true, 100000);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Smartfaq\XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
67
        $this->initVar('howdoi', XOBJ_DTYPE_TXTBOX, null, false, 255);
68
        $this->initVar('diduno', XOBJ_DTYPE_TXTBOX, null, false, 255);
69
        $this->initVar('uid', XOBJ_DTYPE_INT, 0, false);
70
        $this->initVar('datesub', XOBJ_DTYPE_INT, null, false);
71
        $this->initVar('status', XOBJ_DTYPE_INT, -1, false);
72
        $this->initVar('counter', XOBJ_DTYPE_INT, 0, false);
73
        $this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
74
        $this->initVar('html', XOBJ_DTYPE_INT, 1, false);
75
        $this->initVar('smiley', XOBJ_DTYPE_INT, 1, false);
76
        $this->initVar('image', XOBJ_DTYPE_INT, 1, false);
77
        $this->initVar('linebreak', XOBJ_DTYPE_INT, 1, false);
78
        $this->initVar('xcodes', XOBJ_DTYPE_INT, 1, false);
79
        $this->initVar('cancomment', XOBJ_DTYPE_INT, 1, false);
80
        $this->initVar('comments', XOBJ_DTYPE_INT, 0, false);
81
        $this->initVar('notifypub', XOBJ_DTYPE_INT, 1, false);
82
        $this->initVar('modulelink', XOBJ_DTYPE_TXTBOX, 'None', false, 50);
83
        $this->initVar('contextpage', XOBJ_DTYPE_TXTBOX, null, false, 255);
84
        $this->initVar('exacturl', XOBJ_DTYPE_INT, 0, false);
85
        $this->initVar('partialview', XOBJ_DTYPE_INT, 0, false);
86
87
        if (null !== $id) {
88
            $faqHandler = new Smartfaq\FaqHandler($this->db);
89
            $faq        = $faqHandler->get($id);
90
            foreach ($faq->vars as $k => $v) {
91
                $this->assignVar($k, $v['value']);
92
            }
93
            $this->assignOtherProperties();
94
        }
95
    }
96
97
    public function assignOtherProperties()
98
    {
99
        $smartModule = Smartfaq\Utility::getModuleInfo();
100
        $module_id   = $smartModule->getVar('mid');
101
102
        $gpermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
        $gpermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
103
104
        $this->category    = new Smartfaq\Category($this->getVar('categoryid'));
105
        $this->groups_read = $gpermHandler->getGroupIds('item_read', $this->faqid(), $module_id);
106
    }
107
108
    /**
109
     * @return bool
110
     */
111
    public function checkPermission()
112
    {
113
//        require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php';
114
115
        $userIsAdmin = Smartfaq\Utility::userIsAdmin();
116
        if ($userIsAdmin) {
117
            return true;
118
        }
119
        /** @var \XoopsModules\Smartfaq\PermissionHandler $smartPermHandler */
120
        $smartPermHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Permission');
121
//        $smartPermHandler = xoops_getModuleHandler('permission', 'smartfaq');
122
123
        $faqsGranted = $smartPermHandler->getPermissions('item');
124
        if (in_array($this->categoryid(), $faqsGranted)) {
125
            $ret = true;
126
        }
127
128
        return $ret;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.
Loading history...
129
    }
130
131
    /**
132
     * @return array
133
     */
134
    public function getGroups_read()
135
    {
136
        if (count($this->groups_read) < 1) {
137
            $this->assignOtherProperties();
138
        }
139
140
        return $this->groups_read;
141
    }
142
143
    /**
144
     * @param array $groups_read
145
     */
146
    public function setGroups_read($groups_read = ['0'])
147
    {
148
        $this->groups_read = $groups_read;
149
    }
150
151
    /**
152
     * @return mixed
153
     */
154
    public function faqid()
155
    {
156
        return $this->getVar('faqid');
157
    }
158
159
    /**
160
     * @return mixed
161
     */
162
    public function categoryid()
163
    {
164
        return $this->getVar('categoryid');
165
    }
166
167
    /**
168
     * @return Smartfaq\Category
169
     */
170
    public function category()
171
    {
172
        return $this->category;
173
    }
174
175
    /**
176
     * @param  int    $maxLength
177
     * @param  string $format
178
     * @return mixed|string
179
     */
180
    public function question($maxLength = 0, $format = 'S')
181
    {
182
        $ret = $this->getVar('question', $format);
183
        if (('s' === $format) || ('S' === $format) || ('show' === $format)) {
184
            $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer 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...
185
            $ret  = $myts->displayTarea($ret);
186
        }
187
        if (0 != $maxLength) {
188
            if (!XOOPS_USE_MULTIBYTES) {
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Smartfaq\XOOPS_USE_MULTIBYTES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
189
                if (strlen($ret) >= $maxLength) {
190
                    $ret = substr($ret, 0, $maxLength - 1) . '...';
191
                }
192
            }
193
        }
194
195
        return $ret;
196
    }
197
198
    /**
199
     * @param  string $format
200
     * @return mixed
201
     */
202
    public function howdoi($format = 'S')
203
    {
204
        $ret = $this->getVar('howdoi', $format);
205
        if (('s' === $format) || ('S' === $format) || ('show' === $format)) {
206
            $myts = \MyTextSanitizer::getInstance();
207
            $ret  = $myts->displayTarea($ret);
208
        }
209
210
        return $ret;
211
    }
212
213
    /**
214
     * @param  string $format
215
     * @return mixed
216
     */
217
    public function diduno($format = 'S')
218
    {
219
        $ret = $this->getVar('diduno', $format);
220
        if (('s' === $format) || ('S' === $format) || ('show' === $format)) {
221
            $myts = \MyTextSanitizer::getInstance();
222
            $ret  = $myts->displayTarea($ret);
223
        }
224
225
        return $ret;
226
    }
227
228
    /**
229
     * @return mixed
230
     */
231
    public function uid()
232
    {
233
        return $this->getVar('uid');
234
    }
235
236
    /**
237
     * @param  string $dateFormat
238
     * @param  string $format
239
     * @return string
240
     */
241
    public function datesub($dateFormat = 'none', $format = 'S')
242
    {
243
        if ('none' === $dateFormat) {
244
            $smartConfig = Smartfaq\Utility::getModuleConfig();
245
            $dateFormat  = $smartConfig['dateformat'];
246
        }
247
248
        return formatTimestamp($this->getVar('datesub', $format), $dateFormat);
0 ignored issues
show
Bug introduced by
The function formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

248
        return /** @scrutinizer ignore-call */ formatTimestamp($this->getVar('datesub', $format), $dateFormat);
Loading history...
249
    }
250
251
    /**
252
     * @return mixed
253
     */
254
    public function status()
255
    {
256
        return $this->getVar('status');
257
    }
258
259
    /**
260
     * @return mixed
261
     */
262
    public function counter()
263
    {
264
        return $this->getVar('counter');
265
    }
266
267
    /**
268
     * @return mixed
269
     */
270
    public function weight()
271
    {
272
        return $this->getVar('weight');
273
    }
274
275
    /**
276
     * @return mixed
277
     */
278
    public function html()
279
    {
280
        return $this->getVar('html');
281
    }
282
283
    /**
284
     * @return mixed
285
     */
286
    public function smiley()
287
    {
288
        return $this->getVar('smiley');
289
    }
290
291
    /**
292
     * @return mixed
293
     */
294
    public function xcodes()
295
    {
296
        return $this->getVar('xcodes');
297
    }
298
299
    /**
300
     * @return mixed
301
     */
302
    public function cancomment()
303
    {
304
        return $this->getVar('cancomment');
305
    }
306
307
    /**
308
     * @return mixed
309
     */
310
    public function comments()
311
    {
312
        return $this->getVar('comments');
313
    }
314
315
    /**
316
     * @return mixed
317
     */
318
    public function notifypub()
319
    {
320
        return $this->getVar('notifypub');
321
    }
322
323
    /**
324
     * @param  string $format
325
     * @return mixed
326
     */
327
    public function modulelink($format = 'S')
328
    {
329
        return $this->getVar('modulelink', $format);
330
    }
331
332
    /**
333
     * @param  string $format
334
     * @return mixed
335
     */
336
    public function contextpage($format = 'S')
337
    {
338
        return $this->getVar('contextpage', $format);
339
    }
340
341
    /**
342
     * @return mixed
343
     */
344
    public function exacturl()
345
    {
346
        return $this->getVar('exacturl');
347
    }
348
349
    /**
350
     * @return mixed
351
     */
352
    public function partialview()
353
    {
354
        return $this->getVar('partialview');
355
    }
356
357
    /**
358
     * @param  int $realName
359
     * @return string
360
     */
361
    public function posterName($realName = -1)
362
    {
363
        if (-1 == $realName) {
364
            $smartConfig = Smartfaq\Utility::getModuleConfig();
365
            $realName    = $smartConfig['userealname'];
366
        }
367
368
        return Smartfaq\Utility::getLinkedUnameFromId($this->uid(), $realName);
369
    }
370
371
    /**
372
     * @return mixed|object|Smartfaq\Answer
373
     */
374
    public function answer()
375
    {
376
        $answerHandler = new Smartfaq\AnswerHandler($this->db);
377
        switch ($this->status()) {
378
            case Constants::SF_STATUS_SUBMITTED:
379
                $theAnswers = $answerHandler->getAllAnswers($this->faqid(), Constants::SF_AN_STATUS_APPROVED, 1, 0);
380
                //echo "test";
381
                //exit;
382
                $this->answer =& $theAnswers[0];
383
                break;
384
385
            case Constants::SF_STATUS_ANSWERED:
386
                $theAnswers = $answerHandler->getAllAnswers($this->faqid(), Constants::SF_AN_STATUS_PROPOSED, 1, 0);
387
                //echo "test";
388
                //exit;
389
                $this->answer =& $theAnswers[0];
390
                break;
391
392
            case Constants::SF_STATUS_PUBLISHED:
393
            case Constants::SF_STATUS_NEW_ANSWER:
394
            case Constants::SF_STATUS_OFFLINE:
395
                $this->answer = $answerHandler->getOfficialAnswer($this->faqid());
396
                break;
397
398
            case Constants::SF_STATUS_ASKED:
399
                $this->answer = $answerHandler->create();
400
                break;
401
            case Constants::SF_STATUS_OPENED:
402
                $this->answer = $answerHandler->create();
403
                break;
404
        }
405
406
        if ($this->answer) {
407
            $this->answer->setVar('dohtml', $this->getVar('html'));
408
            $this->answer->setVar('doxcode', $this->getVar('xcodes'));
409
            $this->answer->setVar('dosmiley', $this->getVar('smiley'));
410
            $this->answer->setVar('doimage', $this->getVar('image'));
411
            $this->answer->setVar('dobr', $this->getVar('linebreak'));
412
        }
413
414
        return $this->answer;
415
    }
416
417
    /**
418
     * @return array
419
     */
420
    public function getAllAnswers()
421
    {
422
        $answerHandler = new Smartfaq\AnswerHandler($this->db);
423
424
        return $answerHandler->getAllAnswers($this->faqid());
425
    }
426
427
    /**
428
     * @return bool
429
     */
430
    public function updateCounter()
431
    {
432
        $faqHandler = new Smartfaq\FaqHandler($this->db);
433
434
        return $faqHandler->updateCounter($this->faqid());
435
    }
436
437
    /**
438
     * @param  bool $force
439
     * @return bool
440
     */
441
    public function store($force = true)
442
    {
443
        $faqHandler = new Smartfaq\FaqHandler($this->db);
444
445
        return $faqHandler->insert($this, $force);
446
    }
447
448
    /**
449
     * @return mixed
450
     */
451
    public function getCategoryName()
452
    {
453
        if (!isset($this->category)) {
454
            $this->category = new Smartfaq\Category($this->getVar('categoryid'));
455
        }
456
457
        return $this->category->name();
458
    }
459
460
    /**
461
     * @param array $notifications
462
     */
463
    public function sendNotifications($notifications = [])
464
    {
465
        $smartModule = Smartfaq\Utility::getModuleInfo();
466
467
        $myts                = \MyTextSanitizer::getInstance();
468
        $notificationHandler = xoops_getHandler('notification');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

468
        $notificationHandler = /** @scrutinizer ignore-call */ xoops_getHandler('notification');
Loading history...
469
        //$categoryObj = $this->category();
470
471
        $tags                  = [];
472
        $tags['MODULE_NAME']   = $myts->displayTarea($smartModule->getVar('name'));
473
        $tags['FAQ_NAME']      = $this->question();
474
        $tags['CATEGORY_NAME'] = $this->getCategoryName();
475
        $tags['CATEGORY_URL']  = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/category.php?categoryid=' . $this->categoryid();
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Smartfaq\XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
476
        $tags['FAQ_QUESTION']  = $this->question();
477
        $answerObj             = $this->answer();
478
        if (is_object($answerObj)) {
479
            // TODO : Not sure about the 'formpreview' ...
480
            $tags['FAQ_ANSWER'] = $answerObj->answer('formpreview');
481
        }
482
        $tags['DATESUB'] = $this->datesub();
483
484
        foreach ($notifications as $notification) {
485
            switch ($notification) {
486
                case Constants::SF_NOT_FAQ_PUBLISHED:
487
                    $tags['FAQ_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/faq.php?faqid=' . $this->faqid();
488
489
                    $notificationHandler->triggerEvent('global_faq', 0, 'published', $tags);
490
                    $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'published', $tags);
491
                    $notificationHandler->triggerEvent('faq', $this->faqid(), 'approved', $tags);
492
                    break;
493
494
                case Constants::SF_NOT_FAQ_SUBMITTED:
495
                    $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/faq.php?faqid=' . $this->faqid();
496
                    $notificationHandler->triggerEvent('global_faq', 0, 'submitted', $tags);
497
                    $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'submitted', $tags);
498
                    break;
499
500
                case Constants::SF_NOT_QUESTION_PUBLISHED:
501
                    $tags['FAQ_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/answer.php?faqid=' . $this->faqid();
502
                    $notificationHandler->triggerEvent('global_question', 0, 'published', $tags);
503
                    $notificationHandler->triggerEvent('category_question', $this->categoryid(), 'published', $tags);
504
                    $notificationHandler->triggerEvent('question', $this->faqid(), 'approved', $tags);
505
                    break;
506
507
                case Constants::SF_NOT_QUESTION_SUBMITTED:
508
                    $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/question.php?op=mod&faqid=' . $this->faqid();
509
                    $notificationHandler->triggerEvent('global_question', 0, 'submitted', $tags);
510
                    $notificationHandler->triggerEvent('category_question', $this->categoryid(), 'submitted', $tags);
511
                    break;
512
513
                case Constants::SF_NOT_FAQ_REJECTED:
514
                    $notificationHandler->triggerEvent('faq', $this->faqid(), 'rejected', $tags);
515
                    break;
516
517
                case Constants::SF_NOT_NEW_ANSWER_PROPOSED:
518
                    $tags['WAITINGFILES_URL'] = XOOPS_URL . '/modules/' . $smartModule->getVar('dirname') . '/admin/answer.php?op=mod&faqid=' . $this->faqid();
519
                    $notificationHandler->triggerEvent('global_faq', 0, 'answer_proposed', $tags);
520
                    $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'answer_proposed', $tags);
521
                    break;
522
523
                case Constants::SF_NOT_NEW_ANSWER_PUBLISHED:
524
                    $notificationHandler->triggerEvent('global_faq', 0, 'answer_published', $tags);
525
                    $notificationHandler->triggerEvent('category_faq', $this->categoryid(), 'answer_published', $tags);
526
                    break;
527
528
                // TODO : I commented out this one because I'm not sure. The $this->faqid() should probably be the
529
                // answerid not the faqid....
530
                /*
531
                case Constants::SF_NOT_ANSWER_APPROVED:
532
                $notificationHandler->triggerEvent('faq', $this->faqid(), 'answer_approved', $tags);
533
                break;
534
                */
535
536
                // TODO : I commented out this one because I'm not sure. The $this->faqid() should probably be the
537
                // answerid not the faqid....
538
                /*
539
                case Constants::SF_NOT_ANSWER_REJECTED:
540
                $notificationHandler->triggerEvent('faq', $this->faqid(), 'answer_approved', $tags);
541
                break;
542
                */
543
544
                case -1:
545
                default:
546
                    break;
547
            }
548
        }
549
    }
550
551
    public function setDefaultPermissions()
552
    {
553
        $memberHandler = xoops_getHandler('member');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

553
        $memberHandler = /** @scrutinizer ignore-call */ xoops_getHandler('member');
Loading history...
554
        $groups        = $memberHandler->getGroupList();
555
556
        $j         = 0;
557
        $group_ids = [];
558
        foreach (array_keys($groups) as $i) {
559
            $group_ids[$j] = $i;
560
            ++$j;
561
        }
562
        $this->groups_read = $group_ids;
563
    }
564
565
    /**
566
     * @param $group_ids
567
     */
568
    public function setPermissions($group_ids)
569
    {
570
        if (!isset($group_ids)) {
571
            $memberHandler = xoops_getHandler('member');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

571
            $memberHandler = /** @scrutinizer ignore-call */ xoops_getHandler('member');
Loading history...
572
            $groups        = $memberHandler->getGroupList();
573
574
            $j         = 0;
575
            $group_ids = [];
576
            foreach (array_keys($groups) as $i) {
577
                $group_ids[$j] = $i;
578
                ++$j;
579
            }
580
        }
581
    }
582
583
    /**
584
     * @return bool
585
     */
586
    public function notLoaded()
587
    {
588
        return (-1 == $this->getVar('faqid'));
589
    }
590
591
    /**
592
     * @param  null  $answerObj
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $answerObj is correct as it would always require null to be passed?
Loading history...
593
     * @param  array $users
594
     * @return string
595
     */
596
    public function getWhoAndWhen($answerObj = null, $users = [])
597
    {
598
        $smartModuleConfig = Smartfaq\Utility::getModuleConfig();
599
600
        $requester   = Smartfaq\Utility::getLinkedUnameFromId($this->uid(), $smartModuleConfig['userealname'], $users);
601
        $requestdate = $this->datesub();
602
603
        if ((Constants::SF_STATUS_PUBLISHED == $this->status()) || Constants::SF_STATUS_NEW_ANSWER == $this->status()) {
604
            if (null === $answerObj) {
605
                $answerObj = $this->answer();
606
            }
607
            $submitdate = $answerObj->datesub();
608
            if ($this->uid() == $answerObj->uid()) {
609
                $result = sprintf(_MD_SF_REQUESTEDANDANSWERED, $requester, $submitdate);
610
            } else {
611
                $submitter = Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users);
612
                $result    = sprintf(_MD_SF_REQUESTEDBYANDANSWEREDBY, $requester, $submitter, $submitdate);
613
            }
614
        } else {
615
            $result = sprintf(_MD_SF_REQUESTEDBY, $requester, $requestdate);
616
        }
617
618
        return $result;
619
    }
620
621
    /**
622
     * @return string
623
     */
624
    public function getComeFrom()
625
    {
626
        global $xoopsConfig;
627
        $text = _MD_SF_QUESTIONCOMEFROM;
628
        if ((Constants::SF_STATUS_PUBLISHED == $this->status()) || Constants::SF_STATUS_NEW_ANSWER == $this->status()) {
629
            $text = _MD_SF_FAQCOMEFROM;
630
        }
631
632
        return $text . $xoopsConfig['sitename'] . ' : <a href=' . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=' . $this->faqid() . '>' . XOOPS_URL . '/modules/smartfaq/faq.php?faqid=' . $this->faqid() . '</a>';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Smartfaq\XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
633
    }
634
635
    /**
636
     * @param  array $faq
637
     * @param  null  $category
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $category is correct as it would always require null to be passed?
Loading history...
638
     * @param  bool  $linkInQuestion
639
     * @return array
640
     */
641
    public function toArray($faq = [], $category = null, $linkInQuestion = true)
642
    {
643
        global $xoopsModuleConfig;
644
        $lastfaqsize = (int)$xoopsModuleConfig['lastfaqsize'];
645
646
        $faq['id']         = $this->faqid();
647
        $faq['categoryid'] = $this->categoryid();
648
        $faq['question']   = $this->question();
649
        $page              = (Constants::SF_STATUS_OPENED == $this->status()) ? 'answer.php' : 'faq.php';
650
651
        $faq['questionlink'] = "<a href='$page?faqid=" . $this->faqid() . "'>" . $this->question($lastfaqsize) . '</a>';
652
        if ($linkInQuestion) {
653
            $faq['fullquestionlink'] = "<a href='$page?faqid=" . $this->faqid() . "'>" . $this->question() . '</a>';
654
        } else {
655
            $faq['fullquestionlink'] = $this->question();
656
        }
657
        $faq['faqid']      = $this->faqid();
658
        $faq['counter']    = $this->counter();
659
        $faq['cancomment'] = $this->cancomment();
660
        $faq['comments']   = $this->comments();
661
        $faq['datesub']    = $this->datesub();
662
        if (null !== $category) {
663
            if (is_object($category) && 'xoopsmodules\smartfaq\category' === strtolower(get_class($category))) {
664
                $categoryObj = $category;
665
            } elseif (is_array($category)) {
666
                $categoryObj = $category[$this->categoryid()];
667
            }
668
            $faq['categoryname'] = $categoryObj->getVar('name');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $categoryObj does not seem to be defined for all execution paths leading up to this point.
Loading history...
669
            $faq['categorylink'] = "<a href='" . XOOPS_URL . '/modules/smartfaq/category.php?categoryid=' . $this->categoryid() . "'>" . $categoryObj->getVar('name') . '</a>';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Smartfaq\XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
670
        }
671
672
        return $faq;
673
    }
674
}
675