PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/exchange/code/trunk/administrator/components/com_exchange/helpers/zine.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 92 lines | 47 code | 8 blank | 37 comment | 4 complexity | 4801d9b22d607c172c5768a5028f3fe9 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: zine.php 280 2010-09-18 02:14:15Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_exchange
  6. * @copyright Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License version 2 or later.
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die;
  12. /**
  13. * Function to find the id of a section that was created
  14. * during the Core to Magazine migration process. It matches
  15. * the new section with the old section by the alias.
  16. *
  17. * @param int $oldId The old numeric id of row in the #__sections table.
  18. * @return int The numeric id of the section in #__jxzine_categories or 0.
  19. */
  20. function getZineSectionId($oldId)
  21. {
  22. $db = &JFactory::getDBO();
  23. $db->setQuery('SELECT a.id'
  24. . ' FROM #__jxzine_categories AS a'
  25. . ' JOIN #__sections AS b ON b.alias = a.alias'
  26. . ' WHERE a.parent_id = 0'
  27. . ' AND a.section = 1'
  28. . ' AND b.id = '.(int)$oldId);
  29. return (int)$db->loadResult();
  30. }
  31. /**
  32. * Function to find the id of a category that was created
  33. * during the Core to Magazine migration process. It matches
  34. * the new category with the old category by the alias.
  35. *
  36. * @param int $oldId The old numeric id of row in the #__categories table.
  37. * @return int The numeric id of the category in #__jxzine_categories or 0.
  38. */
  39. function getZineCategoryId($oldId)
  40. {
  41. $db = &JFactory::getDBO();
  42. $db->setQuery('SELECT a.id'
  43. . ' FROM #__jxzine_categories AS a'
  44. . ' JOIN #__categories AS b ON b.alias = a.alias'
  45. . ' WHERE a.parent_id = 1'
  46. . ' AND a.section = -1'
  47. . ' AND b.id = '.(int)$oldId);
  48. return (int)$db->loadResult();
  49. }
  50. /**
  51. * Function to find the id of an author based on the created_by_alias
  52. * during the Core to Magazine migration process. If the author does not
  53. * exist yet, it will be created.
  54. *
  55. * @param string $oldAlias The created_by_alias of the article from #__content.
  56. * @return int The numeric id of the author in #__jxzine_authors or 0.
  57. */
  58. function getZineAuthorIdByAlias($oldAlias)
  59. {
  60. if (empty($oldAlias)) {
  61. return 0;
  62. }
  63. // Try to load the author id from the database.
  64. $db = &JFactory::getDBO();
  65. $db->setQuery('SELECT a.id'
  66. . ' FROM #__jxzine_authors AS a'
  67. . ' WHERE fullname = '.$db->Quote($oldAlias));
  68. $id = (int)$db->loadResult();
  69. if ($id > 0) {
  70. // Return the author id.
  71. return $id;
  72. }
  73. else {
  74. // Add the author to the database.
  75. $db->setQuery('INSERT INTO #__jxzine_authors'
  76. . ' SET fullname = '.$db->Quote($oldAlias));
  77. // Return the author id.
  78. if ($db->query()) {
  79. $id = (int)$db->insertid();
  80. return $id;
  81. }
  82. }
  83. return 0;
  84. }