-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.php
115 lines (96 loc) · 3.08 KB
/
helper.php
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* @package Hello World Module for Joomla!
* @author Jon Brown https://quantumwarp.com/
* @copyright Copyright (C) 2019 Jon Brown, All rights reserved.
* @license GNU/GPLv3 or later; https://www.gnu.org/licenses/gpl.html
*/
// No direct access
defined('_JEXEC') or die;
class ModHelloWorldHelper
{
/**
* Retrieves the `Hello World` message
*
* @param array $params An object containing the module parameters
*
* @access public
*/
public static function getHello($language)
{
// Obtain a database connection
$db = JFactory::getDbo();
// Retrieve the shout - note we are now retrieving the id not the `language` field.
$query = $db->getQuery(true)
->select($db->quoteName('hello'))
->from($db->quoteName('#__mod_helloworld'))
->where('id = '. $db->Quote($language));
// Prepare the query
$db->setQuery($query);
// Load the row.
$result = $db->loadResult();
// Return the Hello
return $result;
}
/**
* com_ajax Action - This example downloads a CSV
*
* @since 1.0.1
*/
public static function downloadCsvActionAjax()
{
// Output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=HelloWorld.csv');
// Create a file pointer connected to the output stream
$output_stream = fopen('php://output', 'w');
// Output the column headings
fputcsv($output_stream, array(\JText::_('MOD_HELLOWORLD_AJAX_RECORD_NAME'), \JText::_('MOD_HELLOWORLD_AJAX_RECORD_TYPE')));
// Demo Content
$records = array(
array('Orange', 'Fruit'),
array('Apple', 'Fruit'),
array('Potato', 'Vegetable'),
array('Carrot', 'Vegetable'),
);
// loop over the records, outputting them as rows
foreach($records as $record) {
$row = array($record[0], $record[1]);
fputcsv($output_stream, $row);
}
// close the csv file
fclose($output_stream);
// Prevent further actions
exit();
}
/**
* com_ajax Action - This example adds a message to a placeholder
*
* @since 1.0.1
*/
public static function addMessageActionAjax()
{
$result = '<script>jQuery(".browser-message").html("'.JTEXT::_('MOD_HELLOWORLD_AJAX_ADDED_MESSAGE_MSG').'");</script>';
return $result;
}
/**
* com_ajax Action - This example removes the message from teh placeholder
*
* @since 1.0.1
*/
public static function removeMessageActionAjax()
{
$result = '<script>jQuery(".browser-message").html("");</script>';
return $result;
}
/**
* com_ajax Action - This example generates a standard Javascript Alert message
*
* @since 1.0.1
*/
public static function alertMessageActionAjax()
{
$result = '<script>alert("'.JTEXT::_('MOD_HELLOWORLD_AJAX_ALERT_MESSAGE_MSG').'");</script>';
return $result;
}
}