1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Database\Connection;
13: use Xoops\Core\Kernel\XoopsObject;
14: use Xoops\Core\Kernel\XoopsPersistableObjectHandler;
15:
16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: class PagePage_related_link extends XoopsObject
28: {
29: 30: 31:
32: public function __construct()
33: {
34: $this->initVar('link_id', XOBJ_DTYPE_INT, null, false, 8);
35: $this->initVar('link_related_id', XOBJ_DTYPE_TXTBOX, null, false);
36: $this->initVar('link_content_id', XOBJ_DTYPE_INT, null, false, 1);
37: $this->initVar('link_weight', XOBJ_DTYPE_INT, null, false, 1);
38:
39:
40: $this->initVar('content_id', XOBJ_DTYPE_INT, 0, false, 11);
41: $this->initVar('content_title', XOBJ_DTYPE_TXTBOX, '', false);
42: }
43:
44: public function getValues($keys = null, $format = null, $maxDepth = null)
45: {
46: $ret = parent::getValues($keys, $format, $maxDepth);
47: return $ret;
48: }
49:
50: public function get_new_id()
51: {
52: $xoops = Xoops::getInstance();
53: $new_id = $xoopsDB->getInsertId();
54: return $new_id;
55: }
56: }
57:
58: class PagePage_related_linkHandler extends XoopsPersistableObjectHandler
59: {
60: 61: 62:
63: public function __construct(Connection $db = null)
64: {
65: parent::__construct($db, 'page_related_link', 'pagepage_related_link', 'link_id', 'link_related_id');
66: }
67:
68: public function getLinks($related_id, $sort = 'link_weight', $order = 'desc')
69: {
70: $this->table_link = $this->db->prefix('page_content');
71: $this->field_link = 'content_id';
72: $this->field_object = 'link_content_id';
73:
74:
75: $criteria = new CriteriaCompo();
76: $criteria->add(new Criteria('link_related_id', $related_id));
77: $criteria->setSort($sort);
78: $criteria->setOrder($order);
79: return parent::getByLink($criteria, null, false);
80: }
81:
82: public function getContentByRelated($related_id, $sort = 'link_weight', $order = 'asc')
83: {
84: $criteria = new CriteriaCompo();
85: $criteria->add(new Criteria('link_related_id', $related_id));
86: $criteria->setSort($sort);
87: $criteria->setOrder($order);
88:
89: $ret = array();
90: $result = parent::getAll($criteria, array('link_content_id'), false);
91: foreach ($result as $k) {
92: $ret[] = $k['link_content_id'];
93: }
94: return $ret;
95: }
96:
97: public function getContentUsed()
98: {
99: $result = parent::getAll(null, array('link_content_id'), false);
100: foreach ($result as $k) {
101: $ret[] = $k['link_content_id'];
102: }
103: return $ret;
104: }
105:
106: public function DeleteByIds($links_ids)
107: {
108: $criteria = new CriteriaCompo();
109: $criteria->add(new Criteria('link_id', '(' . implode(', ', $links_ids) . ')', 'IN'));
110: return parent::deleteAll($criteria);
111: }
112:
113: public function menu_related($content_id)
114: {
115: $criteria = new CriteriaCompo();
116: $criteria->add(new Criteria('link_content_id', $content_id));
117: $related = parent::getAll($criteria, null, true, false);
118: if (count($related) > 0) {
119: $related_Handler = Page::getInstance()->getRelatedHandler();
120: $related_arr = $related_Handler->get($related[0]->getVar('link_related_id'));
121: $ret = $related_arr->getValues();
122:
123:
124: $keys = array_keys($ret['related_links']);
125: foreach ($keys as $k => $i) {
126: if ($content_id == $ret['related_links'][$i]['content_id']) {
127: if (($k-1) >= 0) {
128: $ret['prev_id'] = $ret['related_links'][$keys[($k-1)]]['content_id'];
129: $ret['prev_title'] = $ret['related_links'][$keys[($k-1)]]['content_title'];
130: }
131: if (($k+1) < count($keys)) {
132: $ret['next_id'] = $ret['related_links'][$keys[($k+1)]]['content_id'];
133: $ret['next_title'] = $ret['related_links'][$keys[($k+1)]]['content_title'];
134: }
135: break;
136: }
137: }
138: return $ret;
139: }
140: return array();
141: }
142: }
143: