public function getVideosCommentsUser($id, $limit = null, $user_id = null, $sort = null) { //$id = picture id $arrayVId = array(); $order = "id desc"; $commentM = new Application_Model_Comment(); $where = "item_id ='{$id}' and item_type='movie_user_video' and parent_id='0'"; if (!is_null($user_id)) { $where .= " and user_id='{$user_id}'"; } if (!is_null($sort)) { if ($sort != "recent") { $comments = $commentM->fetchAll($where, $order); foreach ($comments as $row) { $arrayVId[] = $row->getId(); } } else { $comments = $commentM->fetchAll($where, $order, $limit); } //$strPicId=implode(",",$arrayPicId); $voteM = new Application_Model_Vote(); $res = array(); if ($sort == "up") { $res = $voteM->getTotalVotesGroup($arrayVId, 'movie', 'user_movie_videos_comments', 1, null); } else { if ($sort == "down") { $res = $voteM->getTotalVotesGroup($arrayVId, 'movie', 'user_movie_videos_comments', -1, null); } else { if ($sort == "sum") { $res = $voteM->getTotalVotesSum($arrayVId, 'movie', 'user_movie_videos_comments'); } } } if (count($res) > 0 && $sort != "recent") { unset($comments); $ctr = 0; foreach ($res as $row) { $ctr++; if (!is_null($limit)) { if ($limit < $ctr) { break; } } $comments[] = $commentM->find($row->item_id); $usedIds[] = $row->item_id; } $remain = array_diff($arrayVId, $usedIds); foreach ($remain as $comment_id) { $ctr++; if (!is_null($limit)) { if ($limit < $ctr) { break; } } $comments[] = $commentM->find($comment_id); } } } else { $comments = $commentM->fetchAll($where, $order, $limit); } return $comments; }