PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_k2/models/extrafields.php

https://github.com/navinpai/GEC-Tandav
PHP | 304 lines | 247 code | 49 blank | 8 comment | 23 complexity | 6cee9f9b2b344a6ea278bfb3bb0f9c12 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: extrafields.php 306 2010-01-11 16:09:17Z joomlaworks $
  4. * @package K2
  5. * @author JoomlaWorks http://www.joomlaworks.gr
  6. * @copyright Copyright (c) 2006 - 2010 JoomlaWorks Ltd. All rights reserved.
  7. * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
  8. */
  9. // no direct access
  10. defined('_JEXEC') or die('Restricted access');
  11. jimport('joomla.application.component.model');
  12. JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');
  13. class K2ModelExtraFields extends JModel
  14. {
  15. function getData() {
  16. $mainframe = &JFactory::getApplication();
  17. $option = JRequest::getCmd('option');
  18. $view = JRequest::getCmd('view');
  19. $db = & JFactory::getDBO();
  20. $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
  21. $limitstart = $mainframe->getUserStateFromRequest($option.$view.'.limitstart', 'limitstart', 0, 'int');
  22. $filter_order = $mainframe->getUserStateFromRequest($option.$view.'filter_order', 'filter_order', 'groupname', 'cmd');
  23. $filter_order_Dir = $mainframe->getUserStateFromRequest($option.$view.'filter_order_Dir', 'filter_order_Dir', 'ASC', 'word');
  24. $filter_state = $mainframe->getUserStateFromRequest($option.$view.'filter_state', 'filter_state', -1, 'int');
  25. $search = $mainframe->getUserStateFromRequest($option.$view.'search', 'search', '', 'string');
  26. $search = JString::strtolower($search);
  27. $filter_type = $mainframe->getUserStateFromRequest($option.$view.'filter_type', 'filter_type', '', 'string');
  28. $filter_group = $mainframe->getUserStateFromRequest($option.$view.'filter_group', 'filter_group', 0, 'int');
  29. $query = "SELECT exf.*, exfg.name as groupname FROM #__k2_extra_fields AS exf LEFT JOIN #__k2_extra_fields_groups exfg ON exf.group=exfg.id WHERE exf.id>0";
  30. if ($filter_state > -1) {
  31. $query .= " AND published={$filter_state}";
  32. }
  33. if ($search) {
  34. $query .= " AND LOWER( exf.name ) LIKE ".$db->Quote('%'.$search.'%');
  35. }
  36. if ($filter_type) {
  37. $query .= " AND `type`=".$db->Quote($filter_type);
  38. }
  39. if ($filter_group) {
  40. $query .= " AND `group`={$filter_group}";
  41. }
  42. if (!$filter_order) {
  43. $filter_order = '`group`';
  44. }
  45. if ($filter_order == 'ordering') {
  46. $query .= " ORDER BY `group`, ordering {$filter_order_Dir}";
  47. }
  48. else {
  49. $query .= " ORDER BY {$filter_order} {$filter_order_Dir}, `group`, ordering";
  50. }
  51. $db->setQuery($query, $limitstart, $limit);
  52. $rows = $db->loadObjectList();
  53. return $rows;
  54. }
  55. function getTotal() {
  56. $mainframe = &JFactory::getApplication();
  57. $option = JRequest::getCmd('option');
  58. $view = JRequest::getCmd('view');
  59. $db = & JFactory::getDBO();
  60. $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
  61. $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int');
  62. $filter_state = $mainframe->getUserStateFromRequest($option.$view.'filter_state', 'filter_state', 1, 'int');
  63. $search = $mainframe->getUserStateFromRequest($option.$view.'search', 'search', '', 'string');
  64. $search = JString::strtolower($search);
  65. $filter_type = $mainframe->getUserStateFromRequest($option.$view.'filter_type', 'filter_type', '', 'string');
  66. $filter_group = $mainframe->getUserStateFromRequest($option.$view.'filter_group', 'filter_group', '', 'string');
  67. $query = "SELECT COUNT(*) FROM #__k2_extra_fields WHERE id>0";
  68. if ($filter_state > -1) {
  69. $query .= " AND published={$filter_state}";
  70. }
  71. if ($search) {
  72. $query .= " AND LOWER( name ) LIKE ".$db->Quote('%'.$search.'%');
  73. }
  74. if ($filter_type) {
  75. $query .= " AND `type`=".$db->Quote($filter_type);
  76. }
  77. if ($filter_group) {
  78. $query .= " AND `group`=".$db->Quote($filter_group);
  79. }
  80. $db->setQuery($query);
  81. $total = $db->loadresult();
  82. return $total;
  83. }
  84. function publish() {
  85. $mainframe = &JFactory::getApplication();
  86. $cid = JRequest::getVar('cid');
  87. $row = & JTable::getInstance('K2ExtraField', 'Table');
  88. foreach ($cid as $id) {
  89. $row->load($id);
  90. $row->publish($id, 1);
  91. }
  92. $cache = & JFactory::getCache('com_k2');
  93. $cache->clean();
  94. $mainframe->redirect('index.php?option=com_k2&view=extraFields');
  95. }
  96. function unpublish() {
  97. $mainframe = &JFactory::getApplication();
  98. $cid = JRequest::getVar('cid');
  99. $row = & JTable::getInstance('K2ExtraField', 'Table');
  100. foreach ($cid as $id) {
  101. $row->load($id);
  102. $row->publish($id, 0);
  103. }
  104. $cache = & JFactory::getCache('com_k2');
  105. $cache->clean();
  106. $mainframe->redirect('index.php?option=com_k2&view=extraFields');
  107. }
  108. function saveorder() {
  109. $mainframe = &JFactory::getApplication();
  110. $db = & JFactory::getDBO();
  111. $cid = JRequest::getVar('cid', array (0), 'post', 'array');
  112. $total = count($cid);
  113. $order = JRequest::getVar('order', array (0), 'post', 'array');
  114. JArrayHelper::toInteger($order, array (0));
  115. $row = & JTable::getInstance('K2ExtraField', 'Table');
  116. $groupings = array ();
  117. for ($i = 0; $i < $total; $i++) {
  118. $row->load((int)$cid[$i]);
  119. $groupings[] = $row->group;
  120. if ($row->ordering != $order[$i]) {
  121. $row->ordering = $order[$i];
  122. if (!$row->store()) {
  123. JError::raiseError(500, $db->getErrorMsg());
  124. }
  125. }
  126. }
  127. $params = &JComponentHelper::getParams('com_k2');
  128. if(!$params->get('disableCompactOrdering')){
  129. $groupings = array_unique($groupings);
  130. foreach ($groupings as $group) {
  131. $row->reorder("`group` = {$group}");
  132. }
  133. }
  134. $cache = & JFactory::getCache('com_k2');
  135. $cache->clean();
  136. $msg = JText::_('New ordering saved');
  137. $mainframe->redirect('index.php?option=com_k2&view=extraFields', $msg);
  138. }
  139. function orderup() {
  140. $mainframe = &JFactory::getApplication();
  141. $cid = JRequest::getVar('cid');
  142. $row = & JTable::getInstance('K2ExtraField', 'Table');
  143. $row->load($cid[0]);
  144. $row->move(-1, "`group` = '{$row->group}'");
  145. $params = &JComponentHelper::getParams('com_k2');
  146. if(!$params->get('disableCompactOrdering'))
  147. $row->reorder("`group` = '{$row->group}'");
  148. $cache = & JFactory::getCache('com_k2');
  149. $cache->clean();
  150. $msg = JText::_('New ordering saved');
  151. $mainframe->redirect('index.php?option=com_k2&view=extraFields', $msg);
  152. }
  153. function orderdown() {
  154. $mainframe = &JFactory::getApplication();
  155. $cid = JRequest::getVar('cid');
  156. $row = & JTable::getInstance('K2ExtraField', 'Table');
  157. $row->load($cid[0]);
  158. $row->move(1, "`group` = '{$row->group}'");
  159. $params = &JComponentHelper::getParams('com_k2');
  160. if(!$params->get('disableCompactOrdering'))
  161. $row->reorder("`group` = '{$row->group}'");
  162. $cache = & JFactory::getCache('com_k2');
  163. $cache->clean();
  164. $msg = JText::_('New ordering saved');
  165. $mainframe->redirect('index.php?option=com_k2&view=extraFields', $msg);
  166. }
  167. function remove() {
  168. $mainframe = &JFactory::getApplication();
  169. $db = & JFactory::getDBO();
  170. $cid = JRequest::getVar('cid');
  171. $row = & JTable::getInstance('K2ExtraField', 'Table');
  172. foreach ($cid as $id) {
  173. $row->load($id);
  174. $row->delete($id);
  175. }
  176. $cache = & JFactory::getCache('com_k2');
  177. $cache->clean();
  178. $mainframe->redirect('index.php?option=com_k2&view=extraFields', JText::_('Delete Completed'));
  179. }
  180. function getExtraFieldsGroup() {
  181. $cid = JRequest::getVar('cid');
  182. $row = & JTable::getInstance('K2ExtraFieldsGroup', 'Table');
  183. $row->load($cid);
  184. return $row;
  185. }
  186. function getGroups() {
  187. $mainframe = &JFactory::getApplication();
  188. $option = JRequest::getCmd('option');
  189. $view = JRequest::getCmd('view');
  190. $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
  191. $limitstart = $mainframe->getUserStateFromRequest($option.$view.'.limitstart', 'limitstart', 0, 'int');
  192. $db = & JFactory::getDBO();
  193. $query = "SELECT * FROM #__k2_extra_fields_groups ORDER BY `name`";
  194. $db->setQuery($query, $limitstart, $limit);
  195. $rows = $db->loadObjectList();
  196. for ($i=0;$i<sizeof($rows);$i++){
  197. $query = "SELECT name FROM #__k2_categories WHERE extraFieldsGroup={$rows[$i]->id}";
  198. $db->setQuery($query);
  199. $categories = $db->loadResultArray();
  200. $rows[$i]->categories = implode(', ', $categories);
  201. }
  202. return $rows;
  203. }
  204. function getTotalGroups() {
  205. $db = & JFactory::getDBO();
  206. $query = "SELECT COUNT(*) FROM #__k2_extra_fields_groups";
  207. $db->setQuery($query);
  208. $total = $db->loadResult();
  209. return $total;
  210. }
  211. function saveGroup(){
  212. $mainframe = &JFactory::getApplication();
  213. $id = JRequest::getInt('id');
  214. $row = & JTable::getInstance('K2ExtraFieldsGroup', 'Table');
  215. if (!$row->bind(JRequest::get('post'))) {
  216. $mainframe->redirect('index.php?option=com_k2&view=extraFieldsGroups', $row->getError(), 'error');
  217. }
  218. if (!$row->check()) {
  219. $mainframe->redirect('index.php?option=com_k2&view=extraFieldsGroup&cid='.$row->id, $row->getError(), 'error');
  220. }
  221. if (!$row->store()) {
  222. $mainframe->redirect('index.php?option=com_k2&view=extraFieldsGroup', $row->getError(), 'error');
  223. }
  224. switch(JRequest::getCmd('task')) {
  225. case 'apply':
  226. $msg = JText::_('Changes to Group saved');
  227. $link = 'index.php?option=com_k2&view=extraFieldsGroup&cid='.$id;
  228. break;
  229. case 'save':
  230. default:
  231. $msg = JText::_('Group Saved');
  232. $link = 'index.php?option=com_k2&view=extraFieldsGroups';
  233. break;
  234. }
  235. $cache = & JFactory::getCache('com_k2');
  236. $cache->clean();
  237. $mainframe->redirect($link, $msg);
  238. }
  239. function removeGroups(){
  240. $mainframe = &JFactory::getApplication();
  241. $db = & JFactory::getDBO();
  242. $cid = JRequest::getVar('cid');
  243. $row = & JTable::getInstance('K2ExtraFieldsGroup', 'Table');
  244. foreach ($cid as $id) {
  245. $row->load($id);
  246. $query = "DELETE FROM #__k2_extra_fields WHERE `group`={$id}";
  247. $db->setQuery($query);
  248. $db->query();
  249. $row->delete($id);
  250. }
  251. $cache = & JFactory::getCache('com_k2');
  252. $cache->clean();
  253. $mainframe->redirect('index.php?option=com_k2&view=extraFieldsGroups', JText::_('Delete Completed'));
  254. }
  255. }