17 public function __construct($dbh, $logger, String $creditUnion) {
19 $this->logger = $logger;
20 $this->creditUnion = $creditUnion;
23 protected function TableName($creditUnion) {
24 return sprintf(static::TABLE_NAME, $creditUnion);
32 public function Read($creditUnion) {
34 $query =
"SELECT COALESCE(flagset, 0) as flagset, 35 COALESCE(flagset2, 0) as flagset2, 36 COALESCE(flagset3, 0) as flagset3, 38 TRIM(lastupdate) as lastupdate, 41 COALESCE(histdays, 0) as fhdays, 42 COALESCE(gracelimit, 0) as grace, 46 WHERE LOWER(cu) = '". strtolower(prep_save($creditUnion)) .
"'";
48 $query = sprintf($query, static::TABLE_NAME);
49 $sth = db_query($query, $this->dbh);
50 $rows = db_fetch_all($sth);
53 throw new Exception(
'CuAdmin: Problem getting credit union settings!');;
86 public function Update($identifiers, $data) {
87 if (empty($identifiers)) {
88 throw new Exception(static::class .
': Did not pass an identifier to update');
91 throw new Exception(static::class .
': Did not pass any valid columns to update in table ' . $this->TableName($this->creditUnion));
93 $meta = db_meta_data($this->dbh, $this->TableName($this->creditUnion));
96 throw new Exception(static::class .
': Did not pass any valid columns to update in table ' . $this->TableName($this->creditUnion) );
99 $index = count($values) + 1;
100 foreach ($identifiers as $value) {
104 $key = rtrim($key,
',');
110 $sql = sprintf($sql, $this->TableName($this->creditUnion) );
111 $query = db_query_params($sql, array_merge($values, $identifiers), $this->dbh);
113 $error = db_last_error();
114 $this->logger->error(
'Failed updating identifier [' . implode(
',', $identifiers) .
": $error");
142 foreach ($data as $column => $value) {
143 $type = $meta[$column][
'type'];
144 $result .=
"$column = \$$index,\n";
148 return [rtrim($result,
",\n"), $values];
163 foreach ($data as $column => $value) {
164 if (!array_key_exists($column, $meta)) {
165 $this->logger->debug(
"Tried to insert invalid column: $column, into table " . static::TABLE_NAME);
168 $type = $meta[$column][
'type'];
169 $columns[] = $column;
170 $place[] =
"\$$count";
175 implode(
',', $columns),
176 implode(
',', $place),
190 case strpos($type,
'int') !==
false:
191 return intval($value);
193 case strpos($type,
'double') !==
false:
194 case 'numeric' === $type:
195 return floatval($value);
197 case strpos($type,
'char') !==
false:
198 case 'text' === $type:
201 case strpos($type,
'timestamp') !==
false:
202 case 'date' === $type:
205 case strpos($type,
'bool') !==
false:
206 return $value ?
'true' :
'false';
BuildInsertColumns($data, $meta)
BuildSetColumns($data, $meta)
Update($identifiers, $data)
__construct($dbh, $logger, String $creditUnion)
ColumnByType($value, $type)