Compare commits
3 Commits
feature/cu
...
feature/cu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
704546fee2 | ||
|
|
5df15d39c1 | ||
|
|
143bcac1f9 |
13
extensions/tasks/meta.json
Normal file
13
extensions/tasks/meta.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"label": "My Tasks",
|
||||
"menu": ["Tasks", "fa-list"],
|
||||
"icon": "fa-tasks",
|
||||
"user_levels": [
|
||||
"Admin",
|
||||
"Manager",
|
||||
"User"
|
||||
],
|
||||
"model_namespace": "\\Tasks\\Model",
|
||||
"manager": "\\Tasks\\Extension",
|
||||
"headless": false
|
||||
}
|
||||
28
extensions/tasks/src/Tasks/Extension.php
Normal file
28
extensions/tasks/src/Tasks/Extension.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Tasks;
|
||||
|
||||
use Classes\IceExtension;
|
||||
|
||||
class Extension extends IceExtension
|
||||
{
|
||||
|
||||
public function install() {
|
||||
$migration = new Migration();
|
||||
return $migration->up();
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
$migration = new Migration();
|
||||
return $migration->down();
|
||||
}
|
||||
|
||||
public function setupModuleClassDefinitions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setupRestEndPoints()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
33
extensions/tasks/src/Tasks/Migration.php
Normal file
33
extensions/tasks/src/Tasks/Migration.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Tasks;
|
||||
|
||||
use Classes\Migration\AbstractMigration;
|
||||
|
||||
class Migration extends AbstractMigration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
create table `Tasks` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`employee` bigint(20) NULL,
|
||||
`name` varchar(250) NOT NULL,
|
||||
`description` TEXT NULL,
|
||||
`attachment` varchar(100) NULL,
|
||||
`created` DATETIME default NULL,
|
||||
`updated` DATETIME default NULL,
|
||||
primary key (`id`),
|
||||
CONSTRAINT `Fk_EmployeeTasks_Employees` FOREIGN KEY (`employee`) REFERENCES `Employees` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) engine=innodb default charset=utf8;
|
||||
SQL;
|
||||
return $this->executeQuery($sql);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
DROP TABLE IF EXISTS `Tasks`;
|
||||
SQL;
|
||||
return $this->executeQuery($sql);
|
||||
}
|
||||
}
|
||||
11
extensions/tasks/src/Tasks/Model/Task.php
Normal file
11
extensions/tasks/src/Tasks/Model/Task.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tasks\Model;
|
||||
|
||||
use Classes\ModuleAccess;
|
||||
use Model\BaseModel;
|
||||
|
||||
class Task extends BaseModel
|
||||
{
|
||||
public $table = 'Tasks';
|
||||
}
|
||||
4
extensions/tasks/tasks.php
Normal file
4
extensions/tasks/tasks.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
require_once __DIR__.'/src/Tasks/Extension.php';
|
||||
require_once __DIR__.'/src/Tasks/Migration.php';
|
||||
require_once __DIR__.'/src/Tasks/Model/Task.php';
|
||||
33
extensions/tasks/web/index.php
Normal file
33
extensions/tasks/web/index.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
$user = \Classes\BaseService::getInstance()->getCurrentUser();
|
||||
echo "Welcome ".$user->username."<br/>";
|
||||
|
||||
echo "Creating a task <br/>";
|
||||
|
||||
$task = new \Tasks\Model\Task();
|
||||
$taskName = 'Task-'.rand(rand(0, 100), 50000);
|
||||
|
||||
$task->name = $taskName;
|
||||
$task->employee = $user->employee;
|
||||
$task->description = $taskName.' description';
|
||||
$task->created = date('Y-m-d H:i:s');
|
||||
$task->updated = date('Y-m-d H:i:s');
|
||||
|
||||
/**
|
||||
* Saving the task, $ok will be false if there were any error during the creation
|
||||
*/
|
||||
$ok = $task->Save();
|
||||
|
||||
if (!$ok) {
|
||||
echo "Error: ".$task->ErrorMsg()." <br/>";
|
||||
}
|
||||
|
||||
echo "Find last task <br/>";
|
||||
|
||||
$taskFromDB = new \Tasks\Model\Task();
|
||||
/**
|
||||
* You can use load method to load the first matching task into an empty model
|
||||
*/
|
||||
$taskFromDB->Load('name = ?', [$taskName]);
|
||||
|
||||
var_dump($taskFromDB);
|
||||
Reference in New Issue
Block a user