/** * Prompts the user for a status option, and returns the title of the * selected one. * * @param RemoteApi $client The connection resource * @param array $auth Array of authentication information (email, password) * @param integer $prj_id The project ID * @return string The selected status title */ public function promptStatusSelection($client, $auth, $prj_id) { $list = $client->getClosedAbbreviationAssocList($auth[0], $auth[1], (int) $prj_id); if (count($list) > 1) { // need to ask which status this person wants to use $prompt = "Which status do you want to use in this action?\n"; foreach ($list as $key => $value) { $prompt .= sprintf(" [%s] => %s\n", $key, $value); } $prompt .= 'Please enter the status'; $status = CLI_Misc::prompt($prompt, false); $lowercase_keys = array_map(function ($s) { return strtolower($s); }, array_keys($list)); $lowercase_values = array_map(function ($s) { return strtolower($s); }, array_values($list)); if (!in_array(strtolower($status), $lowercase_keys) && !in_array(strtolower($status), $lowercase_values)) { self::quit("Entered status doesn't match any in the list available to you"); } else { if (in_array(strtolower($status), $lowercase_keys)) { $status_title = $list[strtoupper($status)]; } else { $status_title = $status; } } } else { $t = array_values($list); $status_title = $t[0]; } return $status_title; }