Skip to content

Commit 80639d4

Browse files
committed
Refactor get status name code
1 parent 70a1255 commit 80639d4

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

controller/list_controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function ideas_list($sort)
5656
}
5757

5858
// Set the name for displaying in the template
59-
$status_name = 'LIST_' . strtoupper($status > 0 ? array_search($status, ext::$statuses) : $sort);
59+
$status_name = 'LIST_' . ($status > 0 ? ext::status_name($status) : strtoupper($sort));
6060
$status_name = $this->language->is_set($status_name) ? $this->language->lang($status_name) : '';
6161

6262
// For special case where we want to request ALL ideas,

event/listener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function show_idea($event)
198198
'IDEA_VOTES_DOWN' => $idea['idea_votes_down'],
199199
'IDEA_POINTS' => $points,
200200
'IDEA_STATUS_ID' => $idea['idea_status'],
201-
'IDEA_STATUS_NAME' => $this->idea->get_status_from_id($idea['idea_status']),
201+
'IDEA_STATUS_NAME' => $this->language->lang(ext::status_name($idea['idea_status'])),
202202

203203
'IDEA_DUPLICATE' => $idea['duplicate_id'] ? $this->idea->get_title($idea['duplicate_id']) : '',
204204
'IDEA_RFC' => $idea['rfc_link'],

ext.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ class ext extends \phpbb\extension\base
4040
'INVALID' => 5,
4141
);
4242

43+
/**
44+
* Return the status name from the status ID.
45+
*
46+
* @param int $id ID of the status.
47+
*
48+
* @return string The status name.
49+
* @static
50+
* @access public
51+
*/
52+
public static function status_name($id)
53+
{
54+
return array_flip(self::$statuses)[$id];
55+
}
56+
4357
/**
4458
* Check whether or not the extension can be enabled.
4559
*

factory/base.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,6 @@ public function __construct(auth $auth, config $config, driver_interface $db, la
7777
$this->table_topics = $table_topics;
7878
}
7979

80-
/**
81-
* Returns the status name from the status ID specified.
82-
*
83-
* @param int $id ID of the status.
84-
*
85-
* @return string|bool The status name if it exists, false otherwise.
86-
*/
87-
public function get_status_from_id($id)
88-
{
89-
return $this->language->lang(array_search($id, ext::$statuses));
90-
}
91-
9280
/**
9381
* Helper method for inserting new idea data
9482
*

0 commit comments

Comments
 (0)