1
|
|
|
<?php namespace Xoopsmodules\instruction; |
2
|
|
|
|
3
|
|
|
//use Xoopsmodules\instruction; |
4
|
|
|
|
5
|
|
|
//if (!defined("XOOPS_ROOT_PATH")) { |
6
|
|
|
// die("XOOPS root path not defined"); |
7
|
|
|
//} |
8
|
|
|
|
9
|
|
|
//include_once $GLOBALS['xoops']->path('include/common.php'); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class InstructionHandler |
13
|
|
|
* @package Xoopsmodules\instruction |
14
|
|
|
*/ |
15
|
|
|
class InstructionHandler extends \XoopsPersistableObjectHandler |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param null|mixed $db |
19
|
|
|
*/ |
20
|
|
|
public function __construct(\XoopsDatabase $db = null) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($db, 'instruction_instr', Instruction::class, 'instrid', 'title'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// Обновление даты обновления инструкций |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param int $instrid |
29
|
|
|
* @param bool|int $time |
30
|
|
|
* @return mixed |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
public function updateDateupdated($instrid = 0, $time = null) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
// Если не передали время |
35
|
|
|
$time = null === $time ? time() : (int)$time; |
36
|
|
|
// |
37
|
|
|
$sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `instrid` = %u', $this->table, $time, (int)$instrid); |
38
|
|
|
// |
39
|
|
|
return $this->db->query($sql); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// Обновление числа страниц |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param int $instrid |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function updatePages($instrid = 0) |
49
|
|
|
{ |
50
|
|
|
// $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
51
|
|
|
$pageHandler = new PageHandler; |
52
|
|
|
// Находим число активных страниц |
53
|
|
|
$criteria = new \CriteriaCompo(); |
54
|
|
|
$criteria->add(new \Criteria('instrid', $instrid, '=')); |
55
|
|
|
$criteria->add(new \Criteria('status ', '0', '>')); |
56
|
|
|
// Число страниц |
57
|
|
|
$pages = $pageHandler->getCount($criteria); |
58
|
|
|
unset($criteria); |
59
|
|
|
|
60
|
|
|
// Сохраняем это число |
61
|
|
|
$sql = sprintf('UPDATE `%s` SET `pages` = %u, `dateupdated` = %u WHERE `instrid` = %u', $this->table, $pages, time(), $instrid); |
62
|
|
|
// |
63
|
|
|
return $this->db->query($sql); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.