1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Database\Connection;
13: use Xoops\Core\FixedGroups;
14: use Xoops\Core\Kernel\XoopsObject;
15: use Xoops\Core\Kernel\XoopsPersistableObjectHandler;
16:
17: 18: 19: 20: 21: 22: 23: 24:
25:
26: class MenusMenu extends XoopsObject
27: {
28: 29: 30:
31: public function __construct()
32: {
33: $this->initVar('id', XOBJ_DTYPE_INT);
34: $this->initVar('pid', XOBJ_DTYPE_INT);
35: $this->initVar('mid', XOBJ_DTYPE_INT);
36: $this->initVar('title', XOBJ_DTYPE_TXTBOX, '');
37: $this->initVar('alt_title', XOBJ_DTYPE_TXTBOX, '');
38: $this->initVar('visible', XOBJ_DTYPE_INT, 1);
39: $this->initVar('link', XOBJ_DTYPE_TXTBOX);
40: $this->initVar('weight', XOBJ_DTYPE_INT, 255);
41: $this->initVar('target', XOBJ_DTYPE_TXTBOX, '_self');
42: $this->initVar('groups', XOBJ_DTYPE_ARRAY, serialize(array(FixedGroups::ANONYMOUS, FixedGroups::USERS)));
43: $this->initVar('hooks', XOBJ_DTYPE_ARRAY, serialize(array()));
44: $this->initVar('image', XOBJ_DTYPE_TXTBOX);
45: $this->initVar('css', XOBJ_DTYPE_TXTBOX);
46: }
47: }
48:
49: class MenusMenuHandler extends XoopsPersistableObjectHandler
50: {
51: 52: 53:
54: public function __construct(Connection $db = null)
55: {
56: parent::__construct($db, 'menus_menu', 'MenusMenu', 'id', 'title');
57: }
58:
59: 60: 61:
62: public function update_weights(MenusMenu $obj)
63: {
64: $sql = "UPDATE " . $this->table
65: . " SET weight = weight+1"
66: . " WHERE weight >= " . $obj->getVar('weight')
67: . " AND id <> " . $obj->getVar('id')
68:
69: . " AND mid = " . $obj->getVar('mid')
70: ;
71: $this->db->queryF($sql);
72:
73: $sql = "SELECT id FROM " . $this->table
74: . " WHERE mid = " . $obj->getVar('mid')
75:
76: . " ORDER BY weight ASC"
77: ;
78: $result = $this->db->query($sql);
79: $i = 1;
80: while (list($id) = $this->db->fetchRow($result)) {
81: $sql = "UPDATE " . $this->table
82: . " SET weight = {$i}"
83: . " WHERE id = {$id}"
84: ;
85: $this->db->queryF($sql);
86: ++$i;
87: }
88: }
89: }
90: