Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Add comment sorting configuration #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions modules/comments/constant/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete one newline.

define("OLDEST_FIRST",0);
define("NEWEST_FIRST",1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define('COMMENTS_OLDEST_FIRST', 0);
define('COMMENTS_NEWEST_FIRST', 1);

Propagate change throughout.


?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete closing tag and extra newline.

41 changes: 41 additions & 0 deletions modules/comments/controllers/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be called AdminController.

/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/**
* Config controller for the comments module.
*/
class Comments_ConfigController extends Comments_AppController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Admin controller ... */`
class Comments_AdminController extends Comments_AppController

{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete newlines.

public $_models = array('Setting','User');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the user model being used?


public function indexAction()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Index action. */ (or a more meaningful comment)

{
$this->requireAdminPrivileges();
if($this->_request->isPost())
{
$this->view->commentOrder = $_POST['commentOrder'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Zend_Controller_Request_Http::getPost

MidasLoader::loadModel("Setting")->setConfig('commentOrder',$this->view->commentOrder,"comments");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->Setting->setConfig('commentOrder', $this->view->commentOrder, 'comments');

};


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete one newline.

session_start();
}
}
14 changes: 13 additions & 1 deletion modules/comments/models/pdo/ItemcommentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,20 @@ class Comments_ItemcommentModel extends Comments_ItemcommentModelBase
*/
public function getComments($item, $limit = 10, $offset = 0)
{
/*
* Change the order of the retrieval based upon the user setting. This changes the display
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One space between sentences.

* order of the comments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments.

*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete newlines.

* 'ASC' shows the oldest comment first, 'DESC' shows the newest first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first.

*/
if( MidasLoader::loadModel("Setting")->getValueByName("commentOrder","comments") == OLDEST_FIRST) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Setting'
'commentOrder', 'comments'
===

This would be a global setting for all users. Is that what you meant?

$commentSort = "ASC";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ASC'

}
else {
$commentSort = "DESC";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'DESC'

}
$sql = $this->database->select()->where('item_id = ?', $item->getKey())->limit($limit, $offset)->order(
'date ASC'
'date ' . $commentSort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'date'.$commentSort

);

$rowset = $this->database->fetchAll($sql);
Expand Down
40 changes: 40 additions & 0 deletions modules/comments/views/config/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

$this->declareVars('form', 'pageTitle');
$this->headTitle($this->escape($this->pageTitle));
?>

<div class="viewMain">
<h1><?php ?></h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix or delete.

<div>
<form class='genericform' id='configForm' method='POST' action=''>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Zend_Form. See the various AdminController for other modules.

<h3> Comment Module Configuration </h3>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<h3>Comment Module Configuration</h3>

<p>Currently sorting comments by <b><?php if( MidasLoader::loadModel("Setting")->getValueByName("commentOrder","comments") ==0) { echo "OLDEST";} else { echo "NEWEST";};?></b> first.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put logic in the controller. Also
'Setting'
'commentOrder', 'comments'
=== OLDEST_FIRST
'OLDEST'
'NEWEST'

<label for"'commentOrder'>Order comments by</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. Use Zend_Form.

<select name='commentOrder'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. Use Zend_Form.

<option value="<?php echo OLDEST_FIRST ?>">Oldest First</option>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. Use Zend_Form.

<option value="<?php echo NEWEST_FIRST ?>">Newest First</option>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. Use Zend_Form.

</form>
</div>
<div>
<input type='submit' value='Save Configuration'/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. Use Zend_Form.

</div>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indents should be multiples of four.