summaryrefslogtreecommitdiffstats
path: root/web/lib/pkgfuncs.inc.php
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2014-04-26 14:07:20 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2014-04-26 14:07:20 +0200
commitcc3244ea8ae0202265df3d0fd2cfe86fbbeb9d30 (patch)
treeacdf3629538c57886b41f9216bb4e132939d7452 /web/lib/pkgfuncs.inc.php
parent3720bdf6b264cb4bb603e4199f2758598c260ed4 (diff)
downloadaur-cc3244ea8ae0202265df3d0fd2cfe86fbbeb9d30.tar.gz
aur-cc3244ea8ae0202265df3d0fd2cfe86fbbeb9d30.tar.xz
Store package groups in the database
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib/pkgfuncs.inc.php')
-rw-r--r--web/lib/pkgfuncs.inc.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index a04f5259..f80d4b4b 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -805,3 +805,46 @@ function pkg_add_src($pkgid, $pkgsrc) {
$dbh->exec($q);
}
+
+/**
+ * Creates a new group and returns its ID
+ *
+ * If the groups already exists, the ID of the already existing group is
+ * returned.
+ *
+ * @param string $name The name of the group to create
+ *
+ * @return int The ID of the group
+ */
+function pkg_create_group($name) {
+ $dbh = DB::connect();
+ $q = sprintf("SELECT ID FROM Groups WHERE Name = %s", $dbh->quote($name));
+ $result = $dbh->query($q);
+ if ($result) {
+ $grpid = $result->fetch(PDO::FETCH_COLUMN, 0);
+ if ($grpid > 0) {
+ return $grpid;
+ }
+ }
+
+ $q = sprintf("INSERT INTO Groups (Name) VALUES (%s)", $dbh->quote($name));
+ $dbh->exec($q);
+ return $dbh->lastInsertId();
+}
+
+/**
+ * Add a package to a group
+ *
+ * @param int $pkgid The package ID of the package to add
+ * @param int $grpid The group ID of the group to add the package to
+ *
+ * @return void
+ */
+function pkg_add_grp($pkgid, $grpid) {
+ $dbh = DB::connect();
+ $q = sprintf("INSERT INTO PackageGroups (PackageID, GroupID) VALUES (%d, %d)",
+ $pkgid,
+ $grpid
+ );
+ $dbh->exec($q);
+}