summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-06-20 15:41:05 -0300
committerFrédéric Guillot <fred@kanboard.net>2014-06-20 15:41:05 -0300
commit7c5b900bd83b6b9bdb5656eb169381ff46f8106a (patch)
tree39481ff2ee73d7479369655ba86d343f302e1499 /app
parentefdc959c555872677e599d2ff12e1263d719f3f2 (diff)
First API implementation
Diffstat (limited to 'app')
-rw-r--r--app/Model/Board.php15
-rw-r--r--app/Model/Category.php15
-rw-r--r--app/Model/Project.php15
-rw-r--r--app/Model/Task.php17
-rw-r--r--app/Model/User.php2
-rw-r--r--app/Schema/Mysql.php7
-rw-r--r--app/Schema/Sqlite.php7
-rw-r--r--app/Templates/config_index.php4
8 files changed, 77 insertions, 5 deletions
diff --git a/app/Model/Board.php b/app/Model/Board.php
index 59a98923..09fc5b50 100644
--- a/app/Model/Board.php
+++ b/app/Model/Board.php
@@ -99,7 +99,7 @@ class Board extends Base
foreach (array('title', 'task_limit') as $field) {
foreach ($values[$field] as $column_id => $field_value) {
- $this->db->table(self::TABLE)->eq('id', $column_id)->update(array($field => $field_value));
+ $this->updateColumn($column_id, array($field => $field_value));
}
}
@@ -109,6 +109,19 @@ class Board extends Base
}
/**
+ * Update a column
+ *
+ * @access public
+ * @param integer $column_id Column id
+ * @param array $values Form values
+ * @return boolean
+ */
+ public function updateColumn($column_id, array $values)
+ {
+ return $this->db->table(self::TABLE)->eq('id', $column_id)->update($values);
+ }
+
+ /**
* Move a column down, increment the column position value
*
* @access public
diff --git a/app/Model/Category.php b/app/Model/Category.php
index 58eba403..f86abe58 100644
--- a/app/Model/Category.php
+++ b/app/Model/Category.php
@@ -62,6 +62,21 @@ class Category extends Base
}
/**
+ * Return all categories for a given project
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function getAll($project_id)
+ {
+ return $this->db->table(self::TABLE)
+ ->eq('project_id', $project_id)
+ ->asc('name')
+ ->findAll();
+ }
+
+ /**
* Create a category
*
* @access public
diff --git a/app/Model/Project.php b/app/Model/Project.php
index e1465012..b5716a81 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -198,6 +198,18 @@ class Project extends Base
}
/**
+ * Get a project by the name
+ *
+ * @access public
+ * @param string $project_name Project name
+ * @return array
+ */
+ public function getByName($project_name)
+ {
+ return $this->db->table(self::TABLE)->eq('name', $project_name)->findOne();
+ }
+
+ /**
* Fetch project data by using the token
*
* @access public
@@ -505,7 +517,8 @@ class Project extends Base
new Validators\Integer('id', t('This value must be an integer')),
new Validators\Required('name', t('The project name is required')),
new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50),
- new Validators\Unique('name', t('This project must be unique'), $this->db->getConnection(), self::TABLE)
+ new Validators\Unique('name', t('This project must be unique'), $this->db->getConnection(), self::TABLE),
+ new Validators\Integer('is_active', t('This value must be an integer'))
));
return array(
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 70f1404c..09e2f4e4 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -114,6 +114,23 @@ class Task extends Base
* @access public
* @param integer $project_id Project id
* @param array $status List of status id
+ * @return array
+ */
+ public function getAll($project_id, array $status = array(self::STATUS_OPEN, self::STATUS_CLOSED))
+ {
+ return $this->db
+ ->table(self::TABLE)
+ ->eq('project_id', $project_id)
+ ->in('is_active', $status)
+ ->findAll();
+ }
+
+ /**
+ * Count all tasks for a given project and status
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param array $status List of status id
* @return integer
*/
public function countByProjectId($project_id, array $status = array(self::STATUS_OPEN, self::STATUS_CLOSED))
diff --git a/app/Model/User.php b/app/Model/User.php
index 6804d765..3240d547 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -135,7 +135,7 @@ class User extends Base
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values);
- if ($_SESSION['user']['id'] == $values['id']) {
+ if (session_id() !== '' && $_SESSION['user']['id'] == $values['id']) {
$this->updateSession();
}
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 5c7e256f..ddb2acee 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -2,7 +2,12 @@
namespace Schema;
-const VERSION = 18;
+const VERSION = 19;
+
+function version_19($pdo)
+{
+ $pdo->exec("ALTER TABLE config ADD COLUMN api_token VARCHAR(255) DEFAULT '".\Core\Security::generateToken()."'");
+}
function version_18($pdo)
{
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index bfe81c13..438769f0 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -2,7 +2,12 @@
namespace Schema;
-const VERSION = 18;
+const VERSION = 19;
+
+function version_19($pdo)
+{
+ $pdo->exec("ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT '".\Core\Security::generateToken()."'");
+}
function version_18($pdo)
{
diff --git a/app/Templates/config_index.php b/app/Templates/config_index.php
index 602e2070..b242d16f 100644
--- a/app/Templates/config_index.php
+++ b/app/Templates/config_index.php
@@ -46,6 +46,10 @@
<?= t('Webhooks token:') ?>
<strong><?= Helper\escape($values['webhooks_token']) ?></strong>
</li>
+ <li>
+ <?= t('API token:') ?>
+ <strong><?= Helper\escape($values['api_token']) ?></strong>
+ </li>
<?php if (DB_DRIVER === 'sqlite'): ?>
<li>
<?= t('Database size:') ?>