* @copyright 2011 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
*/
-
+ //functions to sort replies
class NoticeTree extends NoticeList
{
function show()
}
try {
- $this->showNoticePlus($this->notice);
+ $this->showNoticePlus($this->newListItem($this->notice));
} catch (Exception $e) {
// we log exceptions and continue
+ print "ERROR!" . $e->getMessage();
common_log(LOG_ERR, $e->getMessage());
continue;
}
return $cnt;
}
+ function _cmpDate($a, $b) { return strcmp($a->notice->modified, $b->notice->modified); }
+ function _cmpFav($a, $b) { return (int)$a->faves < (int)$b->faves; }
- function showNoticePlus($notice)
+ function showNoticePlus($item)
{
$replies = new Notice();
- $replies->reply_to = $notice->id;
+ $replies->reply_to = $item->notice->id;
// We take responsibility for doing the li
- $this->out->elementStart('li', array('class' => 'hentry notice',
- 'id' => 'notice-' . $id));
+ $this->out->elementStart('li', array('class' => 'hentry notice',
+ 'id' => 'notice-' . $item->notice->id));
- $item = $this->newListItem($notice);
$item->show();
if ($replies->find()) {
$this->out->elementStart('ol', array('class' => 'notices'));
+ $replieslist = array();
while ($replies->fetch()) {
- $this->showNoticePlus($replies);
+ $replieslist[] = $this->newListItem(clone($replies));
+ }
+
+ //Sorting based on url argument
+ if($_GET['sort'] == 'faves')
+ usort($replieslist, array($this, '_cmpFav'));
+ else
+ usort($replieslist, array($this, '_cmpDate'));
+
+
+ foreach($replieslist as $reply) {
+ $this->showNoticePlus($reply);
}
$this->out->elementEnd('ol');
class NoticeTreeItem extends NoticeListItem
{
- function showStart()
- {
- return;
- }
-
- function showEnd()
+ function __construct($notice, $out=null)
{
+ parent::__construct($notice, $out);
//TODO: Rewrite this
//Showing number of favorites
$fave = new Fave();
while ($fave->fetch())
$cnt++;
}
- if ($cnt > 0) {
- $this->out->text(_m("Favorited by $cnt user"));
- if ($cnt > 1) $this->out->text("s"); //there has to be a better way to do this...
+ $this->faves = $cnt;
+ }
+
+ function showStart()
+ {
+ return;
+ }
+
+ function showEnd()
+ {
+ if ($this->faves > 0) {
+ $this->out->text(_m("Favorited by $this->faves user"));
+ if ($this->faves > 1) $this->out->text("s"); //there has to be a better way to do this...
}
//Show response form