@@ -18,6 +18,14 @@ class ProjectsRequestHandler extends \RecordsRequestHandler
1818 public static function handleRecordRequest (\ActiveRecord $ Project , $ action = false )
1919 {
2020 switch ($ action ? $ action : $ action = static ::shiftPath ()) {
21+ case 'add-role ' :
22+ return static ::handleAddRoleRequest ($ Project );
23+ case 'modify-role ' :
24+ return static ::handleModifyRoleRequest ($ Project );
25+ case 'remove-role ' :
26+ return static ::handleRemoveRoleRequest ($ Project );
27+ case 'add-application ' :
28+ return static ::handleAddRoleApplicationRequest ($ Project );
2129 case 'add-member ' :
2230 return static ::handleAddMemberRequest ($ Project );
2331 case 'remove-member ' :
@@ -84,6 +92,104 @@ public static function handleBrowseRequest($options = [], $conditions = [], $res
8492 return parent ::handleBrowseRequest ($ options , $ conditions , $ responseID , $ responseData );
8593 }
8694
95+ public static function handleAddRoleRequest (Project $ Project )
96+ {
97+ $ GLOBALS ['Session ' ]->requireAuthentication ();
98+
99+ $ Person = User::getByUsername ($ _POST ['username ' ]);
100+
101+ $ recordData = [
102+ 'ProjectID ' => $ Project ->ID ,
103+ 'PersonID ' => (!$ Person )?null :$ Person ->ID
104+ ];
105+
106+ $ ProjectRole = ProjectRole::create ($ recordData );
107+
108+ if (!empty ($ _POST ['role ' ])) {
109+ $ ProjectRole ->Role = $ _POST ['role ' ];
110+ }
111+
112+ if (!empty ($ _POST ['description ' ])) {
113+ $ ProjectRole ->Description = $ _POST ['description ' ];
114+ }
115+
116+ $ ProjectRole ->save ();
117+
118+ return static ::respond ('roleAdded ' , [
119+ 'data ' => $ ProjectRole ,
120+ 'Project ' => $ Project ,
121+ 'Member ' => $ Person
122+ ]);
123+ }
124+
125+ public static function handleModifyRoleRequest (Project $ Project )
126+ {
127+ $ GLOBALS ['Session ' ]->requireAuthentication ();
128+
129+ $ Person = User::getByUsername ($ _POST ['username ' ]);
130+
131+ $ recordData = [
132+ 'ProjectID ' => $ Project ->ID ,
133+ 'PersonID ' => (!$ Person )?null :$ Person ->ID
134+ ];
135+
136+ $ ProjectRole = ProjectRole::create ($ recordData );
137+
138+ if (!empty ($ _POST ['role ' ])) {
139+ $ ProjectRole ->Role = $ _POST ['role ' ];
140+ }
141+
142+ if (!empty ($ _POST ['description ' ])) {
143+ $ ProjectRole ->Description = $ _POST ['description ' ];
144+ }
145+
146+ $ ProjectRole ->save ();
147+
148+ return static ::respond ('roleModified ' , [
149+ 'data ' => $ ProjectRole ,
150+ 'Project ' => $ Project ,
151+ 'Member ' => $ Person
152+ ]);
153+ }
154+
155+ public static function handleAddRoleApplicationRequest (Project $ Project ){
156+ $ GLOBALS ['Session ' ]->requireAuthentication ();
157+
158+ }
159+
160+ public static function handleRemoveRoleRequest (Project $ Project )
161+ {
162+ $ GLOBALS ['Session ' ]->requireAuthentication ();
163+
164+ if (empty ($ _REQUEST ['role_id ' ])) {
165+ return static ::throwError (_ ('Parameter "role_id" required ' ));
166+ }
167+
168+ $ ProjectRole = ProjectRole::getByWhere ([
169+ 'ProjectID ' => $ Project ->ID ,
170+ 'ID ' => $ _REQUEST ['role_id ' ]
171+ ]);
172+
173+ if ($ _SERVER ['REQUEST_METHOD ' ] != 'POST ' ) {
174+ return static ::respond ('confirm ' , [
175+ 'question ' => sprintf (
176+ _ ('Are you sure you want to remove %s from %s? ' ),
177+ htmlspecialchars ($ Role ->Role ),
178+ htmlspecialchars ($ Project ->Title )
179+ )
180+ ]);
181+ }
182+
183+ if ($ ProjectRole ) {
184+ $ ProjectRole ->destroy ();
185+ }
186+
187+ return static ::respond ('roleRemoved ' , [
188+ 'data ' => $ ProjectRole ,
189+ 'Project ' => $ Project
190+ ]);
191+ }
192+
87193 public static function handleAddMemberRequest (Project $ Project )
88194 {
89195 $ GLOBALS ['Session ' ]->requireAuthentication ();
0 commit comments