/administrator/components/com_phocaguestbook/models/phocaguestbookb.php

https://github.com/navinpai/GEC-Tandav · PHP · 284 lines · 219 code · 30 blank · 35 comment · 29 complexity · 0ca2ebd7eb23bc3d704676c4e0c361d3 MD5 · raw file

  1. <?php
  2. /*
  3. * @package Joomla 1.5
  4. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  5. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  6. *
  7. * @component Phoca Guestbook
  8. * @copyright Copyright (C) Jan Pavelka www.phoca.cz
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  10. */
  11. // Check to ensure this file is included in Joomla!
  12. defined('_JEXEC') or die();
  13. jimport('joomla.application.component.model');
  14. class PhocaGuestbookCpModelPhocaGuestbookb extends JModel
  15. {
  16. function __construct()
  17. {
  18. parent::__construct();
  19. $array = JRequest::getVar('cid', 0, '', 'array');
  20. $this->setId((int)$array[0]);
  21. }
  22. function setId($id)
  23. {
  24. // Set id and wipe data
  25. $this->_id = $id;
  26. $this->_data = null;
  27. }
  28. function &getData()
  29. {
  30. if ($this->_loadData())
  31. {
  32. $user = &JFactory::getUser();
  33. /* // Check to see if the category is published
  34. if (!$this->_data->cat_pub) {
  35. JError::raiseError( 404, JText::_("Resource Not Found") );
  36. return;
  37. }
  38. // Check whether category access level allows access
  39. if ($this->_data->cat_access > $user->get('aid', 0)) {
  40. JError::raiseError( 403, JText::_('ALERTNOTAUTH') );
  41. return;
  42. }*/
  43. }
  44. else
  45. {
  46. $this->_initData();
  47. }
  48. return $this->_data;
  49. }
  50. function isCheckedOut( $uid=0 )
  51. {
  52. if ($this->_loadData())
  53. {
  54. if ($uid) {
  55. return ($this->_data->checked_out && $this->_data->checked_out != $uid);
  56. } else {
  57. return $this->_data->checked_out;
  58. }
  59. }
  60. }
  61. function checkin()
  62. {
  63. if ($this->_id)
  64. {
  65. $phocaguestbook = & $this->getTable();
  66. if(! $phocaguestbook->checkin($this->_id)) {
  67. $this->setError($this->_db->getErrorMsg());
  68. return false;
  69. }
  70. }
  71. return false;
  72. }
  73. function checkout($uid = null)
  74. {
  75. if ($this->_id)
  76. {
  77. // Make sure we have a user id to checkout the article with
  78. if (is_null($uid)) {
  79. $user =& JFactory::getUser();
  80. $uid = $user->get('id');
  81. }
  82. // Lets get to it and checkout the thing...
  83. $phocaguestbook = & $this->getTable();
  84. if(!$phocaguestbook->checkout($uid, $this->_id)) {
  85. $this->setError($this->_db->getErrorMsg());
  86. return false;
  87. }
  88. return true;
  89. }
  90. return false;
  91. }
  92. function store($data)
  93. {
  94. $row =& $this->getTable();
  95. // Bind the form fields to the table
  96. if (!$row->bind($data)) {
  97. $this->setError($this->_db->getErrorMsg());
  98. return false;
  99. }
  100. // if new item, order last in appropriate group
  101. if (!$row->id) {
  102. //$where = 'catid = ' . (int) $row->catid ;
  103. $where = '';
  104. $row->ordering = $row->getNextOrder( $where );
  105. }
  106. // Make sure the table is valid
  107. if (!$row->check()) {
  108. $this->setError($this->_db->getErrorMsg());
  109. return false;
  110. }
  111. // Store the table to the database
  112. if (!$row->store()) {
  113. $this->setError($this->_db->getErrorMsg());
  114. return false;
  115. }
  116. return $row->id;
  117. }
  118. function accessmenu($id, $access)
  119. {
  120. global $mainframe;
  121. $row =& $this->getTable();
  122. $row->id = $id;
  123. $row->access = $access;
  124. if ( !$row->check() ) {
  125. $this->setError($this->_db->getErrorMsg());
  126. return false;
  127. }
  128. if ( !$row->store() ) {
  129. $this->setError($this->_db->getErrorMsg());
  130. return false;
  131. }
  132. }
  133. function delete($cid = array())
  134. {
  135. $result = false;
  136. if (count( $cid ))
  137. {
  138. JArrayHelper::toInteger($cid);
  139. $cids = implode( ',', $cid );
  140. //Delete it from DB
  141. $query = 'DELETE FROM #__phocaguestbook_books'
  142. . ' WHERE id IN ( '.$cids.' )';
  143. $this->_db->setQuery( $query );
  144. if(!$this->_db->query()) {
  145. $this->setError($this->_db->getErrorMsg());
  146. return false;
  147. }
  148. }
  149. return true;
  150. }
  151. function publish($cid = array(), $publish = 1)
  152. {
  153. $user =& JFactory::getUser();
  154. if (count( $cid ))
  155. {
  156. JArrayHelper::toInteger($cid);
  157. $cids = implode( ',', $cid );
  158. $query = 'UPDATE #__phocaguestbook_books'
  159. . ' SET published = '.(int) $publish
  160. . ' WHERE id IN ( '.$cids.' )'
  161. . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )'
  162. ;
  163. $this->_db->setQuery( $query );
  164. if (!$this->_db->query()) {
  165. $this->setError($this->_db->getErrorMsg());
  166. return false;
  167. }
  168. }
  169. return true;
  170. }
  171. function move($direction)
  172. {
  173. $row =& $this->getTable();
  174. if (!$row->load($this->_id)) {
  175. $this->setError($this->_db->getErrorMsg());
  176. return false;
  177. }
  178. if (!$row->move( $direction, ' published >= 0 ' )) {
  179. $this->setError($this->_db->getErrorMsg());
  180. return false;
  181. }
  182. return true;
  183. }
  184. function saveorder($cid = array(), $order)
  185. {
  186. $row =& $this->getTable();
  187. $groupings = array();
  188. //$catid is null
  189. // update ordering values
  190. for( $i=0; $i < count($cid); $i++ )
  191. {
  192. $row->load( (int) $cid[$i] );
  193. // track categories
  194. $groupings[] = $row->catid;
  195. if ($row->ordering != $order[$i])
  196. {
  197. $row->ordering = $order[$i];
  198. if (!$row->store()) {
  199. $this->setError($this->_db->getErrorMsg());
  200. return false;
  201. }
  202. }
  203. }
  204. // execute updateOrder for each parent group
  205. $groupings = array_unique( $groupings );
  206. foreach ($groupings as $group){
  207. $row->reorder('catid = '.(int) $group);
  208. }
  209. return true;
  210. }
  211. function _loadData()
  212. {
  213. if (empty($this->_data))
  214. {
  215. $query = 'SELECT p.* '.
  216. ' FROM #__phocaguestbook_books AS p' .
  217. ' WHERE p.id = '.(int) $this->_id;
  218. $this->_db->setQuery($query);
  219. $this->_data = $this->_db->loadObject();
  220. return (boolean) $this->_data;
  221. }
  222. return true;
  223. }
  224. function _initData()
  225. {
  226. // Lets load the content if it doesn't already exist
  227. if (empty($this->_data))
  228. {
  229. $phocaguestbook = new stdClass();
  230. $phocaguestbook->id = 0;
  231. $phocaguestbook->parent_id = 0;
  232. $phocaguestbook->title = null;
  233. $phocaguestbook->name = null;
  234. $phocaguestbook->alias = null;
  235. $phocaguestbook->image = null;
  236. $phocaguestbook->section = null;
  237. $phocaguestbook->image_position = null;
  238. $phocaguestbook->description = null;
  239. $phocaguestbook->published = 0;
  240. $phocaguestbook->checked_out = 0;
  241. $phocaguestbook->checked_out_time = 0;
  242. $phocaguestbook->editor = null;
  243. $phocaguestbook->ordering = 0;
  244. $phocaguestbook->access = 0;
  245. $phocaguestbook->count = 0;
  246. $phocaguestbook->params = null;
  247. $this->_data = $phocaguestbook;
  248. return (boolean) $this->_data;
  249. }
  250. return true;
  251. }
  252. }
  253. ?>