/** * get post data and organise by ticket * @return array post data in format $postsArray[ticket][field] = value */ function organisePosts() { $authenticationAndSecurity = new authenticationAndSecurity(); $postsArray = []; $posts = $authenticationAndSecurity->getAllPosts(); foreach ($posts as $inputName => $Val) { $inputValue = $authenticationAndSecurity->getPost($inputName); if ($inputName != 'test' && $inputName != 'user' && $inputName != 'password') { $keyArray = []; $explode = explode('-', $inputName); // split all parts if (count($explode) > 0) { $keyArray[1] = array_pop($explode); // removes the last element, and returns it if (count($explode) > 0) { $keyArray[0] = implode('-', $explode); // glue the remaining pieces back together $keyArray[0] = str_replace('¬', ' ', $keyArray[0]); } } $postsArray[$keyArray[1]][$keyArray[0]] = $inputValue; } } // remove hidden inputs form unset($postsArray[0]); return $postsArray; }
/** * format & send timing data to Youtrack * @return array */ function submit() { $authenticationAndSecurity = new authenticationAndSecurity(); $this->checkForCookie(); $posts = $authenticationAndSecurity->getAllPosts(); $ticketId = $posts['project'] . '-' . $posts['ticketnumber']; $organisedPosts = $this->organisePosts($posts); foreach ($organisedPosts as $key => $timeRow) { $xml = $this->createXml($timeRow); $organisedPosts[$key]['success'] = $this->postData($xml, $ticketId); } return $organisedPosts; }