Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 29 additions & 2 deletions Controller/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@ public function add($foreign_model = null, $foreign_id = null)
$this->Comments->forgetInfo();
}

$this->redirect($this->request->referer().'#comment-'.$this->Comment->id);
}
$this->redirect($this->request->referer() . '#comment-' . $this->Comment->id);
}

/**
* delete method
*
* @throws NotFoundException
* @throws MethodNotAllowedException
* @param string $id
* @return void
*/
public function delete($id = null) {
$redirect = $this->request->referer() . '#comment';
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->Comment->id = $id;
if (!$this->Comment->exists()) {
throw new NotFoundException(__d('feedback','Invalid request.'));
}
if ($this->Comment->delete()) {
$this->Flash->success(__d('feedback','Record deleted.'));
$this->redirect($redirect );
}
$this->Flash->error(__d('feedback','Failed, record was not deleted.'));

$this->redirect($redirect);
}

}
Empty file added Locale/eng/LC_MESSAGES/empty
Empty file.
36 changes: 36 additions & 0 deletions Locale/eng/LC_MESSAGES/feedback.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# LANGUAGE translation of pHkondo Application
# Copyright pHAlkaline <contact@phalkaline.eu>
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: pHKondo V1.1\n"
"POT-Creation-Date: 2015-03-01 22:26+0000\n"
"PO-Revision-Date: 2015-04-08 17:43+0100\n"
"Last-Translator: pHAlkaline <contact@phalkaline.eu>\n"
"Language-Team: English <contact@phalkaline.eu>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.5.4\n"
"Language: pt\n"
"X-Poedit-SourceCharset: UTF-8\n"

msgid "Failed, record was not deleted."
msgstr "Não foi possível remover."

msgid "Record deleted."
msgstr "Registo removido."

msgid "Invalid request."
msgstr "Pedido inválido."

msgid "You cannot vote more than once!"
msgstr "Não pode votar mais de uma vez!"

msgid "There was an error while saving your vote."
msgstr "Não foi possível registar o seu voto."

msgid "Thanks for voting!"
msgstr "Obrigado pelo seu voto!"
Empty file added Locale/por/LC_MESSAGES/empty
Empty file.
36 changes: 36 additions & 0 deletions Locale/por/LC_MESSAGES/feedback.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# LANGUAGE translation of pHkondo Application
# Copyright pHAlkaline <contact@phalkaline.eu>
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: pHKondo V1.1\n"
"POT-Creation-Date: 2015-03-01 22:26+0000\n"
"PO-Revision-Date: 2015-04-08 17:43+0100\n"
"Last-Translator: pHAlkaline <contact@phalkaline.eu>\n"
"Language-Team: English <contact@phalkaline.eu>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.5.4\n"
"Language: en\n"
"X-Poedit-SourceCharset: UTF-8\n"

msgid "Failed, record was not deleted."
msgstr "Não foi possível remover."

msgid "Record deleted."
msgstr "Registo removido."

msgid "Invalid request."
msgstr "Pedido inválido."

msgid "You cannot vote more than once!"
msgstr "Não pode votar mais de uma vez!"

msgid "There was an error while saving your vote."
msgstr "Não foi possível registar o seu voto."

msgid "Thanks for voting!"
msgstr "Obrigado pelo seu voto!"
20 changes: 10 additions & 10 deletions Model/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ class Comment extends FeedbackAppModel
(
'foreign_model' => array
(
'notempty' => array
'' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
'allowEmpty' => false,
'required' => true,
),
),
'foreign_id' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
'allowEmpty' => false,
'required' => true,
),
),
'author_name' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
'message' => 'Name cannot be empty',
'allowEmpty' => false,
//'required' => false,
Expand All @@ -61,9 +61,9 @@ class Comment extends FeedbackAppModel
),
'author_email' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
'message' => 'E-mail address cannot be empty',
'allowEmpty' => false,
//'required' => false,
Expand All @@ -87,9 +87,9 @@ class Comment extends FeedbackAppModel
),
'content' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
'message' => 'Comment cannot be empty',
'allowEmpty' => false,
//'required' => false,
Expand Down
12 changes: 6 additions & 6 deletions Model/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class Rating extends FeedbackAppModel
(
'foreign_model' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
//'message' => 'Your custom message here',
'allowEmpty' => false,
'required' => false,
Expand All @@ -38,9 +38,9 @@ class Rating extends FeedbackAppModel
),
'foreign_id' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
//'message' => 'Your custom message here',
'allowEmpty' => false,
'required' => false,
Expand All @@ -50,9 +50,9 @@ class Rating extends FeedbackAppModel
),
'rating' => array
(
'notempty' => array
'notBlank' => array
(
'rule' => array('notempty'),
'rule' => array('notBlank'),
//'message' => 'Your custom message here',
'allowEmpty' => false,
'required' => true,
Expand Down
33 changes: 17 additions & 16 deletions View/Helper/CommentsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ class CommentsHelper extends AppHelper
{
public $helpers = array('Html', 'Form', 'Time', 'Goodies.Gravatar');

private $_defaultOptions = array
(
public $settings = array(
'model' => null,
'showForm' => true,
'elementIndex' => 'Feedback.comment_index',
'elementForm' => 'Feedback.comment_add',
);

function __construct(View $view, $settings = array())
function __construct(View $view, $settings = null)
{
parent::__construct($view, $settings);

if (!empty($this->request->params['models']))
if ($this->settings['model']==null && !empty($this->request->params['models']))
{
$this->_defaultOptions['model'] = key($this->request->params['models']);
$this->settings['model'] = key($this->request->params['models']);
}
}

Expand All @@ -48,9 +48,9 @@ function __construct(View $view, $settings = array())
*/
function display_for(array $data, array $options = array())
{
$options = array_merge($this->_defaultOptions, $options);

if (empty($options['model']))
$this->settings = array_merge($this->settings, $options);
if (empty($this->settings['model']))
{
throw new CakeException(__('Missing model for %s::%s() call', __CLASS__, __FUNCTION__));
}
Expand All @@ -59,28 +59,29 @@ function display_for(array $data, array $options = array())

if (isset($data['Comment']) && !empty($data['Comment']))
{
$output .= $this->_View->element('Feedback.comment_index', array('comments' => $data['Comment']));
$output .= $this->_View->element($this->settings['elementIndex'], array('comments' => $data['Comment']));
}

if ($options['showForm'])
if ($this->settings['showForm'])
{
App::uses($options['model'], 'Model');
$Model = ClassRegistry::init($options['model']);
App::uses($this->settings['model'], 'Model');
$Model = ClassRegistry::init($this->settings['model']);

if (empty($Model))
{
throw new CakeException(__('Missing model for %s::%s() call', __CLASS__, __FUNCTION__));
}

$output .= $this->form($options['model'], $data[$Model->alias][$Model->primaryKey]);
$output .= $this->form($this->settings['model'], $data[$Model->alias][$Model->primaryKey]);
}

return $output;
}

public function form($foreign_model, $foreign_id)
{
App::uses($foreign_model, 'Model');

App::uses($foreign_model, 'Model');
$Model = ClassRegistry::init($foreign_model);

if (empty($Model))
Expand All @@ -94,6 +95,6 @@ public function form($foreign_model, $foreign_id)
}

$options = compact('foreign_model', 'foreign_id');
return $this->_View->element('Feedback.comment_add', $options);
return $this->_View->element($this->settings['elementForm'], $options);
}
}