├── LICENSE ├── README.md ├── composer.json └── src ├── Base.php ├── Facades └── TaskManager.php ├── Formatter └── Formatter.php ├── Laravel └── TaskManagerServiceProvider.php ├── app └── Http │ └── routes.php ├── config └── taskmanager.php ├── database └── migrations │ ├── 2015_12_26_022802_create_projects_table.php │ ├── 2015_12_26_022803_create_tasks_table.php │ └── 2015_12_26_022804_add_foreign_keys_to_tasks_table.php └── resources └── ajax.php /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Fariz Luqman (Studio Nexus) 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TaskManager 2 | A simple task manager for Laravel 3 | - Simple and extensible 4 | - Method chaining 5 | - Formatter (alpha) 6 | 7 | TaskManager is a Laravel package which allows you to create projects, and create tasks. The package is in **development stage** for time being, and not ready for production uses. 8 | 9 | ---- 10 | 11 | ### Version 12 | 0.3.2 13 | 14 | ### Requirements 15 | 16 | * Laravel - version 5 (version 4 <= untested, need help here). 17 | * PHP - version => 5.3 18 | 19 | ---- 20 | 21 | ### Installation 22 | 23 | Download the package as a zip, and then put it on /vendor folder. 24 | 25 | Add the following line on your **composer.json** file, under the psr-4: 26 | 27 | ``` 28 | "psr-4": { 29 | ... 30 | "Areyi\\TaskManager\\": "vendor/areyi/taskmanager/src" 31 | } 32 | ``` 33 | 34 | After that, register the TaskManagerServiceProvider in the /config/app.php file, under the **providers** array: 35 | ```php 36 | 'Areyi\TaskManager\Laravel\TaskManagerServiceProvider' 37 | ``` 38 | 39 | And in the same file, put the TaskManager alias under the **aliases** array: 40 | ```php 41 | 'TaskManager' => 'Areyi\TaskManager\Facades\TaskManager' 42 | ``` 43 | 44 | And finally, run all the migration files 45 | ```sh 46 | php artisan migrate --path=vendor/areyi/taskmanager/src/database/migrations 47 | ``` 48 | 49 | ---- 50 | 51 | ## Usage 52 | 53 | First, you must supply with the user_id (which you can get from your favourite authentication managers). This will make sure projects and tasks belongs to the right user. 54 | 55 | ```php 56 | $user_id = 1; // get from your login manager 57 | TaskManager::setUserId($user_id); 58 | ``` 59 | 60 | ### 1. To create a new project: 61 | Try this: 62 | ```sh 63 | $project_details = [ 64 | 'name' => 'New Project', 65 | 'name' => 'new_project', //optional 66 | ]; 67 | 68 | TaskManager::addProject($project_details); 69 | ``` 70 | 71 | which will return: 72 | ``` 73 | Areyi\TaskManager\Base Object 74 | ( 75 | [userID] => 1 76 | [result] => 1 77 | [project_id] => 77 78 | ) 79 | ``` 80 | 81 | ### 2. To create a new task: 82 | You can straightaway creating a task without supplying the project_id if you have created a project before 83 | ```php 84 | $task_details = [ 85 | 'name' => 'New Task' 86 | ]; 87 | 88 | TaskManager::addTask($task_details); 89 | ``` 90 | 91 | or you can also chain them to create multiple tasks: 92 | ```php 93 | TaskManager::addTask($task_details)->addTask($task2_details)->addTask($task3_details); 94 | ``` 95 | 96 | which will return: 97 | 98 | ``` 99 | Areyi\TaskManager\Base Object 100 | ( 101 | [userID] => 1 102 | [result] => 1 103 | [project_id] => 79 104 | [task_id] => Array 105 | ( 106 | [0] => 75 107 | [1] => 76 108 | [2] => 77 109 | ) 110 | ) 111 | ``` 112 | 113 | and you can also create project and add tasks to it at the same time: 114 | ```php 115 | TaskManager::addProject($project_details)->addTask($task_details)->addTask($task_details); 116 | ``` 117 | 118 | ### 3. Get all projects: 119 | To get all existing projects: 120 | ```php 121 | TaskManager::getProjects(); 122 | ``` 123 | which will returns straightaway: 124 | ``` 125 | Areyi\TaskManager\Base Object 126 | ( 127 | [userID] => 1 128 | [projects] => Array 129 | ( 130 | [0] => Array 131 | ( 132 | [id] => 1 133 | [name] => Web Development Project 134 | [slug] => webdev 135 | [owner_id] => 1 136 | [owner] => admin 137 | [created_at] => 2015-12-26 01:00:55 138 | [updated_at] => 2015-12-26 01:00:55 139 | ) 140 | 141 | [1] => Array 142 | ( 143 | [id] => 2 144 | [name] => New Project 145 | [slug] => new_project 146 | [owner_id] => 2 147 | [owner] => staff 148 | [created_at] => 2015-12-26 01:43:38 149 | [updated_at] => 2015-12-26 01:43:38 150 | ) 151 | ) 152 | ) 153 | ``` 154 | 155 | ### 4. Get all tasks with specified project_id 156 | 157 | To get all tasks assign to a project: 158 | ```php 159 | $project_id = 1; 160 | TaskManager::getProject($project_id)->getTasks(); 161 | ``` 162 | which returns: 163 | 164 | ``` 165 | Areyi\TaskManager\Base Object 166 | ( 167 | [userID] => 1 168 | [id] => 1 169 | [name] => Web Development Project 170 | [slug] => webdev 171 | [owner_id] => 1 172 | [owner] => admin 173 | [created_at] => 2015-12-26 01:43:38 174 | [updated_at] => 2015-12-26 01:43:38 175 | [tasks] => Array 176 | ( 177 | [0] => Array 178 | ( 179 | [id] => 1 180 | [name] => Buy a milk 181 | [slug] => 182 | [author_id] => 1 183 | [author] => admin 184 | [completed] => 0 185 | [description] => 186 | [created_at] => 2015-12-26 01:43:38 187 | [updated_at] => 2015-12-26 01:43:38 188 | ) 189 | 190 | [1] => Array 191 | ( 192 | [id] => 2 193 | [name] => Buy a book 194 | [slug] => 195 | [author_id] => 1 196 | [author] => admin 197 | [completed] => 0 198 | [description] => 199 | [created_at] => 2015-12-26 01:43:38 200 | [updated_at] => 2015-12-26 01:43:38 201 | ) 202 | 203 | ) 204 | 205 | ) 206 | ``` 207 | 208 | #### 5. Get the whole thing 209 | You can also get all projects along with their tasks: 210 | ```php 211 | TaskManager::getAll(); 212 | ``` 213 | 214 | #### 6. Delete a project 215 | To delete a project (this will also delete all tasks under the same project): 216 | ```php 217 | $projectId = 1; 218 | TaskManager::deleteProject($projectId); 219 | ``` 220 | 221 | #### 7. Delete a task 222 | To delete a task: 223 | ```php 224 | $task_id = 1; 225 | TaskManager::deleteTask($task_id); 226 | ``` 227 | 228 | 229 | #### 8. Mark a task as completed 230 | To mark a task as completed: 231 | ```php 232 | TaskManager::completeTask($task_id) 233 | ``` 234 | 235 | ---- 236 | 237 | ### Formatting 238 | This is **still under development**! 239 | TaskManager is included with a powerful formatter, allowing you to edit or delete projects/tasks and complete a task on the run. The formatter is powered by AJAX. 240 | 241 | #### 1. Get all projects as list 242 | To list all projects as a list 243 | ```php 244 | TaskManager::getProjects()->format()->asList(); 245 | ``` 246 | 247 | Result: 248 | * Web Development Project (by admin) [Delete](#) 249 | * Test Project (by admin) [Delete](#) 250 | 251 | #### 2. Get all tasks as list 252 | To list all tasks under a project as a list 253 | ```php 254 | $project_id = 1; 255 | TaskManager::getProject($project_id)->getTasks()->format()->asList(); 256 | ``` 257 | 258 | Result: 259 | * Buy a milk [Complete](#) 260 | * Buy a book [Complete](#) 261 | 262 | ---- 263 | 264 | ### List of available routes 265 | These are the available routes in the package: 266 | 267 | | Route | Uses | 268 | |----------------------------------------------|------------------------------------------| 269 | | GET /taskmanager/list/all | List all projects and tasks | 270 | | GET /taskmanager/list/projects | List all projects | 271 | | GET /taskmanager/list/project/{project_id} | Get a project with the given project id | 272 | | GET /taskmanager/list/tasks/{project_id} | Get tasks associated with the project id | 273 | | GET /taskmanager/delete/project/{project_id} | Delete the project | 274 | | GET /taskmanager/delete/task/{task_id} | Delete the task | 275 | | GET /taskmanager/complete/task/{task_id} | Mark the task as completed | 276 | 277 | ---- 278 | 279 | ### List of avaiable methods 280 | These are the methods in the package: 281 | 282 | | Method | Uses | 283 | |--------------------------------------------|----------------------------------------------| 284 | | TaskManager::setUserId($userId); | Set the ownership for all projects and tasks | 285 | | TaskManager::addProject($project_details); | Create a new project | 286 | | TaskManager::addTask($task_details); | Add a new task | 287 | | TaskManager::getProjects(); | Get all projects | 288 | | TaskManager::getProject($project_id); | Get a project by given project_id | 289 | | TaskManager::getTasks(); | Get all tasks | 290 | | TaskManager::getTask($project_id); | Get a task by given project_id | 291 | | TaskManager::getAll(); | Get all projects and their tasks | 292 | | TaskManager::deleteProject($projectId); | Delete a project | 293 | | TaskManager::deleteTask($taskId); | Delete a task | 294 | | TaskManager::completeTask($taskId); | Mark a task as done | 295 | | TaskManager::format(); | (todo) | 296 | 297 | ---- 298 | 299 | ### Todos 300 | 301 | - Formatter (50%) 302 | 303 | ---- 304 | 305 | ### License 306 | 307 | BSD 3-Clause 308 | 309 | ### Contributions 310 | 311 | Feel free to contribute to the project! It will be much appriciated! And most importantly, its a **Free Software, Hell Yeah!** 312 | 313 | 314 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "areyi/taskmanager", 3 | "description": "A simple task manager for Laravel 5", 4 | "type": "library", 5 | "license": "BSD 3-Clause", 6 | "keywords": [ 7 | "php", 8 | "areyi", 9 | "laravel", 10 | "todo", 11 | "task manager", 12 | "project manager", 13 | "taskmanager" 14 | ], 15 | "authors": [ 16 | { 17 | "name": "areyi", 18 | "email": "fariz.studionexus@gmail.com" 19 | } 20 | ], 21 | "minimum-stability": "dev", 22 | "require": { 23 | "php": ">=5.4.0", 24 | "illuminate/support": "~5.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Base.php: -------------------------------------------------------------------------------- 1 | initialize(); 15 | } 16 | 17 | /** 18 | * @return null 19 | */ 20 | private function initialize() 21 | { 22 | config([ 23 | 'project_columns' => ['projects.id', 'projects.name', 'projects.slug', 'users.id as owner_id', 'users.username as owner', 'projects.created_at', 'projects.updated_at'] 24 | ]); 25 | 26 | config([ 27 | 'task_columns' => ['tasks.id', 'tasks.name', 'tasks.slug', 'users.id as author_id', 'users.username as author', 'tasks.completed', 'tasks.description', 'tasks.created_at', 'tasks.updated_at'] 28 | ]); 29 | } 30 | 31 | /** 32 | * Set the user id for creating projects and tasks 33 | * @param int $userId 34 | * @return null 35 | */ 36 | public function setUserId($userId) 37 | { 38 | $this->userID = $userId; 39 | } 40 | 41 | /** 42 | * Get all projects and tasks 43 | * @return Areyi\TaskManager $this 44 | */ 45 | public function getAll() 46 | { 47 | $projects = (array) DB::table('projects') 48 | ->join('users', 'users.id', '=', 'projects.owner') 49 | ->get(config('project_columns')); 50 | 51 | $c = 0; 52 | 53 | foreach($projects as $project){ 54 | $this->projects[$c] = (array) $project; 55 | $tasks = (array) DB::table('tasks') 56 | ->where('project_id', $project->id) 57 | ->join('users', 'users.id', '=', 'tasks.author') 58 | ->get(config('task_columns')); 59 | foreach($tasks as $task){ 60 | $this->projects[$c]['tasks'][] = (array) $task; 61 | } 62 | $c++; 63 | } 64 | 65 | return $this; 66 | } 67 | 68 | /** 69 | * Get a project with given projectId 70 | * 71 | * @param mixed $projectId 72 | * @return Areyi\TaskManager $this 73 | */ 74 | public function getProject($projectId) 75 | { 76 | $project = DB::table('projects') 77 | ->where('projects.id', $projectId) 78 | ->join('users', 'users.id', '=', 'projects.owner') 79 | ->first(config('project_columns')); 80 | 81 | if(count($project) == 0){ 82 | return ['error' => 'project not found']; 83 | } 84 | 85 | foreach($project as $key => $value) { 86 | $this->$key = $value; 87 | } 88 | return $this; 89 | } 90 | 91 | /** 92 | * Get whole projects 93 | * @return Areyi\TaskManager $this 94 | */ 95 | public function getProjects() 96 | { 97 | $projects = DB::table('projects') 98 | ->join('users', 'users.id', '=', 'projects.owner') 99 | ->get(config('project_columns')); 100 | foreach($projects as $project) { 101 | $this->projects[] = (array)$project; 102 | } 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * Get all tasks, with or without project id. Get the project ID from $this->id, 109 | * which is created when chaining methods together for example: 110 | * 111 | * TaskManager::addProject($project_details)->addTask($task_details) 112 | * 113 | * @return Areyi\TaskManager $this 114 | */ 115 | public function getTasks() 116 | { 117 | 118 | if(isset($this->id)){ 119 | $tasks = DB::table('tasks') 120 | ->where('project_id', $this->id) 121 | ->join('users', 'users.id', '=', 'tasks.author') 122 | ->get(config('task_columns')); 123 | foreach($tasks as $task) { 124 | $this->tasks[] = (array)$task; 125 | } 126 | }else{ 127 | $tasks = DB::table('tasks') 128 | ->join('users', 'users.id', '=', 'tasks.author') 129 | ->get(config('task_columns')); 130 | foreach($tasks as $task) { 131 | $this->tasks[] = (array)$task; 132 | } 133 | } 134 | 135 | 136 | return $this; 137 | } 138 | 139 | /** 140 | * Get a specific task by task id 141 | * 142 | * @param mixed $taskId 143 | * @return Areyi\TaskManager $this 144 | */ 145 | public function getTask($taskId) 146 | { 147 | $this->task = (array)DB::table('tasks') 148 | ->where('project_id', $this->id) 149 | ->where('tasks.id', $taskId)->join('users', 'users.id', '=', 'tasks.author') 150 | ->first(config('task_columns')); 151 | return $this; 152 | } 153 | 154 | /** 155 | * Create a project 156 | * 157 | * @param mixed|array $details 158 | * @return Areyi\TaskManager $this 159 | */ 160 | public function addProject(array $details) 161 | { 162 | 163 | if(!isset($details['slug'])) 164 | { 165 | $details['slug'] = ''; 166 | } 167 | 168 | $this->result = DB::table('projects')->insert( 169 | [ 170 | 'name' => $details['name'], 171 | 'slug' => $details['slug'], //optional 172 | 'owner' => $this->userID, 173 | 'created_at' => Carbon\Carbon::now(), 174 | 'updated_at' => Carbon\Carbon::now() 175 | ] 176 | ); 177 | 178 | $this->project_id = $this->getLastInsertId(); 179 | Session::set('last_project_id', $this->project_id); 180 | 181 | return $this; 182 | } 183 | 184 | /** 185 | * Create a task 186 | * 187 | * @param mixed|array $details 188 | * @return Areyi\TaskManager $this 189 | */ 190 | public function addTask(array $details) 191 | { 192 | 193 | // Use the default slug 194 | if(!isset($details['slug'])) 195 | { 196 | $details['slug'] = ''; 197 | } 198 | 199 | // Use the default description 200 | if(!isset($details['description'])) 201 | { 202 | $details['description'] = ''; 203 | } 204 | 205 | // Use the newest created project_id 206 | if(!isset($details['project_id'])) 207 | { 208 | if(!isset($this->project_id)) 209 | { 210 | //todo 211 | $details['project_id'] = Session::get('last_project_id'); 212 | } 213 | else 214 | { 215 | $details['project_id'] = $this->project_id; 216 | } 217 | 218 | } 219 | 220 | $this->result = DB::table('tasks')->insert( 221 | [ 222 | 'project_id' => $details['project_id'], 223 | 'name' => $details['name'], 224 | 'slug' => $details['slug'], 225 | 'author' => $this->userID, 226 | 'completed' => 0, 227 | 'description' => $details['description'], 228 | 'created_at' => Carbon\Carbon::now(), 229 | 'updated_at' => Carbon\Carbon::now() 230 | ] 231 | ); 232 | 233 | $this->task_id[] = $this->getLastInsertId(); 234 | 235 | return $this; 236 | } 237 | 238 | /** 239 | * Formats the project / task (Areyi\TaskManager) 240 | * @returns Areyi\TaskManager\Formatter\Formatter $formated 241 | */ 242 | public function format() 243 | { 244 | return $formated = new Formatter($this); 245 | } 246 | 247 | /** 248 | * Delete a project 249 | * $return int $rows_deleted 250 | */ 251 | public function deleteProject($projectId) 252 | { 253 | $rows_deleted = DB::table('projects')->where('id', '=', $projectId)->delete(); 254 | return $rows_deleted; 255 | } 256 | 257 | /** 258 | * Delete a task 259 | * $return int $rows_deleted 260 | */ 261 | public function deleteTask($taskId) 262 | { 263 | $rows_deleted = DB::table('tasks')->where('id', '=', $taskId)->delete(); 264 | return $rows_deleted; 265 | } 266 | 267 | /** 268 | * Mark a task as completed 269 | * $return int $rows_affected 270 | */ 271 | public function completeTask($taskId) 272 | { 273 | $rows_affected = DB::table('tasks') 274 | ->where('id', $taskId) 275 | ->update(['completed' => 1]); 276 | return $rows_affected; 277 | } 278 | 279 | /** 280 | * !!TODO!! 281 | * Helper method to get the last insert id 282 | */ 283 | private function getLastInsertId() 284 | { 285 | $lid = json_decode(json_encode(DB::select('SELECT LAST_INSERT_ID()')), true); 286 | $lastInsertId = $lid[0]['LAST_INSERT_ID()']; 287 | return $lastInsertId; 288 | } 289 | 290 | public function __toString() 291 | { 292 | return json_encode($this); 293 | } 294 | } -------------------------------------------------------------------------------- /src/Facades/TaskManager.php: -------------------------------------------------------------------------------- 1 | _data = $_data; 12 | $this->config = Config::get('taskmanager'); 13 | 14 | } 15 | 16 | public function loadResources(){ 17 | include(__DIR__.'/../resources/ajax.php'); 18 | } 19 | 20 | /** 21 | * !!TODO!! need rework 22 | * 23 | */ 24 | public function asList(){ 25 | if(isset($this->_data->projects)){ 26 | $type = 'p'; 27 | $format_placeholder = Config::get('taskmanager.list_project_format'); 28 | foreach($this->_data->projects as $project){ 29 | echo $this->replace($type, $project, $format_placeholder); 30 | } 31 | }else{ 32 | $type = 't'; 33 | $format_placeholder = Config::get('taskmanager.list_tasks_format'); 34 | foreach($this->_data->tasks as $task){ 35 | echo $this->replace($type, $task, $format_placeholder); 36 | } 37 | } 38 | $this->loadResources(); 39 | } 40 | 41 | 42 | /** 43 | * !!TODO!! need rework 44 | * 45 | */ 46 | public function replace($type, $data, $format_placeholder){ 47 | if(!isset($data['owner'])){ 48 | $data['owner'] = $data['author']; 49 | } 50 | $i = str_replace(':name', $data['name'], $format_placeholder); 51 | $i = str_replace(':username', $data['owner'], $i); 52 | $i = str_replace(':complete_button', $this->config['complete_button'], $i); 53 | $i = str_replace(':view_button', $this->config['view_button'], $i); 54 | $i = str_replace(':edit_button', $this->config['edit_button'], $i); 55 | $i = str_replace(':delete_button', $this->config['delete_button'], $i); 56 | $i = str_replace(':view_url', $this->config['view_url'], $i); 57 | $i = str_replace(':edit_url', $this->config['edit_url'], $i); 58 | 59 | if($type == 'p'){ 60 | $i = str_replace(':type', 'project', $i); 61 | $i = str_replace(':delete_url', $this->config['delete_project_url'], $i); 62 | }else if($type == 't'){ 63 | $i = str_replace(':type', 'task', $i); 64 | $i = str_replace(':delete_url', $this->config['delete_button'], $i); 65 | } 66 | 67 | $i = str_replace(':complete_url', $this->config['complete_url'], $i); 68 | $i = str_replace(':id', $data['id'], $i); 69 | return $i; 70 | } 71 | } -------------------------------------------------------------------------------- /src/Laravel/TaskManagerServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->routesAreCached()) { 20 | require __DIR__.'/../app/Http/routes.php'; 21 | } 22 | } 23 | 24 | /** 25 | * Register the application services. 26 | * 27 | * @return void 28 | */ 29 | public function register() 30 | { 31 | $this->prepareResources(); 32 | } 33 | 34 | /** 35 | * Prepare the package resources. 36 | * 37 | * @return void 38 | */ 39 | protected function prepareResources() 40 | { 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /src/app/Http/routes.php: -------------------------------------------------------------------------------- 1 | '