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);
33 public function Read($username) {
34 $sql =
"SELECT user_id, 35 TRIM(user_name) AS user_name, 36 TRIM(passwd) AS passwd, 37 forcechange AS fchange, 38 COALESCE(forceremain, 0) AS fremain, 41 LOWER(TRIM(email)) AS email, 42 TRIM(confidence) As confidence, 43 group_id AS cuuser_group_id, 44 TRIM(lastlogin) AS llog, 45 TRIM(failedlogin) AS flog, 46 COALESCE(msg_tx, 0) AS msg_tx, 48 COALESCE(challenge_quest_id, 0) AS savecqid, 50 TRIM(primary_account) As primary_account 52 WHERE LOWER(user_name) = '" . strtolower(prep_save($username)) .
"'";
54 $sql = sprintf($sql, $this->TableName($this->creditUnion));
56 $query = db_query($sql, $this->dbh);
59 $error = db_last_error();
60 $this->logger->error(
'Could not read table ' . $this->TableName($this->creditUnion) .
". Error: $error");
63 $rows = db_fetch_all($query);
96 public function Update($identifiers, $data) {
97 if (empty($identifiers)) {
98 throw new Exception(static::class .
': Did not pass an identifier to update');
101 throw new Exception(static::class .
': Did not pass any valid columns to update in table ' . $this->TableName($this->creditUnion));
103 $meta = db_meta_data($this->dbh, $this->TableName($this->creditUnion));
106 throw new Exception(static::class .
': Did not pass any valid columns to update in table ' . $this->TableName($this->creditUnion) );
109 $index = count($values) + 1;
110 foreach ($identifiers as $value) {
114 $key = rtrim($key,
',');
118 WHERE user_name IN ($key);
120 $sql = sprintf($sql, $this->TableName($this->creditUnion) );
121 $query = db_query_params($sql, array_merge($values, $identifiers), $this->dbh);
123 $error = db_last_error();
124 $this->logger->error(
'Failed updating identifier [' . implode(
',', $identifiers) .
": $error");
152 foreach ($data as $column => $value) {
153 $type = $meta[$column][
'type'];
154 $result .=
"$column = \$$index,\n";
158 return [rtrim($result,
",\n"), $values];
173 foreach ($data as $column => $value) {
174 if (!array_key_exists($column, $meta)) {
175 $this->logger->debug(
"Tried to insert invalid column: $column, into table " . static::TABLE_NAME);
178 $type = $meta[$column][
'type'];
179 $columns[] = $column;
180 $place[] =
"\$$count";
185 implode(
',', $columns),
186 implode(
',', $place),
200 case strpos($type,
'int') !==
false:
201 return intval($value);
203 case strpos($type,
'double') !==
false:
204 case 'numeric' === $type:
205 return floatval($value);
207 case strpos($type,
'char') !==
false:
208 case 'text' === $type:
211 case strpos($type,
'timestamp') !==
false:
212 case 'date' === $type:
215 case strpos($type,
'bool') !==
false:
216 return $value ?
'true' :
'false';
BuildSetColumns($data, $meta)
ColumnByType($value, $type)
__construct($dbh, $logger, String $creditUnion)
BuildInsertColumns($data, $meta)
Update($identifiers, $data)