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: use Xoops\Core\Kernel\Handlers\XoopsUser;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: class PagePage_content extends XoopsObject
28: {
29:
30: public $options = array(
31: 'title',
32: 'author',
33: 'date',
34: 'hits',
35: 'rating',
36: 'print',
37: 'mail',
38: 'coms',
39: 'ncoms',
40: 'notifications',
41: 'pdf',
42: 'social'
43: );
44:
45: 46: 47:
48: public function __construct()
49: {
50: $this->initVar('content_id', XOBJ_DTYPE_INT, 0, false, 11);
51: $this->initVar('content_title', XOBJ_DTYPE_TXTBOX, '', false);
52: $this->initVar('content_shorttext', XOBJ_DTYPE_TXTAREA, '', false);
53: $this->initVar('content_text', XOBJ_DTYPE_TXTAREA, '', false);
54: $this->initVar('content_create', XOBJ_DTYPE_INT, time(), false, 10);
55: $this->initVar('content_author', XOBJ_DTYPE_INT, 0, false, 11);
56: $this->initVar('content_status', XOBJ_DTYPE_INT, 1, false, 1);
57: $this->initVar('content_hits', XOBJ_DTYPE_INT, 0, false, 10);
58: $this->initVar('content_rating', XOBJ_DTYPE_OTHER, 0, false, 10);
59: $this->initVar('content_votes', XOBJ_DTYPE_INT, 0, false, 11);
60: $this->initVar('content_comments', XOBJ_DTYPE_INT, 0, false, 11);
61: $this->initVar('content_mkeyword', XOBJ_DTYPE_TXTAREA, '', false);
62: $this->initVar('content_mdescription', XOBJ_DTYPE_TXTAREA, '', false);
63: $this->initVar('content_maindisplay', XOBJ_DTYPE_INT, 1, false, 1);
64: $this->initVar('content_weight', XOBJ_DTYPE_INT, 0, false, 5);
65: $this->initVar('content_dopdf', XOBJ_DTYPE_INT, 1, false, 1);
66: $this->initVar('content_doprint', XOBJ_DTYPE_INT, 1, false, 1);
67: $this->initVar('content_dosocial', XOBJ_DTYPE_INT, 1, false, 1);
68: $this->initVar('content_doauthor', XOBJ_DTYPE_INT, 1, false, 1);
69: $this->initVar('content_dodate', XOBJ_DTYPE_INT, 1, false, 1);
70: $this->initVar('content_domail', XOBJ_DTYPE_INT, 1, false, 1);
71: $this->initVar('content_dohits', XOBJ_DTYPE_INT, 1, false, 1);
72: $this->initVar('content_dorating', XOBJ_DTYPE_INT, 1, false, 1);
73: $this->initVar('content_docoms', XOBJ_DTYPE_INT, 1, false, 1);
74: $this->initVar('content_doncoms', XOBJ_DTYPE_INT, 1, false, 1);
75: $this->initVar('content_dotitle', XOBJ_DTYPE_INT, 1, false, 1);
76: $this->initVar('content_donotifications', XOBJ_DTYPE_INT, 1, false, 1);
77: $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
78: }
79:
80: public function getValues($keys = null, $format = null, $maxDepth = null)
81: {
82: $page = Page::getInstance();
83: $ret = parent::getValues($keys, $format, $maxDepth);
84: $ret['rating'] = number_format($this->getVar('content_rating'), 1);
85:
86: $ret['content_authorid'] = $this->getVar('content_author');
87: $ret['content_author'] = XoopsUser::getUnameFromId($this->getVar('content_author'), true);
88: $ret['content_date'] = XoopsLocale::formatTimestamp($this->getVar('content_create'), $page->getConfig('page_dateformat'));
89: $ret['content_time'] = XoopsLocale::formatTimestamp($this->getVar('content_create'), $page->getConfig('page_timeformat'));
90: $ret['content_rating'] = number_format($this->getVar('content_rating'), 2);
91: return $ret;
92: }
93:
94: public function toArray()
95: {
96: $ret = parent::getValues();
97: unset($ret['dohtml']);
98: return $ret;
99: }
100:
101: public function getOptions()
102: {
103: $xoops = Xoops::getInstance();
104: $ret = array();
105: if ($this->getVar('content_dotitle') == 1) {
106: array_push($ret, 'title');
107: }
108: if ($this->getVar('content_doauthor') == 1) {
109: array_push($ret, 'author');
110: }
111: if ($this->getVar('content_dodate') == 1) {
112: array_push($ret, 'date');
113: }
114: if ($this->getVar('content_dohits') == 1) {
115: array_push($ret, 'hits');
116: }
117: if ($this->getVar('content_dorating') == 1) {
118: array_push($ret, 'rating');
119: }
120: if ($this->getVar('content_doprint') == 1) {
121: array_push($ret, 'print');
122: }
123: if ($this->getVar('content_domail') == 1) {
124: array_push($ret, 'mail');
125: }
126: if ($xoops->isActiveModule('comments')) {
127: if ($this->getVar('content_docoms') == 1) {
128: array_push($ret, 'coms');
129: }
130: if ($this->getVar('content_doncoms') == 1) {
131: array_push($ret, 'ncoms');
132: }
133: }
134: if ($xoops->isActiveModule('notifications')) {
135: if ($this->getVar('content_donotifications') == 1) {
136: array_push($ret, 'notifications');
137: }
138: }
139: if ($xoops->isActiveModule('pdf')) {
140: if ($this->getVar('content_dopdf') == 1) {
141: array_push($ret, 'pdf');
142: }
143: }
144: if ($xoops->isActiveModule('xoosocialnetwork')) {
145: if ($this->getVar('content_dosocial') == 1) {
146: array_push($ret, 'social');
147: }
148: }
149: return $ret;
150: }
151:
152: public function get_new_id()
153: {
154: return Xoops::getInstance()->db()->getInsertId();
155: }
156: }
157:
158: class PagePage_contentHandler extends XoopsPersistableObjectHandler
159: {
160: 161: 162:
163: public function __construct(Connection $db = null)
164: {
165: parent::__construct($db, 'page_content', 'pagepage_content', 'content_id', 'content_title');
166: }
167:
168: public function getPagePublished($start = 0, $limit = 0, $sort = 'content_weight ASC, content_title', $order = 'ASC')
169: {
170: $helper = Page::getInstance();
171: $xoops = $helper->xoops();
172: $module_id = $helper->getModule()->getVar('mid');
173:
174:
175:
176: $groups = $xoops->getUserGroups();
177: $pages_ids = $helper->getGrouppermHandler()->getItemIds('page_view_item', $groups, $module_id);
178:
179:
180: $criteria = new CriteriaCompo();
181: $criteria->add(new Criteria('content_id', '(' . implode(', ', $pages_ids) . ')', 'IN'));
182: $criteria->add(new Criteria('content_status', 0, '!='));
183: $criteria->add(new Criteria('content_maindisplay', 0, '!='));
184: $criteria->setSort($sort);
185: $criteria->setOrder($order);
186: $criteria->setStart($start);
187: $criteria->setLimit($limit);
188: return parent::getAll($criteria);
189: }
190:
191: public function getCountPublished($start = 0, $limit = 0, $sort = 'content_weight ASC, content_title', $order = 'ASC')
192: {
193: $helper = Page::getInstance();
194: $xoops = $helper->xoops();
195: $module_id = $helper->getModule()->getVar('mid');
196:
197:
198: $groups = $xoops->getUserGroups();
199: $pages_ids = $helper->getGrouppermHandler()->getItemIds('page_view_item', $groups, $module_id);
200:
201:
202: $criteria = new CriteriaCompo();
203: $criteria->add(new Criteria('content_id', '(' . implode(', ', $pages_ids) . ')', 'IN'));
204: $criteria->add(new Criteria('content_status', 0, '!='));
205: $criteria->add(new Criteria('content_maindisplay', 0, '!='));
206: $criteria->setSort($sort);
207: $criteria->setOrder($order);
208: $criteria->setStart($start);
209: $criteria->setLimit($limit);
210: return parent::getCount($criteria);
211: }
212:
213: public function getPage($start = 0, $limit = 0, $sort = 'content_weight ASC, content_title', $order = 'ASC')
214: {
215: $criteria = new CriteriaCompo();
216: $criteria->setSort($sort);
217: $criteria->setOrder($order);
218: $criteria->setStart($start);
219: $criteria->setLimit($limit);
220: return parent::getAll($criteria);
221: }
222:
223: public function countPage($start = 0, $limit = 0, $sort = 'content_weight ASC, content_title', $order = 'ASC')
224: {
225: $criteria = new CriteriaCompo();
226: $criteria->setSort($sort);
227: $criteria->setOrder($order);
228: $criteria->setStart($start);
229: $criteria->setLimit($limit);
230: return parent::getCount($criteria);
231: }
232:
233: public function getPageTitle($status = null, $sort = 'content_weight ASC, content_title', $order = 'ASC')
234: {
235: $criteria = new CriteriaCompo();
236: if (isset($status)) {
237: $criteria->add(new Criteria('content_status', $status));
238: }
239: $criteria->setSort($sort);
240: $criteria->setOrder($order);
241: return parent::getAll($criteria, array('content_id', 'content_title'), false);
242: }
243:
244: public function getClone($content_id)
245: {
246: $values = parent::get($content_id)->toArray();
247: $values['content_id'] = 0;
248: $values['content_title'] = PageLocale::CONTENT_COPY . $values['content_title'];
249: $values['content_weight'] = 0;
250: $values['content_hits'] = 0;
251: $values['content_votes'] = 0;
252: $values['content_rating'] = 0;
253: $values['content_create'] = time();
254:
255: $obj = parent::create();
256: $obj->setVars($values);
257: return $obj;
258: }
259: }
260: