/** * 获取JSON Portal数据 */ public static function getCommentJSONData($type = "") { $criteria = new CDbCriteria(); $criteria->order = 'remind_time desc'; $criteria->condition = '(to_id = :to_id and remind_flag != :to_remind_flag and delete_flag != :to_delete_flag)'; $criteria->params = array(':to_id' => Yii::app()->user->id, ':to_remind_flag' => $type == "" ? 1 : 2, ':to_delete_flag' => 1); $models = self::model()->findAll($criteria); $data = array(); foreach ($models as $model) { $contentModel = NotificationContent::model()->findByPk($model->content_id); if ($contentModel->notification_type != "attention" && $contentModel->notification_type != "report") { $pk_id = Comment::model()->findByPk($contentModel->pk_id)->pk_id; if ($contentModel->notification_type == "answer") { $dataUrl = Yii::app()->controller->createUrl("diary", array("action" => "view", "id" => $pk_id, "pk_id" => $model->id)); } else { if ($contentModel->notification_type == "topic") { $dataUrl = Yii::app()->controller->createUrl("topic", array("id" => $pk_id, "pk_id" => $model->id)); } else { if ($contentModel->notification_type == "picture") { $dataUrl = Yii::app()->controller->createUrl("picturewall", array("type" => "sharepicture", "id" => $pk_id, "pk_id" => $model->id)); } else { if ($contentModel->notification_type == "recent") { $user_id = Recent::model()->findByPk($pk_id)->create_user; $dataUrl = Yii::app()->controller->createUrl("recent", array("type" => "other", "action" => "view", "id" => $pk_id, "user_id" => $user_id, "pk_id" => $model->id)); } else { if ($contentModel->notification_type == "timeline") { $dataUrl = Yii::app()->controller->createUrl("timeline", array("type" => "action", "action" => "view", "id" => $pk_id, "pk_id" => $model->id)); } } } } } $data[] = array('id' => $model->id, 'desc' => Comment::model()->findByPk($contentModel->pk_id)->content, 'content' => $contentModel->content, 'remindFlag' => $model->remind_flag, 'createUserId' => $contentModel->from_id, 'createUser' => User::getNameById($contentModel->from_id), 'createTime' => Comment::model()->timeintval($contentModel->send_time), 'avatarSrc' => User::getAvatarById($contentModel->from_id), 'dataUrl' => $dataUrl); } } return $type == "" ? CJSON::encode($data) : $data; }
public function getComment($parent_id = 0, $model, $pk) { $criteria = new CDbCriteria(); $criteria->addCondition("model=:model"); $criteria->addCondition("pk_id=:pk_id"); $criteria->addCondition("parent_id=:parent_id"); if ($parent_id == 0) { $criteria->order = "create_time desc"; } else { $criteria->order = "create_time asc"; } $criteria->params = array(":model" => $model, ":pk_id" => $pk, ":parent_id" => $parent_id); $data = self::model()->findAll($criteria); $comments = array(); $i = 0; foreach ($data as $value) { $comments[$i]["id"] = $value["id"]; $comments[$i]["parent_id"] = $value["parent_id"]; $comments[$i]["content"] = $value["content"]; $comments[$i]["model"] = $value["model"]; $comments[$i]["pk_id"] = $value["pk_id"]; $comments[$i]["create_time"] = $value["create_time"]; $comments[$i]["create_user"] = self::model()->findByPk($value["parent_id"])->user_id; $comments[$i]["reply_user"] = $value["user_id"]; $comments[$i]["user_avatar"] = User::getAvatarById($value["user_id"]); $comments[$i]["chrildren"] = $this->getComment($value["id"], $model, $pk); $i++; } return $comments; }
} </style> <div class="product"> <div class="product-comment"> <div class="comment-list clearfix"> <a name="<?php echo "comment_" . $data->id; ?> "></a> <div class="item clearfix" style="margin-bottom: 10px;position: relative;"> <div class="user" style="width:6%;float: left;"> <div class="u-icon"> <a title="查看Ta个人信息" target="_blank" href="<?php echo $this->createUrl('default/userinfo', array('user_id' => $data->user_id)); ?> "> <img height="50" width="50" src="<?php echo User::getAvatarById($data->user_id); ?> " alt="<?php echo User::getNameById($data->user_id); ?> "> </a> </div> <div class="u-name"><a target="_blank" href="<?php echo $this->createUrl('default/userinfo', array('user_id' => $data->user_id)); ?> "><b><?php echo User::getNameById($data->user_id); ?> </b></a></div> </div> <div class="clearfix box-section" style="width:94%;float: right;">