the-art-of-joomla-archive /exchange/code/trunk/administrator/components/com_exchange/helpers/zine.php

Language PHP Lines 92
MD5 Hash 4801d9b22d607c172c5768a5028f3fe9 Estimated Cost $1,041 (why?)
Repository https://bitbucket.org/eddieajau/the-art-of-joomla-archive View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
 * @version		$Id: zine.php 280 2010-09-18 02:14:15Z eddieajau $
 * @package		NewLifeInIT
 * @subpackage	com_exchange
 * @copyright	Copyright 2005 - 2010 New Life in IT Pty Ltd. All rights reserved.
 * @license		GNU General Public License version 2 or later.
 * @link		http://www.theartofjoomla.com
 */

// no direct access
defined('_JEXEC') or die;

/**
 * Function to find the id of a section that was created
 * during the Core to Magazine migration process. It matches
 * the new section with the old section by the alias.
 *
 * @param	int		$oldId	The old numeric id of row in the #__sections table.
 * @return	int		The numeric id of the section in #__jxzine_categories or 0.
 */
function getZineSectionId($oldId)
{
	$db	= &JFactory::getDBO();
	$db->setQuery('SELECT a.id'
				. ' FROM #__jxzine_categories AS a'
				. ' JOIN #__sections AS b ON b.alias = a.alias'
				. ' WHERE a.parent_id = 0'
				. ' AND a.section = 1'
				. ' AND b.id = '.(int)$oldId);
	return (int)$db->loadResult();
}

/**
 * Function to find the id of a category that was created
 * during the Core to Magazine migration process. It matches
 * the new category with the old category by the alias.
 *
 * @param	int		$oldId	The old numeric id of row in the #__categories table.
 * @return	int		The numeric id of the category in #__jxzine_categories or 0.
 */
function getZineCategoryId($oldId)
{
	$db	= &JFactory::getDBO();
	$db->setQuery('SELECT a.id'
				. ' FROM #__jxzine_categories AS a'
				. ' JOIN #__categories AS b ON b.alias = a.alias'
				. ' WHERE a.parent_id = 1'
				. ' AND a.section = -1'
				. ' AND b.id = '.(int)$oldId);
	return (int)$db->loadResult();
}

/**
 * Function to find the id of an author based on the created_by_alias
 * during the Core to Magazine migration process. If the author does not
 * exist yet, it will be created.
 *
 * @param	string	$oldAlias	The created_by_alias of the article from #__content.
 * @return	int		The numeric id of the author in #__jxzine_authors or 0.
 */
function getZineAuthorIdByAlias($oldAlias)
{
	if (empty($oldAlias)) {
		return 0;
	}

	// Try to load the author id from the database.
	$db	= &JFactory::getDBO();
	$db->setQuery('SELECT a.id'
				. ' FROM #__jxzine_authors AS a'
				. ' WHERE fullname = '.$db->Quote($oldAlias));
	$id = (int)$db->loadResult();

	if ($id > 0) {
		// Return the author id.
		return $id;
	}
	else {
		// Add the author to the database.
		$db->setQuery('INSERT INTO #__jxzine_authors'
					. ' SET fullname = '.$db->Quote($oldAlias));

		// Return the author id.
		if ($db->query()) {
			$id = (int)$db->insertid();
			return $id;
		}
	}

	return 0;
}
Back to Top