Permalink
Browse files

Intermediate commit just to backup changes. This commit is untested

and may be unstable. For stable version use previous commit or wait
for next one.
  • Loading branch information...
1 parent 3392065 commit cd17cdc88aa0fc06df0828a5b5a905a1d9aa19d7 @snytkine snytkine committed Mar 14, 2011
Showing with 5,521 additions and 209 deletions.
  1. +3 −1 acl.ini
  2. +125 −4 lib/Lampcms/Answer.php
  3. +3 −0 lib/Lampcms/AnswerParser.php
  4. +506 −0 lib/Lampcms/CommentParser.php
  5. +1 −1 lib/Lampcms/Controllers/Accept.php
  6. +234 −0 lib/Lampcms/Controllers/Addcomment.php
  7. +1 −1 lib/Lampcms/Controllers/Delete.php
  8. +141 −0 lib/Lampcms/Controllers/Deletecomment.php
  9. +117 −0 lib/Lampcms/Controllers/Editcomment.php
  10. +103 −0 lib/Lampcms/Controllers/Flagcomment.php
  11. +15 −9 lib/Lampcms/Controllers/Flagger.php
  12. +1 −1 lib/Lampcms/Controllers/Logintwitter.php
  13. +1 −1 lib/Lampcms/Controllers/Stick.php
  14. +78 −0 lib/Lampcms/Controllers/Unstick.php
  15. +7 −4 lib/Lampcms/Controllers/Viewquestion.php
  16. +7 −11 lib/Lampcms/H2t.php
  17. +104 −45 lib/Lampcms/Interfaces/All.php
  18. +2,925 −0 lib/Lampcms/Markdown.php
  19. +21 −0 lib/Lampcms/Modules/Observers/FloodCheck.php
  20. +126 −6 lib/Lampcms/Question.php
  21. +2 −0 lib/Lampcms/ReputationAcl.php
  22. +2 −5 lib/Lampcms/String.php
  23. +11 −1 lib/Lampcms/SubmittedAnswer.php
  24. +403 −0 lib/Lampcms/SubmittedCommentWWW.php
  25. +34 −24 lib/Lampcms/Utf8String.php
  26. +3 −0 lib/Lampcms/WebPage.php
  27. +13 −7 plaintext.xsl
  28. BIN www/images/bg.png
  29. BIN www/images/sprite.png
  30. +257 −19 www/js/qa.js
  31. +136 −65 www/style/1/www/main.css
  32. +16 −2 www/style/1/www/tplAnswer.php
  33. +10 −0 www/style/1/www/tplComdiv.php
  34. +90 −0 www/style/1/www/tplComment.php
  35. +5 −0 www/style/1/www/tplComments.php
  36. +5 −1 www/style/1/www/tplMain.php
  37. +15 −1 www/style/1/www/tplQuestion.php
View
@@ -48,7 +48,7 @@ add_blog_post = A
post_by_email = A
ask = A
answer = A
-comment = A
+comment = D
vote = A
accept = A
@@ -68,7 +68,9 @@ edit_question = A
edit_answer = A
delete_question = A
delete_answer = A
+delete_comment = A
retag = A
+comment = A
ban_user = A
unban_user = A
close_question = A
View
@@ -61,7 +61,7 @@
* @author Dmitri Snytkine
*
*/
-class Answer extends MongoDoc implements Interfaces\LampcmsResource, Interfaces\UpDownRatable
+class Answer extends MongoDoc implements Interfaces\LampcmsResource, Interfaces\UpDownRatable, Interfaces\CommentedResource
{
public function __construct(Registry $oRegistry, array $a = array()){
@@ -126,8 +126,8 @@ public function setDeleted(User $user, $reason = null){
'hts' => date('F j, Y g:i a T')
)
);
-
- $this->updateLastModified();
+
+ $this->touch();
}
return $this;
@@ -159,7 +159,7 @@ public function setEdited(User $user, $reason = ''){
$this->offsetSet('a_edited', $aEdited);
- $this->updateLastModified();
+ $this->touch();
return $this;
}
@@ -196,6 +196,18 @@ public function updateLastModified(){
return $this;
}
+ /**
+ * Updates last modified timestamp
+ * A replacement for updateLastModified() method
+ *
+ * @return object $this
+ */
+ public function touch(){
+ $this->offsetSet('i_lm_ts', time());
+
+ return $this;
+ }
+
/**
* (non-PHPdoc)
@@ -291,4 +303,113 @@ public function getUrl(){
return $this->oRegistry->Ini->SITE_URL.'/q'.$this->offsetGet('i_qid').'/#ans'.$this->offsetGet('_id');
}
+
+ public function addComment(CommentParser $oComment){
+ $aKeys = array('_id', 'i_uid', 'i_prnt', 'username', 'b_owner', 'b', 't', 'ts');
+
+ $aComments = $this->getComments();
+ d('aComments: '.print_r($aComments, 1));
+ /**
+ * Only keep the keys that we need
+ * get rid of keys like hash, i_res
+ * because we don't need them here
+ */
+ $aComment = $oComment->getArrayCopy();
+ $aComment = array_intersect_key($aComment, array_flip($aKeys));
+
+ $aComments[] = $aComment;
+
+ $this->offsetSet('comments', $aComments);
+ $this->increaseCommentsCount();
+
+ return $this;
+
+ }
+
+
+ public function getCommentsCount(){
+ $aComments = $this->getComments();
+
+ return count($aComments);
+ }
+
+
+ public function increaseCommentsCount(){
+ /**
+ * Now increase comments count
+ */
+ $commentsCount = $this->getCommentsCount();
+ d('$commentsCount '.$commentsCount);
+
+ $this->offsetSet('i_comments', ($commentsCount + 1) );
+
+ return $this;
+ }
+
+
+ /**
+ * Remove one comment from array of comments
+ * then re-save the new array of comments
+ * the numerical keys of array will be reset
+ * Also i_comments value will be updated to the
+ * new count of comments
+ *
+ * (non-PHPdoc)
+ * @see Lampcms\Interfaces.CommentedResource::deleteComment()
+ */
+ public function deleteComment($id){
+
+ if(!$this->checkOffset('comments')){
+ e('This question does not have any comments');
+
+ return $this;
+ }
+
+ $aComments = $this->offsetGet('comments');
+
+ for($i = 0; $i<count($aComments); $i+=1){
+ if($aComments[$i]['_id'] == $id){
+ d('unsetting comment: '.$i);
+ array_splice($aComments, $i, 1);
+ break;
+ }
+ }
+
+ $newCount = count($aComments);
+ if( 0 === $newCount){
+ $this->offsetUnset('comments');
+ } else {
+ $this->offsetSet('comments', $aComments);
+ }
+
+ $this->offsetSet('i_comments', $newCount );
+
+ return $this;
+ }
+
+
+ /**
+ * Getter for 'comments' element
+ * @return array of comments or empty array if
+ * 'comments' element not present in the object
+ *
+ */
+ public function getComments(){
+ return $this->getFallback('comments', array());
+ }
+
+
+ /**
+ * Get uid of user who asked the question
+ * for which this is the answer
+ * This is useful during adding a comment
+ * to an asnwer where we need to know wheather of not
+ * the comment comes from the original asker.
+ *
+ *
+ */
+ public function getQuestionOwnerId(){
+ return $this->offsetGet('i_quid');
+ }
+
}
@@ -199,6 +199,7 @@ protected function makeAnswer(){
'_id' => $this->oRegistry->Resource->create('ANSWER'),
'i_qid' => $qid,
'i_uid' => $uid,
+ 'i_quid' => $this->oQuestion->getOwnerId(),
'title' => $this->oQuestion->title,
'hash' => $hash,
'uname' => $username,
@@ -371,4 +372,6 @@ public function getQuestion(){
return $this->oQuestion;
}
+
}
+
Oops, something went wrong.

0 comments on commit cd17cdc

Please sign in to comment.