-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
87 lines (72 loc) · 2.68 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
<?php
/**
* @version 3.0.0
* @package com_imc
* @subpackage mod_imc
* @copyright Copyright (C) 2014. All rights reserved.
* @license GNU AFFERO GENERAL PUBLIC LICENSE Version 3; see LICENSE
* @author Ioannis Tsampoulatidis <[email protected]> - https://github.com/itsam
*/
defined('_JEXEC') or die;
class ModImcinputmapHelper {
/**
* Retrieve component items
* @param Joomla\Registry\Registry &$params module parameters
* @return array Array with all the elements
*/
public static function getList(&$params) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
/* @var $params Joomla\Registry\Registry */
$query
->select('*')
->from($params->get('table'));
$db->setQuery($query, $params->get('offset'), $params->get('limit'));
$rows = $db->loadObjectList();
return $rows;
}
/**
* Retrieve component items
* @param Joomla\Registry\Registry &$params module parameters
* @return mixed stdClass object if the item was found, null otherwise
*/
public static function getItem(&$params) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
/* @var $params Joomla\Registry\Registry */
$query
->select('*')
->from($params->get('item_table'))
->where('id = ' . intval($params->get('item_id')));
$db->setQuery($query);
$element = $db->loadObject();
return $element;
}
/**
* Checks if an element should appear in the table/item view
* @param string $field name of the field
* @return boolean True if it should appear, false otherwise
*/
public static function shouldAppear($field) {
$noHeaderFields = array('checked_out_time', 'checked_out', 'ordering', 'state');
return !in_array($field, $noHeaderFields);
}
/**
* Method to get a value from a external table
* @param string $source_table Source table name
* @param string $key_field Source key field
* @param string $value_field Source value field
* @param mixed $key_value Value for the key field
* @return mixed The value in the external table or null if it wasn't found
*/
private static function loadValueFromExternalTable($source_table, $key_field, $value_field, $key_value) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($value_field)
->from($source_table)
->where($key_field . ' = ' . $db->quote($key_value));
$db->setQuery($query);
return $db->loadResult();
}
}