123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace huo\model\comment;
- use huo\model\common\CommonModel;
- class CommentModel extends CommonModel {
- protected $name = 'comment';
-
- protected $relationFilter = ['mem', 'to_mem'];
-
- protected $autoWriteTimestamp = true;
-
- public function mem() {
- return $this->belongsTo('\huo\model\member\MemberModel', 'mem_id');
- }
- public function toMem() {
- return $this->belongsTo('\huo\model\member\MemberModel', 'to_mem_id');
- }
-
- public function game() {
- return $this->belongsTo('\huo\model\game\GameModel', 'object_id')->field('id,name,icon');
- }
-
- protected function base($query) {
- $query->where('delete_time', 0)
- ->where('status', 1);
- }
-
- public function getContentAttr($value) {
- return cmf_replace_content_file_url(htmlspecialchars_decode($value));
- }
-
- public function getMoreAttr($value) {
- $more = json_decode($value, true);
- if (!empty($more['thumbnail'])) {
- $more['thumbnail'] = cmf_get_image_url($more['thumbnail']);
- }
- if (!empty($more['photos'])) {
- foreach ($more['photos'] as $key => $value) {
- $more['photos'][$key]['url'] = cmf_get_image_url($value['url']);
- }
- }
- if (!empty($more['files'])) {
- foreach ($more['files'] as $key => $value) {
- $more['files'][$key]['url'] = cmf_get_image_url($value['url']);
- }
- }
- return $more;
- }
-
- public static function setComment($data) {
- if (!$data) {
- return false;
- }
- if ($obj = self::create($data)) {
- return $obj->id;
- } else {
- return false;
- }
- }
- }
|