PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/aamenu/code/trunk/administrator/components/com_aamenu/models/tags.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 62 lines | 35 code | 9 blank | 18 comment | 2 complexity | 3406e44243f8084dbdad07b12e2520bc MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: tags.php 255 2010-08-20 09:43:07Z eddieajau $
  4. * @package Artof.AAMenu
  5. * @subpackage com_aamenu
  6. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die('Restricted access');
  12. jimport('joomla.application.component.model');
  13. /**
  14. * @package Artof.AAMenu
  15. * @subpackage com_aamenu
  16. */
  17. class AAMenuModelTags extends JModel
  18. {
  19. /**
  20. * Save the tags assigned to the components in the list
  21. *
  22. * @return boolean True if successful, false otherwise and internal error set
  23. */
  24. function save()
  25. {
  26. $request = $this->getState('request');
  27. $db = $this->getDBO();
  28. $tags = JArrayHelper::getValue($request, 'tags', array(), 'array');
  29. $ordering = JArrayHelper::getValue($request, 'ordering', array(), 'array');
  30. $ids = array_keys($tags);
  31. JArrayHelper::toInteger($ids);
  32. $query = 'DELETE FROM #__taoj_aamenu_tags' .
  33. ' WHERE component_id IN ('.implode(',', $ids).')';
  34. $db->setQuery($query);
  35. if (!$db->query()) {
  36. $this->setError($db->getErrorMsg());
  37. return false;
  38. }
  39. $tuples = array();
  40. foreach ($ids as $id)
  41. {
  42. $tuples[] = '('.(int) $id.','.$db->Quote($tags[$id]).','.(int) $ordering[$id].')';
  43. }
  44. $query = 'INSERT INTO #__taoj_aamenu_tags (component_id,tag,ordering) VALUES '.
  45. implode(',', $tuples);
  46. $db->setQuery($query);
  47. if (!$db->query()) {
  48. $this->setError($db->getErrorMsg());
  49. return false;
  50. }
  51. return true;
  52. }
  53. }