Ejemplo n.º 1
0
 /**
  * Delete task
  */
 public function deleteTask($id)
 {
     $query = new TaskerMAN\Core\DBQuery("DELETE FROM `tasks` \n\t\t\tWHERE `id` = ?\n\t\t\tLIMIT 1\n\t\t");
     $query->execute($id);
     $query = new TaskerMAN\Core\DBQuery("DELETE FROM `steps`\n\t\t\tWHERE `task_id` = ?\n\t\t");
     $query->execute($id);
 }
 /**
  * Validates a user with given email address and password,
  * returns either boolean false or a User object with that user's
  * information
  *
  * @param string $email
  * @param string $password
  * @return mixed Response
  */
 public static function verifyCredentials($email, $password)
 {
     $query = new \TaskerMAN\Core\DBQuery("SELECT `id`, `password`\r\n\t\t\tFROM `users`\r\n\t\t\tWHERE `email` = ?\r\n\t\t\tLIMIT 1\r\n\t\t");
     $query->execute($email);
     $fetch = $query->row();
     // Compare given password with stored user password hash
     if (password_verify($password, $fetch['password'])) {
         return new User($fetch['id']);
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * Loads user info into the object
  *
  * @return boolean
  */
 private function load()
 {
     $query = new \TaskerMAN\Core\DBQuery("SELECT `email`, `name`, `admin`, `api_token`\r\n\t\t\tFROM `users`\r\n\t\t\tWHERE `id` = ?\r\n\t\t\tLIMIT 1\r\n\t\t");
     $query->execute($this->id);
     $fetch = $query->row();
     if (empty($fetch)) {
         return false;
     }
     $this->email = $fetch['email'];
     $this->name = $fetch['name'];
     $this->admin = (bool) $fetch['admin'];
     $this->api_token = $fetch['api_token'];
     return true;
 }
 /**
  * Returns HTML for dropdown
  *
  * @param int $selected Already selected uid
  * @return string HTML output
  */
 public static function generate($selected = null)
 {
     $output = '';
     $query = new \TaskerMAN\Core\DBQuery("SELECT\n\t\t\t`users`.`id`,\n\t\t\t`users`.`name`\n\n\t\t\tFROM `users`\n\n\t\t\tORDER BY `users`.`name` ASC\n\t\t");
     $query->execute();
     while ($row = $query->row()) {
         $output .= '<option value="' . $row['id'] . '"';
         if ($row['id'] == $selected) {
             $output .= ' selected';
         }
         $output .= '>' . $row['name'] . '</option>' . "\n";
     }
     return $output;
 }
Ejemplo n.º 5
0
 /**
  * Saves the task object to the database, also triggers buildSteps() if
  * this is a new task.
  *
  * @return boolean
  * @throws TaskException
  */
 public function save()
 {
     // Check if task is new. If so, INSERT query is run
     if ($this->new_task) {
         if (empty($this->temp_steps)) {
             // Each task must have at least one step associated with it
             throw new TaskException('Task creation requires at least one associated step');
             return false;
         }
         $stmt = new \TaskerMAN\Core\DBQuery("INSERT INTO `tasks`\r\n\t\t\t\t(`created_uid`, `created_time`, `assignee_uid`, `due_by`, `completed_time`, `status`, `title`)\r\n\t\t\t\tVALUES\r\n\t\t\t\t(:created_uid, NOW(), :assignee_uid, :due_by, :completed_time, :status, :title)\r\n\t\t\t");
     } else {
         $stmt = new \TaskerMAN\Core\DBQuery("UPDATE `tasks` SET\r\n\t\t\t\t`created_uid` = :created_uid,\r\n\t\t\t\t`assignee_uid` = :assignee_uid,\r\n\t\t\t\t`due_by` = :due_by,\r\n\t\t\t\t`completed_time` = :completed_time,\r\n\t\t\t\t`status` = :status,\r\n\t\t\t\t`title`= :title\r\n\r\n\t\t\t\tWHERE `id` = :id\r\n\t\t\t\tLIMIT 1\r\n\t\t\t");
         $stmt->bindValue(':id', (int) $this->id, \PDO::PARAM_INT);
     }
     // Bind variables
     $stmt->bindValue(':created_uid', (int) $this->created_uid, \PDO::PARAM_INT);
     $stmt->bindValue(':assignee_uid', (int) $this->assignee_uid, \PDO::PARAM_INT);
     $stmt->bindValue(':due_by', (string) $this->due_by, \PDO::PARAM_STR);
     $stmt->bindValue(':completed_time', (string) $this->completed_time, \PDO::PARAM_STR);
     $stmt->bindValue(':status', (int) $this->status, \PDO::PARAM_INT);
     $stmt->bindValue(':title', (string) $this->title, \PDO::PARAM_STR);
     $stmt->execute();
     // If this is a new task, run buildSteps()
     if ($this->new_task) {
         $this->id = $stmt->lastInsertID();
         $this->new_task = false;
         $this->buildSteps();
     }
 }
 /**
  * Saves any changes to the database
  */
 public function save()
 {
     if ($this->new_step) {
         $query = new \TaskerMAN\Core\DBQuery("INSERT INTO `steps`\r\n\t\t\t\t(`task_id`, `title`, `comment`)\r\n\t\t\t\tVALUES\r\n\t\t\t\t(:task_id, :title, :comment)\r\n\t\t\t");
         $query->bindValue(':task_id', $this->task_id);
         $query->bindValue(':title', $this->title);
         $query->bindValue(':comment', $this->comment);
         $query->execute();
         $this->id = $query->lastInsertID();
     } else {
         $query = new \TaskerMAN\Core\DBQuery("UPDATE `steps` SET\r\n\t\t\t\t`title` = :title,\r\n\t\t\t\t`comment` = :comment\r\n\r\n\t\t\t\tWHERE `id` = :id\r\n\t\t\t\tLIMIT 1\r\n\t\t\t");
         $query->bindValue(':id', $this->id);
         $query->bindValue(':title', $this->title);
         $query->bindValue(':comment', $this->comment);
         $query->execute();
     }
 }
 /**
  * Returns total count of users in database
  *
  * @return int Count
  */
 public static function getNumUsers()
 {
     $conditional = self::buildConditional();
     $query = new \TaskerMAN\Core\DBQuery("SELECT\r\n\t\t \tCOUNT(*) AS `count`\r\n\t\t\tFROM `users`\r\n\r\n\t\t\t{$conditional}\r\n\t\t");
     // Bind any conditional parameters
     if (!is_null($conditional)) {
         foreach (self::$search_criteria as $key => $criteria) {
             if ($criteria['enabled']) {
                 $query->bindValue($criteria['parameter'], $criteria['value']);
             }
         }
     }
     $query->execute();
     $row = $query->row();
     return $row['count'];
 }
<?php

$tasks = range(1, 50);
// Title generation
$verbs = array('Fix', 'Create', 'Confirm', 'Eat', 'Drink', 'Paint', 'Code', 'Test');
$things = array('beer', 'user interface', 'burgers', 'pizza', 'code', 'Jack Reed', 'desktop application', 'Java', 'PHP', 'coffee', 'meeting', 'pasta');
// Get array of all user IDs
$query = new TaskerMAN\Core\DBQuery("SELECT `id` FROM `users`");
$query->execute();
while ($row = $query->row()) {
    $users[] = $row['id'];
}
// Get array of all admins
$query = new TaskerMAN\Core\DBQuery("SELECT `id` FROM `users` WHERE `admin` = '1'");
$query->execute();
while ($row = $query->row()) {
    $admins[] = $row['id'];
}
foreach ($tasks as $i) {
    $t = new TaskerMAN\Application\Task();
    $t->setAssignee($users[array_rand($users)]);
    $due_by = rand_future_time();
    $t->setDueBy(date('Y-m-d', $due_by));
    $t->setCreatedByUser($admins[array_rand($admins)]);
    if (rand(1, 5) > 2) {
        $status = 2;
    } else {
        $status = 1;
    }
    $t->setStatus($status);
    $steps = range(1, rand(1, 3));
 /** 
  * Deletes a given user from the database
  *
  * @param int $id
  * @return boolean
  */
 public static function delete($id)
 {
     // Do not allow deletion if only one user is registered
     $query = new \TaskerMAN\Core\DBQuery("SELECT COUNT(*) AS `rowCount`\r\n\t\t\tFROM `users`\r\n\t\t\tWHERE `admin` = '1'\r\n\t\t");
     $query->execute();
     $fetch = $query->row();
     if ($fetch['rowCount'] == 1) {
         throw new UserManagementException('Cannot delete last remaining administrator');
         return false;
     }
     $query = new \TaskerMAN\Core\DBQuery("DELETE FROM `users`\r\n\t\t\tWHERE `id` = ?\r\n\t\t\tLIMIT 1\r\n\t\t");
     $query->execute($id);
     // Assign this user's tasks to currently logged in user
     $query = new \TaskerMAN\Core\DBQuery("UPDATE `tasks`\r\n\t\t\tSET `assignee_uid` = ?\r\n\t\t\tWHERE `assignee_uid` = ?\r\n\t\t");
     $query->execute(\TaskerMAN\WebInterface\WebInterface::$user->getID(), $id);
     // Make all tasks this user created to now be created by the currently logged in user
     $query = new \TaskerMAN\Core\DBQuery("UPDATE `tasks`\r\n\t\t\tSET `created_uid` = ?\r\n\t\t\tWHERE `created_uid` = ?\r\n\t\t");
     $query->execute(\TaskerMAN\WebInterface\WebInterface::$user->getID(), $id);
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Returns the API token for a given user id
  *
  * @param int user id
  * @return string API Token
  */
 public static function getUserAPIToken($uid)
 {
     $query = new \TaskerMAN\Core\DBQuery("SELECT `api_token`\r\n\t\t\tFROM `users`\r\n\t\t\tWHERE `id` = ?\r\n\t\t\tLIMIT 1\r\n\t\t");
     $query->execute($uid);
     if ($query->rowCount() < 1) {
         return false;
     }
     $fetch = $query->row();
     return $fetch['api_token'];
 }
 /**
  * Clean up and delete test user from database
  */
 public function deleteUser($uid)
 {
     $query = new TaskerMAN\Core\DBQuery("DELETE FROM `users`\n\t\t\tWHERE `id` = ?\n\t\t\tLIMIT 1\n\t\t");
     $query->execute($uid);
 }
 /**
  * Returns number of tasks assigned to each user
  *
  * @return array statistics
  */
 public static function getTaskDistribution()
 {
     $query = new \TaskerMAN\Core\DBQuery("SELECT \r\n\t\t\t`tasks`.`assignee_uid`,\r\n\t\t\tCOUNT(*) AS `count`,\r\n\t\t\t`users`.`name`\r\n\t\t\tFROM `tasks` \r\n\t\t\tJOIN `users` ON `users`.`id` = `tasks`.`assignee_uid`\r\n\t\t\tGROUP BY `tasks`.`assignee_uid`\r\n\t\t");
     $query->execute();
     return $query->results();
 }