54 $where =
"WHERE name <> 'not-set' AND is_enabled = TRUE";
56 $sql =
"SELECT lsc_pk, name, comment, is_enabled " .
57 "FROM license_std_comment $where " .
58 "ORDER BY lsc_pk ASC;";
79 $sql =
"UPDATE license_std_comment " .
80 "SET name = $2, comment = $3, updated = NOW(), user_fk = $4 " .
81 "WHERE lsc_pk = $1 " .
82 "RETURNING 1 AS updated;";
83 $row = $this->
dbManager->getSingleRow($sql,
84 [$commentPk, $newName, $newComment, $userFk]);
85 return $row[
'updated'] == 1;
104 $comment =
trim($comment);
106 if (empty($name) || empty($comment)) {
115 'comment' => $comment,
118 $statement = __METHOD__ .
".insertNewLicStdComment";
119 $returning =
"lsc_pk";
122 $returnVal = $this->
dbManager->insertTableRow(
"license_std_comment",
123 $params, $statement, $returning);
150 foreach ($commentArray as $commentPk => $comment) {
151 if (count($comment) < 1 ||
152 (! array_key_exists(
"name", $comment) &&
153 ! array_key_exists(
"comment", $comment))) {
154 throw new \UnexpectedValueException(
155 "At least name or comment is " .
"required for entry " . $commentPk);
158 $statement = __METHOD__;
159 $params = [$commentPk, $userFk];
160 $updateStatement = [];
161 if (array_key_exists(
"name", $comment)) {
162 $params[] = $comment[
"name"];
163 $updateStatement[] =
"name = $" . count($params);
164 $statement .=
".name";
166 if (array_key_exists(
"comment", $comment)) {
167 $params[] = $comment[
"comment"];
168 $updateStatement[] =
"comment = $" . count($params);
169 $statement .=
".comment";
171 $sql =
"UPDATE license_std_comment " .
172 "SET updated = NOW(), user_fk = $2, " . join(
",", $updateStatement) .
173 "WHERE lsc_pk = $1 " .
174 "RETURNING 1 AS updated;";
175 $retVal = $this->
dbManager->getSingleRow($sql, $params, $statement);
176 $updated += intval($retVal);
189 $sql =
"SELECT comment FROM license_std_comment " .
"WHERE lsc_pk = $1;";
190 $statement = __METHOD__ .
".getComment";
192 $comment = $this->
dbManager->getSingleRow($sql, [$commentPk], $statement);
193 $comment = $comment[
'comment'];
194 if (strcasecmp($comment,
"null") === 0) {
216 $sql =
"UPDATE license_std_comment " .
217 "SET is_enabled = NOT is_enabled, user_fk = $2 " .
218 "WHERE lsc_pk = $1;";
220 $this->
dbManager->getSingleRow($sql, [$commentPk, $userFk]);
232 if (! is_int($commentPk)) {
233 throw new \UnexpectedValueException(
"Inavlid comment id");
235 $sql =
"SELECT count(*) AS cnt FROM license_std_comment " .
236 "WHERE lsc_pk = $1;";
238 $commentCount = $this->
dbManager->getSingleRow($sql, [$commentPk]);
239 if ($commentCount[
'cnt'] < 1) {
241 throw new \UnexpectedValueException(
"Inavlid comment id");
static getUserId()
Get the current user's id.
static isAdmin()
Check if user is admin.
fo_dbManager * dbManager
fo_dbManager object
char * trim(char *ptext)
Trimming whitespace.