diff --git a/include/library/Crunchbutton/Restaurant.php b/include/library/Crunchbutton/Restaurant.php index 3c264c392..4dd477c2b 100644 --- a/include/library/Crunchbutton/Restaurant.php +++ b/include/library/Crunchbutton/Restaurant.php @@ -1160,6 +1160,23 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange { foreach ( $ignore as $property => $val ) { unset( $out[ $property ] ); } + + $comment = $this->comment(); + + if ($comment->id_restaurant_comment) { + $auths = $comment->user()->auths(); + foreach ($auths as $auth) { + if ($auth->type == 'facebook') { + $id = $auth->auth; + break; + } + } + $out['comment'] = [ + 'content' => $comment->content, + 'user' => $comment->user()->get(0)->name(), + 'fb' => $id + ]; + } return $out; } @@ -1493,6 +1510,13 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange { WHERE txt IS NOT NULL"; return Admin::q( $query ); } + + public function comment() { + if (!isset($this->_comment)) { + $this->_comment = Restaurant_Comment::q('select * from restaurant_comment where top=1 && id_restaurant='.$this->id_restaurant.''); + } + return $this->_comment; + } public function save() { if (!$this->timezone) { diff --git a/include/library/Crunchbutton/Restaurant/Comment.php b/include/library/Crunchbutton/Restaurant/Comment.php new file mode 100644 index 000000000..f97a52b3b --- /dev/null +++ b/include/library/Crunchbutton/Restaurant/Comment.php @@ -0,0 +1,25 @@ +table('restaurant_comment') + ->idVar('id_restaurant_comment') + ->load($id); + } + + public function user() { + if (!isset($this->_user)) { + $this->_user = User::o($this->id_user); + } + return $this->_user; + } + + public function restaurant() { + if (!isset($this->_restaurant)) { + $this->_restaurant = Restaurant::o($this->id_restaurant); + } + return $this->_restaurant; + } +} \ No newline at end of file diff --git a/include/library/Crunchbutton/User.php b/include/library/Crunchbutton/User.php index 6676040b6..830913c26 100644 --- a/include/library/Crunchbutton/User.php +++ b/include/library/Crunchbutton/User.php @@ -2,6 +2,14 @@ class Crunchbutton_User extends Cana_Table { + public function name() { + if (!isset($this->_name)) { + $name = explode(' ',$this->name); + $this->_name = $name[0]; + } + return $this->_name; + } + public function byPhone($phone) { $phone = preg_replace('/[^0-9]/i','',$phone); return User::q('select * from user where phone="'.$phone.'" order by id_user desc limit 1'); diff --git a/include/views/default/seven/frontend/restaurant.phtml b/include/views/default/seven/frontend/restaurant.phtml index 6af7a640d..063101506 100644 --- a/include/views/default/seven/frontend/restaurant.phtml +++ b/include/views/default/seven/frontend/restaurant.phtml @@ -17,11 +17,21 @@
{{restaurant.comment.user}} says
+{{restaurant.comment.content}}
+