diff --git a/Controller/CommentsController.php b/Controller/CommentsController.php index b91c821..49c048b 100644 --- a/Controller/CommentsController.php +++ b/Controller/CommentsController.php @@ -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); + } + } diff --git a/Locale/eng/LC_MESSAGES/empty b/Locale/eng/LC_MESSAGES/empty new file mode 100644 index 0000000..e69de29 diff --git a/Locale/eng/LC_MESSAGES/feedback.po b/Locale/eng/LC_MESSAGES/feedback.po new file mode 100644 index 0000000..62abbc3 --- /dev/null +++ b/Locale/eng/LC_MESSAGES/feedback.po @@ -0,0 +1,36 @@ +# LANGUAGE translation of pHkondo Application +# Copyright pHAlkaline +# +#, 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 \n" +"Language-Team: English \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!" \ No newline at end of file diff --git a/Locale/por/LC_MESSAGES/empty b/Locale/por/LC_MESSAGES/empty new file mode 100644 index 0000000..e69de29 diff --git a/Locale/por/LC_MESSAGES/feedback.po b/Locale/por/LC_MESSAGES/feedback.po new file mode 100644 index 0000000..28a728d --- /dev/null +++ b/Locale/por/LC_MESSAGES/feedback.po @@ -0,0 +1,36 @@ +# LANGUAGE translation of pHkondo Application +# Copyright pHAlkaline +# +#, 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 \n" +"Language-Team: English \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!" \ No newline at end of file diff --git a/Model/Comment.php b/Model/Comment.php index 135b38b..ed7f595 100644 --- a/Model/Comment.php +++ b/Model/Comment.php @@ -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, @@ -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, @@ -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, diff --git a/Model/Rating.php b/Model/Rating.php index 118df20..e2d128f 100644 --- a/Model/Rating.php +++ b/Model/Rating.php @@ -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, @@ -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, @@ -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, diff --git a/View/Helper/CommentsHelper.php b/View/Helper/CommentsHelper.php index 1d6b9ab..d9cc86e 100644 --- a/View/Helper/CommentsHelper.php +++ b/View/Helper/CommentsHelper.php @@ -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']); } } @@ -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__)); } @@ -59,20 +59,20 @@ 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; @@ -80,7 +80,8 @@ function display_for(array $data, array $options = array()) 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)) @@ -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); } } \ No newline at end of file