project.path.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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'])&&!empty($_POST['status'])){
  27. $project = Bugs::project(is_numeric($args->project)?intval($args->project):$args->project);
  28. $project->name = $_POST['name'];
  29. $project->description = $_POST['description'];
  30. $project->s_id = $_POST['status'];
  31. $res->json(array(
  32. 'name'=>$project->name
  33. ));
  34. Bugs::activity('project.update',$project);
  35. }else{
  36. $res->json(array(
  37. 'error'=>'You must specify a name and description.'
  38. ));
  39. }
  40. },
  41. '/project/{project}/create/issue'=>function($res,$args){
  42. $res->write(Bugs::template('issue'));
  43. },
  44. '/project/{project}/create/issue/complete'=>function($res,$args){
  45. error_handle_type('json');
  46. if(!empty($_POST['name'])&&!empty($_POST['description'])){
  47. $issue = Bugs::project(is_numeric($args->project)?intval($args->project):$args->project)
  48. ->issue($_POST['name'],$_POST['description']);
  49. $res->json(array(
  50. 'id'=>$issue->id
  51. ));
  52. Bugs::activity('issue.create',$issue);
  53. }else{
  54. $res->json(array(
  55. 'error'=>'You must specify a name and description.'
  56. ));
  57. }
  58. },
  59. '/create/project'=>function($res,$args){
  60. bugs::authorized('project.create');
  61. $res->write(Bugs::template('project'));
  62. },
  63. '/create/project/complete'=>function($res,$args){
  64. error_handle_type('json');
  65. Bugs::authorized('project.create');
  66. if(!empty($_POST['name'])){
  67. if(!Bugs::project_id($_POST['name'])){
  68. $project = Bugs::project($_POST['name'],$_POST['description']);
  69. $res->json(array(
  70. 'name'=>$project->name
  71. ));
  72. Bugs::activity('project.create',$project);
  73. }else{
  74. $res->json(array(
  75. 'error'=>"A project with the name {$_POST['name']} already exists."
  76. ));
  77. }
  78. }else{
  79. $res->json(array(
  80. 'error'=>'No name specified'
  81. ));
  82. }
  83. }
  84. ));
  85. ?>