12 namespace Fossology\Lib\Dao;
44 $where =
"WHERE name <> 'not-set' AND is_enabled = TRUE";
46 $sql =
"SELECT lsc_pk, name, comment, is_enabled " .
47 "FROM license_std_comment $where " .
48 "ORDER BY lsc_pk ASC;";
69 $sql =
"UPDATE license_std_comment " .
70 "SET name = $2, comment = $3, updated = NOW(), user_fk = $4 " .
71 "WHERE lsc_pk = $1 " .
72 "RETURNING 1 AS updated;";
73 $row = $this->
dbManager->getSingleRow($sql,
74 [$commentPk, $newName,
76 return $row[
'updated'] == 1;
95 $comment =
trim($comment);
97 if (empty($name) || empty($comment)) {
109 $statement = __METHOD__ .
".insertNewLicStdComment";
110 $returning =
"lsc_pk";
113 $returnVal = $this->
dbManager->insertTableRow(
"license_std_comment",
114 $params, $statement, $returning);
141 foreach ($commentArray as $commentPk => $comment) {
142 if (count($comment) < 1 ||
143 (! array_key_exists(
"name", $comment) &&
144 ! array_key_exists(
"comment", $comment))) {
145 throw new \UnexpectedValueException(
146 "At least name or comment is " .
"required for entry " . $commentPk);
149 $statement = __METHOD__;
150 $params = [$commentPk, $userFk];
151 $updateStatement = [];
152 if (array_key_exists(
"name", $comment)) {
153 $params[] = $comment[
"name"];
154 $updateStatement[] =
"name = $" . count($params);
155 $statement .=
".name";
157 if (array_key_exists(
"comment", $comment)) {
159 $updateStatement[] =
"comment = $" . count($params);
160 $statement .=
".comment";
162 $sql =
"UPDATE license_std_comment " .
163 "SET updated = NOW(), user_fk = $2, " . join(
",", $updateStatement) .
164 " WHERE lsc_pk = $1 " .
165 "RETURNING 1 AS updated;";
166 $retVal = $this->
dbManager->getSingleRow($sql, $params, $statement);
167 $updated += intval($retVal);
180 $sql =
"SELECT comment FROM license_std_comment " .
"WHERE lsc_pk = $1;";
181 $statement = __METHOD__ .
".getComment";
183 $comment = $this->
dbManager->getSingleRow($sql, [$commentPk], $statement);
184 $comment = $comment[
'comment'];
185 if (strcasecmp($comment,
"null") === 0) {
207 $sql =
"UPDATE license_std_comment " .
208 "SET is_enabled = NOT is_enabled, user_fk = $2 " .
209 "WHERE lsc_pk = $1;";
211 $this->
dbManager->getSingleRow($sql, [$commentPk, $userFk]);
223 if (! is_int($commentPk)) {
224 throw new \UnexpectedValueException(
"Inavlid comment id");
226 $sql =
"SELECT count(*) AS cnt FROM license_std_comment " .
227 "WHERE lsc_pk = $1;";
229 $commentCount = $this->
dbManager->getSingleRow($sql, [$commentPk]);
230 if ($commentCount[
'cnt'] < 1) {
232 throw new \UnexpectedValueException(
"Inavlid comment id");
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
static isAdmin()
Check if user is admin.
static replaceUnicodeControlChar($input, $replace="")
char * trim(char *ptext)
Trimming whitespace.
fo_dbManager * dbManager
fo_dbManager object