project.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. Bugs::actions(
  3. 'project_create',
  4. 'project_update',
  5. 'project_delete'
  6. );
  7. Router::paths(array(
  8. '/project/{project}'=>function($res,$args){
  9. $res->write(
  10. Bugs::template('project')
  11. ->run(Bugs::project(is_numeric($args->project)?intval($args->project):$args->project)
  12. )
  13. );
  14. },
  15. '/project/{project}/issue/{issue}'=>function($res,$args){
  16. Router::redirect(Router::url(Router::$base."/!{$args->issue}"));
  17. },
  18. '/project/{project}/!{issue}'=>function($res,$args){
  19. Router::redirect(Router::url(Router::$base."!{$args->issue}"));
  20. },
  21. '/project/{project}/update'=>function($res,$args){
  22. if(!empty($_POST['name'])&&!empty($_POST['description'])){
  23. $project = Bugs::project(is_numeric($args->project)?intval($args->project):$args->project);
  24. $project->name = $_POST['name'];
  25. $project->description = $_POST['description'];
  26. $res->json(array(
  27. 'name'=>$project->name
  28. ));
  29. }else{
  30. $res->json(array(
  31. 'error'=>'You must specify a name and description.'
  32. ));
  33. }
  34. },
  35. '/project/{project}/create/issue'=>function($res,$args){
  36. $res->write(Bugs::template('issue'));
  37. },
  38. '/project/{project}/create/issue/complete'=>function($res,$args){
  39. if(!empty($_POST['name'])&&!empty($_POST['description'])){
  40. $issue = Bugs::project(is_numeric($args->project)?intval($args->project):$args->project)
  41. ->issue($_POST['name'],$_POST['description']);
  42. $res->json(array(
  43. 'id'=>$issue->id
  44. ));
  45. }else{
  46. $res->json(array(
  47. 'error'=>'You must specify a name and description.'
  48. ));
  49. }
  50. },
  51. '/create/project'=>function($res,$args){
  52. $res->write(Bugs::template('project'));
  53. },
  54. '/create/project/complete'=>function($res,$args){
  55. if(!empty($_POST['name'])){
  56. if(!Bugs::project_id($_POST['name'])){
  57. $project = Bugs::project($_POST['name'],$_POST['description']);
  58. $res->json(array(
  59. 'name'=>$project->name
  60. ));
  61. }else{
  62. $res->json(array(
  63. 'error'=>"A project with the name {$_POST['name']} already exists."
  64. ));
  65. }
  66. }else{
  67. $res->json(array(
  68. 'error'=>'No name specified'
  69. ));
  70. }
  71. }
  72. ));
  73. ?>