summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/CommentModel.php7
-rw-r--r--app/Model/CurrencyModel.php2
-rw-r--r--app/Model/FileModel.php32
-rw-r--r--app/Model/InviteModel.php73
-rw-r--r--app/Model/ProjectModel.php16
-rw-r--r--app/Model/ProjectPermissionModel.php24
-rw-r--r--app/Model/UserMentionModel.php62
7 files changed, 133 insertions, 83 deletions
diff --git a/app/Model/CommentModel.php b/app/Model/CommentModel.php
index a9e48bd3..e44a5ecd 100644
--- a/app/Model/CommentModel.php
+++ b/app/Model/CommentModel.php
@@ -60,6 +60,7 @@ class CommentModel extends Base
->columns(
self::TABLE.'.id',
self::TABLE.'.date_creation',
+ self::TABLE.'.date_modification',
self::TABLE.'.task_id',
self::TABLE.'.user_id',
self::TABLE.'.comment',
@@ -69,7 +70,7 @@ class CommentModel extends Base
UserModel::TABLE.'.avatar_path'
)
->join(UserModel::TABLE, 'id', 'user_id')
- ->orderBy(self::TABLE.'.date_creation', $sorting)
+ ->orderBy(self::TABLE.'.date_modification', $sorting)
->eq(self::TABLE.'.task_id', $task_id)
->findAll();
}
@@ -90,6 +91,7 @@ class CommentModel extends Base
self::TABLE.'.task_id',
self::TABLE.'.user_id',
self::TABLE.'.date_creation',
+ self::TABLE.'.date_modification',
self::TABLE.'.comment',
self::TABLE.'.reference',
UserModel::TABLE.'.username',
@@ -127,6 +129,7 @@ class CommentModel extends Base
public function create(array $values)
{
$values['date_creation'] = time();
+ $values['date_modification'] = time();
$comment_id = $this->db->table(self::TABLE)->persist($values);
if ($comment_id !== false) {
@@ -148,7 +151,7 @@ class CommentModel extends Base
$result = $this->db
->table(self::TABLE)
->eq('id', $values['id'])
- ->update(array('comment' => $values['comment']));
+ ->update(array('comment' => $values['comment'], 'date_modification' => time()));
if ($result) {
$this->queueManager->push($this->commentEventJob->withParams($values['id'], self::EVENT_UPDATE));
diff --git a/app/Model/CurrencyModel.php b/app/Model/CurrencyModel.php
index bfd9697c..55a5b2fe 100644
--- a/app/Model/CurrencyModel.php
+++ b/app/Model/CurrencyModel.php
@@ -42,6 +42,8 @@ class CurrencyModel extends Base
'NOK' => t('NOK - Norwegian Krone'),
'BAM' => t('BAM - Konvertible Mark'),
'RUB' => t('RUB - Russian Ruble'),
+ 'CNY' => t('CNY - Chinese Yuan'),
+ 'TRL' => t('TRL - Turkish Lira'),
);
}
diff --git a/app/Model/FileModel.php b/app/Model/FileModel.php
index 98032f9d..d04b03bf 100644
--- a/app/Model/FileModel.php
+++ b/app/Model/FileModel.php
@@ -210,9 +210,7 @@ abstract class FileModel extends Base
*/
public function isImage($filename)
{
- $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
-
- switch ($extension) {
+ switch (get_file_extension($filename)) {
case 'jpeg':
case 'jpg':
case 'png':
@@ -309,31 +307,35 @@ abstract class FileModel extends Base
* Handle file upload (base64 encoded content)
*
* @access public
- * @param integer $id
- * @param string $original_filename
- * @param string $blob
- * @return bool|integer
+ * @param integer $id
+ * @param string $originalFilename
+ * @param string $data
+ * @param bool $isEncoded
+ * @return bool|int
*/
- public function uploadContent($id, $original_filename, $blob)
+ public function uploadContent($id, $originalFilename, $data, $isEncoded = true)
{
try {
- $data = base64_decode($blob);
+ if ($isEncoded) {
+ $data = base64_decode($data);
+ }
if (empty($data)) {
+ $this->logger->error(__METHOD__.': Content upload with no data');
return false;
}
- $destination_filename = $this->generatePath($id, $original_filename);
- $this->objectStorage->put($destination_filename, $data);
+ $destinationFilename = $this->generatePath($id, $originalFilename);
+ $this->objectStorage->put($destinationFilename, $data);
- if ($this->isImage($original_filename)) {
- $this->generateThumbnailFromData($destination_filename, $data);
+ if ($this->isImage($originalFilename)) {
+ $this->generateThumbnailFromData($destinationFilename, $data);
}
return $this->create(
$id,
- $original_filename,
- $destination_filename,
+ $originalFilename,
+ $destinationFilename,
strlen($data)
);
} catch (ObjectStorageException $e) {
diff --git a/app/Model/InviteModel.php b/app/Model/InviteModel.php
new file mode 100644
index 00000000..13d75f69
--- /dev/null
+++ b/app/Model/InviteModel.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Kanboard\Model;
+
+use Kanboard\Core\Base;
+use Kanboard\Core\Security\Token;
+
+/**
+ * Class InviteModel
+ *
+ * @package Kanboard\Model
+ * @author Frederic Guillot
+ */
+class InviteModel extends Base
+{
+ const TABLE = 'invites';
+
+ public function createInvites(array $emails, $projectId)
+ {
+ $emails = array_unique($emails);
+ $nb = 0;
+
+ foreach ($emails as $email) {
+ $email = trim($email);
+
+ if (! empty($email) && $this->createInvite($email, $projectId)) {
+ $nb++;
+ }
+ }
+
+ return $nb;
+ }
+
+ protected function createInvite($email, $projectId)
+ {
+ $values = array(
+ 'email' => $email,
+ 'project_id' => $projectId,
+ 'token' => Token::getToken(),
+ );
+
+ if ($this->db->table(self::TABLE)->insert($values)) {
+ $this->sendInvite($values);
+ return true;
+ }
+
+ return false;
+ }
+
+ protected function sendInvite(array $values)
+ {
+ $this->emailClient->send(
+ $values['email'],
+ $values['email'],
+ e('Kanboard Invitation'),
+ $this->template->render('user_invite/email', array('token' => $values['token']))
+ );
+ }
+
+ public function getByToken($token)
+ {
+ return $this->db->table(self::TABLE)
+ ->eq('token', $token)
+ ->findOne();
+ }
+
+ public function remove($email)
+ {
+ return $this->db->table(self::TABLE)
+ ->eq('email', $email)
+ ->remove();
+ }
+}
diff --git a/app/Model/ProjectModel.php b/app/Model/ProjectModel.php
index aba5eee2..080217cb 100644
--- a/app/Model/ProjectModel.php
+++ b/app/Model/ProjectModel.php
@@ -106,6 +106,22 @@ class ProjectModel extends Base
}
/**
+ * Get a project by the email address
+ *
+ * @access public
+ * @param string $email
+ * @return array|boolean
+ */
+ public function getByEmail($email)
+ {
+ if (empty($email)) {
+ return false;
+ }
+
+ return $this->db->table(self::TABLE)->eq('email', $email)->findOne();
+ }
+
+ /**
* Fetch project data by using the token
*
* @access public
diff --git a/app/Model/ProjectPermissionModel.php b/app/Model/ProjectPermissionModel.php
index 25b6a382..dabd406c 100644
--- a/app/Model/ProjectPermissionModel.php
+++ b/app/Model/ProjectPermissionModel.php
@@ -62,17 +62,33 @@ class ProjectPermissionModel extends Base
->withFilter(new ProjectUserRoleProjectFilter($project_id))
->withFilter(new ProjectUserRoleUsernameFilter($input))
->getQuery()
- ->findAllByColumn('username');
+ ->columns(
+ UserModel::TABLE.'.id',
+ UserModel::TABLE.'.username',
+ UserModel::TABLE.'.name',
+ UserModel::TABLE.'.email',
+ UserModel::TABLE.'.avatar_path'
+ )
+ ->findAll();
$groupMembers = $this->projectGroupRoleQuery
->withFilter(new ProjectGroupRoleProjectFilter($project_id))
->withFilter(new ProjectGroupRoleUsernameFilter($input))
->getQuery()
- ->findAllByColumn('username');
+ ->columns(
+ UserModel::TABLE.'.id',
+ UserModel::TABLE.'.username',
+ UserModel::TABLE.'.name',
+ UserModel::TABLE.'.email',
+ UserModel::TABLE.'.avatar_path'
+ )
+ ->findAll();
- $members = array_unique(array_merge($userMembers, $groupMembers));
+ $userMembers = array_column_index_unique($userMembers, 'username');
+ $groupMembers = array_column_index_unique($groupMembers, 'username');
+ $members = array_merge($userMembers, $groupMembers);
- sort($members);
+ ksort($members);
return $members;
}
diff --git a/app/Model/UserMentionModel.php b/app/Model/UserMentionModel.php
deleted file mode 100644
index cdb9949e..00000000
--- a/app/Model/UserMentionModel.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-namespace Kanboard\Model;
-
-use Kanboard\Core\Base;
-use Kanboard\Event\GenericEvent;
-
-/**
- * User Mention
- *
- * @package Kanboard\Model
- * @author Frederic Guillot
- */
-class UserMentionModel extends Base
-{
- /**
- * Get list of mentioned users
- *
- * @access public
- * @param string $content
- * @return array
- */
- public function getMentionedUsers($content)
- {
- $users = array();
-
- if (preg_match_all('/@([^\s]+)/', $content, $matches)) {
- $users = $this->db->table(UserModel::TABLE)
- ->columns('id', 'username', 'name', 'email', 'language')
- ->eq('notifications_enabled', 1)
- ->neq('id', $this->userSession->getId())
- ->in('username', array_unique($matches[1]))
- ->findAll();
- }
-
- return $users;
- }
-
- /**
- * Fire events for user mentions
- *
- * @access public
- * @param string $content
- * @param string $eventName
- * @param GenericEvent $event
- */
- public function fireEvents($content, $eventName, GenericEvent $event)
- {
- if (empty($event['project_id'])) {
- $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']);
- }
-
- $users = $this->getMentionedUsers($content);
-
- foreach ($users as $user) {
- if ($this->projectPermissionModel->isMember($event['project_id'], $user['id'])) {
- $event['mention'] = $user;
- $this->dispatcher->dispatch($eventName, $event);
- }
- }
- }
-}