@@ -48,17 +48,19 @@ public function __construct($config = array())
4848 */
4949 protected function populateState ($ ordering = null , $ direction = null )
5050 {
51- // Initialise variables.
52- $ app = JFactory::getApplication ('administrator ' );
53-
51+ // Load the filter state.
52+ $ search = $ this ->getUserStateFromRequest ($ this ->context .'.filter.search ' , 'filter_search ' );
53+ $ this ->setState ('filter.search ' , $ search );
54+
5455 // Load the parameters.
5556 $ params = JComponentHelper::getParams ('com_patchtester ' );
56-
57+
5758 $ this ->setState ('params ' , $ params );
5859 $ this ->setState ('github_user ' , $ params ->get ('org ' , 'joomla ' ));
5960 $ this ->setState ('github_repo ' , $ params ->get ('repo ' , 'joomla-cms ' ));
61+
6062 // List state information.
61- parent ::populateState ('title ' , 'asc ' );
63+ parent ::populateState ('number ' , 'desc ' );
6264 }
6365
6466 /**
@@ -83,7 +85,7 @@ public function getAppliedPatches()
8385 $ query ->select ('* ' );
8486 $ query ->from ('#__tests ' );
8587 $ query ->where ('applied = 1 ' );
86-
88+
8789 $ this ->_db ->setQuery ($ query );
8890 $ tests = $ this ->_db ->loadObjectList ('pull_id ' );
8991 return $ tests ;
@@ -97,12 +99,20 @@ public function getItems()
9799 return array ();
98100 }
99101
102+ $ this ->ordering = $ this ->getState ('list.ordering ' , 'title ' );
103+ $ this ->orderDir = $ this ->getState ('list.direction ' , 'asc ' );
104+ $ search = $ this ->getState ('filter.search ' );
105+
100106 $ github = new JGithub ();
101107 $ pulls = $ github ->pulls ->getAll ($ this ->getState ('github_user ' ), $ this ->getState ('github_repo ' ));
102108 usort ($ pulls , array ($ this , 'sortItems ' ));
103109
104- foreach ($ pulls AS &$ pull )
110+ foreach ($ pulls AS $ i => &$ pull )
105111 {
112+ if ($ search && false === strpos ($ pull ->title , $ search )) {
113+ unset($ pulls [$ i ]);
114+ continue ;
115+ }
106116 $ matches = array ();
107117 preg_match ('#\[\#([0-9]+)\]# ' , $ pull ->title , $ matches );
108118 $ pull ->joomlacode_issue = isset ($ matches [1 ]) ? $ matches [1 ] : 0 ;
@@ -112,6 +122,14 @@ public function getItems()
112122
113123 public function sortItems ($ a , $ b )
114124 {
115- return strcasecmp ($ a ->title , $ b ->title );
125+ switch ($ this ->ordering )
126+ {
127+ case 'title ' :
128+ return ($ this ->orderDir == 'asc ' ) ? strcasecmp ($ a ->title , $ b ->title ) : strcasecmp ($ b ->title , $ a ->title );
129+
130+ case 'number ' :
131+ default :
132+ return ($ this ->orderDir == 'asc ' ) ? $ b ->number < $ a ->number : $ b ->number > $ a ->number ;
133+ }
116134 }
117135}
0 commit comments