@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | $factory = $app['controllers_factory']; |
| 22 | 22 | # il mount point e' precedente e non serve prima |
| 23 | 23 | $this->app['db']; |
| 24 | - R::fancyDebug( TRUE ); |
|
| 24 | + R::fancyDebug(TRUE); |
|
| 25 | 25 | $factory->get('/', array($this, 'getWorkspaceList')); |
| 26 | 26 | $factory->post('/', array($this, 'createWorkspace')); |
| 27 | 27 | $factory->get('/{id}', array($this, 'getWorkspace')); |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | $factory->post('/{id}/part', array($this, 'postPart')); |
| 30 | 30 | return $factory; |
| 31 | 31 | } |
| 32 | - public function getSessionId(){ |
|
| 33 | - $user_id=$this->app['session']->get('user')['id']; |
|
| 32 | + public function getSessionId() { |
|
| 33 | + $user_id = $this->app['session']->get('user')['id']; |
|
| 34 | 34 | return $user_id; |
| 35 | 35 | } |
| 36 | 36 | public function getWorkspaceList(Request $request) |
| 37 | 37 | { |
| 38 | - $user_id=$this->getSessionId(); |
|
| 39 | - $workspaces = R::getAll("SELECT ws.id, |
|
| 38 | + $user_id = $this->getSessionId(); |
|
| 39 | + $workspaces = R::getAll("SELECT ws.id, |
|
| 40 | 40 | ws.title, |
| 41 | 41 | ws.description, |
| 42 | 42 | ws.environment, |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | LEFT JOIN workspace AS ws |
| 46 | 46 | ON uws.workspace = ws.id |
| 47 | 47 | WHERE uws.user = ?",[$user_id]); |
| 48 | - $list=[]; |
|
| 49 | - foreach($workspaces as $ws){ |
|
| 50 | - array_push($list,[ |
|
| 48 | + $list = []; |
|
| 49 | + foreach ($workspaces as $ws) { |
|
| 50 | + array_push($list, [ |
|
| 51 | 51 | "id"=>$ws['id'], |
| 52 | 52 | "title"=>$ws['title'], |
| 53 | 53 | "description"=>$ws['description'], |
| 54 | 54 | "environment"=>$ws['environment'], |
| 55 | - "point"=>0,//TODO fare una view con i point già calcolati per il ws |
|
| 55 | + "point"=>0, //TODO fare una view con i point già calcolati per il ws |
|
| 56 | 56 | "completed"=>$ws['completed'], |
| 57 | 57 | ]); |
| 58 | 58 | } |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | public function createWorkspace(Request $request) |
| 64 | 64 | { |
| 65 | - $user_id=$this->getSessionId(); |
|
| 66 | - $counter=0; |
|
| 65 | + $user_id = $this->getSessionId(); |
|
| 66 | + $counter = 0; |
|
| 67 | 67 | $data = json_decode($request->getContent(), true); |
| 68 | 68 | //TODO validate json_decode |
| 69 | - $title=$data['title']; |
|
| 70 | - $description=$data['description']; |
|
| 71 | - $environment=$data['environment']; |
|
| 69 | + $title = $data['title']; |
|
| 70 | + $description = $data['description']; |
|
| 71 | + $environment = $data['environment']; |
|
| 72 | 72 | |
| 73 | 73 | $patrol = $data['team']['patrol']; |
| 74 | 74 | $unit = $data['team']['unit']; |
@@ -76,46 +76,46 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | //save the workspace get id |
| 78 | 78 | $ws = R::dispense("workspace"); |
| 79 | - $ws->title=$title; |
|
| 80 | - $ws->description=$description; |
|
| 81 | - $ws->environment=$environment; |
|
| 82 | - $ws->completed=false; |
|
| 83 | - $ws->inserttime=date('Y-m-d H:i:s'); |
|
| 84 | - $ws->lastupdatetime=date('Y-m-d H:i:s'); |
|
| 79 | + $ws->title = $title; |
|
| 80 | + $ws->description = $description; |
|
| 81 | + $ws->environment = $environment; |
|
| 82 | + $ws->completed = false; |
|
| 83 | + $ws->inserttime = date('Y-m-d H:i:s'); |
|
| 84 | + $ws->lastupdatetime = date('Y-m-d H:i:s'); |
|
| 85 | 85 | $id = R::store($ws); |
| 86 | 86 | |
| 87 | 87 | //save the team |
| 88 | 88 | $team = R::dispense("team"); |
| 89 | - $team->workspace=$id; |
|
| 90 | - $team->patrol=$patrol; |
|
| 91 | - $team->unit=$unit; |
|
| 92 | - $team->group=$group; |
|
| 89 | + $team->workspace = $id; |
|
| 90 | + $team->patrol = $patrol; |
|
| 91 | + $team->unit = $unit; |
|
| 92 | + $team->group = $group; |
|
| 93 | 93 | $team_id = R::store($team); |
| 94 | 94 | |
| 95 | 95 | //create a phantom part to add badge |
| 96 | 96 | $part = R::dispense("part"); |
| 97 | - $part->workspace=$id; |
|
| 98 | - $part->user=$user_id; |
|
| 99 | - $part->inserttime=date('Y-m-d H:i:s'); |
|
| 100 | - $part->lastupdatetime=date('Y-m-d H:i:s'); |
|
| 101 | - $part->totalpoint=0; |
|
| 97 | + $part->workspace = $id; |
|
| 98 | + $part->user = $user_id; |
|
| 99 | + $part->inserttime = date('Y-m-d H:i:s'); |
|
| 100 | + $part->lastupdatetime = date('Y-m-d H:i:s'); |
|
| 101 | + $part->totalpoint = 0; |
|
| 102 | 102 | $part_id = R::store($part); |
| 103 | 103 | |
| 104 | 104 | //add the badge to the project |
| 105 | - foreach($data['badges'] as $badge_id){ |
|
| 105 | + foreach ($data['badges'] as $badge_id) { |
|
| 106 | 106 | //TODO insert those badge as first hidden post |
| 107 | 107 | $pb = R::dispense("partbadge"); |
| 108 | - $pb->badge=$badge_id; |
|
| 109 | - $pb->part=$part_id; |
|
| 110 | - $pb->inserttime=date('Y-m-d H:i:s'); |
|
| 108 | + $pb->badge = $badge_id; |
|
| 109 | + $pb->part = $part_id; |
|
| 110 | + $pb->inserttime = date('Y-m-d H:i:s'); |
|
| 111 | 111 | $tmp = R::store($pb); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | //add the workspace created to the user as owner |
| 115 | 115 | $usw = R::dispense("userworkspace"); |
| 116 | - $usw->user=$user_id; |
|
| 117 | - $usw->workspace=$id; |
|
| 118 | - $usw->inserttime=date('Y-m-d H:i:s'); |
|
| 116 | + $usw->user = $user_id; |
|
| 117 | + $usw->workspace = $id; |
|
| 118 | + $usw->inserttime = date('Y-m-d H:i:s'); |
|
| 119 | 119 | R::store($usw); |
| 120 | 120 | |
| 121 | 121 | $res = ["id" => $id]; |
@@ -123,22 +123,22 @@ discard block |
||
| 123 | 123 | return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function getWorkspace($id,Request $request){ |
|
| 127 | - $user_id=$this->getSessionId(); |
|
| 126 | + public function getWorkspace($id, Request $request) { |
|
| 127 | + $user_id = $this->getSessionId(); |
|
| 128 | 128 | //TODO controllare che l'utente abbia diritto a vedere questo workspace |
| 129 | 129 | |
| 130 | - $workspace = R::findOne("workspace","id = ?",[$id]); |
|
| 131 | - $part = R::findAll("part","workspace = ?",[$id]); |
|
| 130 | + $workspace = R::findOne("workspace", "id = ?", [$id]); |
|
| 131 | + $part = R::findAll("part", "workspace = ?", [$id]); |
|
| 132 | 132 | |
| 133 | - $badges = R::findAll("workspacebadge","workspace = ?",[$id]); |
|
| 133 | + $badges = R::findAll("workspacebadge", "workspace = ?", [$id]); |
|
| 134 | 134 | |
| 135 | - $l_part=[]; |
|
| 136 | - foreach($part as $p){ |
|
| 137 | - array_push($l_part,intval($p['id'])); |
|
| 135 | + $l_part = []; |
|
| 136 | + foreach ($part as $p) { |
|
| 137 | + array_push($l_part, intval($p['id'])); |
|
| 138 | 138 | } |
| 139 | - $l_badges=[]; |
|
| 140 | - foreach($badges as $b){ |
|
| 141 | - array_push($l_badges,intval($b['badge'])); |
|
| 139 | + $l_badges = []; |
|
| 140 | + foreach ($badges as $b) { |
|
| 141 | + array_push($l_badges, intval($b['badge'])); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $res = [ |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | return JsonResponse::create($res, 201, $headers)->setSharedMaxAge(300); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - public function share($id,Request $request){ |
|
| 159 | - $generatedKey = hash("sha256",(mt_rand(10000,99999).time().$id)); |
|
| 158 | + public function share($id, Request $request) { |
|
| 159 | + $generatedKey = hash("sha256", (mt_rand(10000, 99999).time().$id)); |
|
| 160 | 160 | //TODO verificare documentazione realtiva sulla reale entropia generata da questo sistema |
| 161 | - $user_id=$this->getSessionId(); |
|
| 161 | + $user_id = $this->getSessionId(); |
|
| 162 | 162 | $share = R::dispense("share"); |
| 163 | - $share->user=$user_id; |
|
| 164 | - $share->workspace=$id; |
|
| 165 | - $share->key=$generatedKey; |
|
| 166 | - $share->inserttime=date('Y-m-d H:i:s'); |
|
| 163 | + $share->user = $user_id; |
|
| 164 | + $share->workspace = $id; |
|
| 165 | + $share->key = $generatedKey; |
|
| 166 | + $share->inserttime = date('Y-m-d H:i:s'); |
|
| 167 | 167 | $share_id = R::store($share); |
| 168 | 168 | |
| 169 | 169 | $date = new \DateTime(); |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | return JsonResponse::create($res, 200, $headers)->setSharedMaxAge(300); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - public function postPart($id,Request $request){ |
|
| 183 | - $user_id=$this->getSessionId(); |
|
| 182 | + public function postPart($id, Request $request) { |
|
| 183 | + $user_id = $this->getSessionId(); |
|
| 184 | 184 | |
| 185 | 185 | $res = []; |
| 186 | 186 | $headers = []; |