project.path.php 2.5 KB

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