/usr/share/php/irods/prods/src/RODSGenQueSelFlds.class.php is in php-irods-prods 3.3.0~beta1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | <?php
require_once("autoload.inc.php");
class RODSGenQueSelFlds
{
private $names;
private $indexes;
private $attrs;
/**
* default constructor.
* @param string $name name of the field, which must be one defined in file 'RodsGenQueryNum.inc.php'.
* @param string $attrs extra options used for operations such as order_by, the expected values are:
* - 'order_by_asc' order the result by this field, in ASCENDING order
* - 'order_by_desc' order the result by this field, in DESCENDING order
* - min minimum of the group
* - max maximum of the group
* - sum sum of the group
* - avg average of the group
* - count count of the group
*/
public function __construct(array $names = array(), array $attrs = array())
{
require_once("RodsGenQueryNum.inc.php"); //load magic numbers
$this->names = $names;
$this->attrs = array();
$this->indexes = array();
for ($i = 0; $i < count($names); $i++) {
$name = $names[$i];
if (!isset($GLOBALS['PRODS_GENQUE_NUMS']["$name"])) {
throw new RODSException("General Query select field name '$name' is not valid",
'PERR_USER_INPUT_ERROR');
}
$this->indexes[] = $GLOBALS['PRODS_GENQUE_NUMS']["$name"];
$this->attrs[] = RODSGenQueSelFlds::attr2GenQueNumber($attrs[$i]);
}
}
/**
* Add a single select field.
*
* @param string name name of the field, which must be one defined in file 'RodsGenQueryNum.inc.php'.
*/
public function add($name, $attr = NULL)
{
require_once("RodsGenQueryNum.inc.php"); //load magic numbers
if (!isset($GLOBALS['PRODS_GENQUE_NUMS']["$name"])) {
throw new RODSException("General Query select field name '$name' is not valid",
'PERR_USER_INPUT_ERROR');
}
$this->indexes[] = $GLOBALS['PRODS_GENQUE_NUMS']["$name"];
$this->names[] = $name;
$this->attrs[] = RODSGenQueSelFlds::attr2GenQueNumber($attr);
}
/**
* update a single select field's attr/value. Note that if the value already exists,
* it will OR the bits. This is used when you want more than one type of operation
* for a select field, such as select_max and sort.
*/
public function update($name, $attr)
{
require_once("RodsGenQueryNum.inc.php"); //load magic numbers
if (!isset($GLOBALS['PRODS_GENQUE_NUMS']["$name"])) {
throw new RODSException("General Query select field name '$name' is not valid",
'PERR_USER_INPUT_ERROR');
}
$newattr = RODSGenQueSelFlds::attr2GenQueNumber($attr);
for ($i = 0; $i < count($this->names); $i++) {
if ($this->names[$i] == $name) {
if ($this->attrs[$i] == 1)
$this->attrs[$i] = $newattr;
else
$this->attrs[$i] = $newattr | $this->attrs[$i];
return;
}
}
$this->add($name, $attr);
}
/**
* Convert supported attribute to magic number, that iRODS protocol uses
* Following attributes are supported:
* - 'order_by_asc' order the result by this field, in ASCENDING order
* - 'order_by_desc' order the result by this field, in DESCENDING order
* - min minimum of the group
* - max maximum of the group
* - sum sum of the group
* - avg average of the group
* - count count of the group
*/
public static function attr2GenQueNumber($attr)
{
if (empty($attr)) return 1;
$retval = 1;
switch ($attr) {
case 'order_by_asc':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['ORDER_BY'];
break;
case 'order_by_desc':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['ORDER_BY_DESC'];
break;
case 'min':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['SELECT_MIN'];
break;
case 'max':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['SELECT_MAX'];
break;
case 'sum':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['SELECT_SUM'];
break;
case 'avg':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['SELECT_AVG'];
break;
case 'count':
$retval = $GLOBALS['PRODS_GENQUE_NUMS']['SELECT_COUNT'];
break;
default:
throw new RODSException("Unexpected attribute: '$attr'",
'PERR_USER_INPUT_ERROR');
}
return intval($retval);
}
/**
* make a RP_InxIvalPair, a low level iRODS packet
*/
public function packetize()
{
return (new RP_InxIvalPair(count($this->names), $this->indexes,
$this->attrs));
}
public function getIndexes()
{
return $this->indexes;
}
public function getAttrs()
{
return $this->attrs;
}
public function getCount()
{
return count($this->names);
}
public function getNames()
{
return $this->names;
}
}
?>
|