Tell me how to properly organize tree comments. Algorithm, what properties, methods, technologies. Generally I can not figure out how to make an answer to an existing comment. Please help send in the right direction in this matter.
Closed due to the fact that the issue is too general for the participants Alexey Shimansky , user194374, Alex , pavel , Denis Bubnov 14 Dec '16 at 11:04 .
Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See βHow to ask a good question?β For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .
1 answer
If it is very crude to depict this, then you can add to the class the property responsible for storing the ID of the comment that is answered with the current one. This is probably the most obvious solution.
class Comment { private $id; //ΠΠ΄Π΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΎΡ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ private $from_id; //ΠΠ΄Π΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΎΡ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ, Π½Π° ΠΊΠΎΡΠΎΡΡΠΉ ΠΎΡΠ²Π΅ΡΠ°ΡΡ private $text; //Π’Π΅ΠΊΡΡ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ private $date; //ΠΠ°ΡΠ° ΠΎΡΠΏΡΠ°Π²ΠΊΠΈ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ private $like; //ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π»Π°ΠΉΠΊΠΎΠ² Ρ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ public function __construct($id = 0, $text="SIMPLE TEXT", $date="21.12.2012 12:00:00", $from_id = NULL) //ΠΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ { $this->id = $id; $this->from_id = $from_id; $this->text = $text; $this->date = $date; $this->like = 0; } public function __destruct() { } public function updateText($text="SIMPLE TEXT"){//Π Π΅Π΄Π°ΠΊΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠ΅ΠΊΡΡΠ° $this->text = $text; } public function addLike(){ //ΠΠ°ΠΉΠΊ $this->like++; } } Well, here is a simple and rude (!!!) processing of the form:
$com1 = new comment(1, $_POST['commentText'], date("dmY H:i:s")); //ΠΠ±ΡΡΠ½ΡΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ $com2 = new comment(2, $_POST['commentText'], date("dmY H:i:s"), 1);//ΠΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ-ΠΎΡΠ²Π΅Ρ Π½Π° ΠΏΡΠ΅Π΄ΡΠ΄ΡΡΠΈΠΉ You can also add a username, ID generation, etc. to the class, but I think you will figure it out for yourself.
- onerather, the top-level comment $ from_id will be equal to 0, and for the nested value , Jonny Manowar
Nested sets- u_mulder