Exemple #1
0
 /**
  * Get standardized post data given an SQL query (which can specify WHERE conditions, for example.)
  *
  * @param ETSQLQuery $sql The SQL query to use as a basis.
  * @return array An array of posts and their details.
  */
 public function getWithSQL($sql)
 {
     // likeActivityId: いいね済みの場合、ActivityId が存在する
     // likeCnt: いいねボタンのカウント数(※ポイント数ではないので注意)
     $sql->select("p.*")->select("m.memberId", "memberId")->select("m.username", "username")->select("m.account", "account")->select("m.email", "email")->select("m.avatarFormat", "avatarFormat")->select("m.preferences", "preferences")->select("em.memberId", "editMemberId")->select("em.username", "editMemberName")->select("dm.memberId", "deleteMemberId")->select("dm.username", "deleteMemberName")->select("m.lastActionTime", "lastActionTime")->select("m.lastActionDetail", "lastActionDetail")->select("GROUP_CONCAT(g.groupId)", "groups")->select("GROUP_CONCAT(g.name)", "groupNames")->select("count(b.activityId)", "likeCnt")->from("post p")->from("member m", "m.memberId=p.memberId", "left")->from("member em", "em.memberId=p.editMemberId", "left")->from("member dm", "dm.memberId=p.deleteMemberId", "left")->from("member_group mg", "m.memberId=mg.memberId", "left")->from("group g", "g.groupId=mg.groupId", "left")->from("activity b", "b.memberId=p.memberId AND b.type='like' AND b.fromMemberId is not null AND b.postId=p.postId AND b.conversationId=p.conversationId", "left")->groupBy("p.postId")->orderBy("p.time ASC");
     $fromMemberId = ET::$session->userId;
     if ($fromMemberId) {
         // ログイン済みの場合 いいね済みを取得
         $sql->select("a.activityId", "likeActivityId")->from("activity a", "a.memberId=p.memberId AND a.type='like' AND a.fromMemberId=:fromMemberId AND a.postId=p.postId AND a.conversationId=p.conversationId", "left")->bind(":fromMemberId", $fromMemberId);
     }
     $this->trigger("getPostsBefore", array($sql));
     $result = $sql->exec();
     // Loop through the results and compile them into an array of posts.
     $posts = array();
     while ($post = $result->nextRow()) {
         // 2016/02 SWCユーザ名を設定するように変更対応
         $post["username"] = SwcUtils::getUserName($post["memberId"]);
         $post["editMemberName"] = SwcUtils::getUserName($post["editMemberId"]);
         $post["deleteMemberName"] = SwcUtils::getUserName($post["deleteMemberId"]);
         ET::memberModel()->expand($post);
         $posts[] = $post;
     }
     $this->trigger("getPostsAfter", array(&$posts));
     return $posts;
 }
 /**
  * Get a single conversation's details.
  *
  * This function returns an array of fields which is that "standard" for conversation data structure
  * within this model.
  *
  * @param array $wheres An array of WHERE conditions. Regardless of how many conversations match, only
  * 		the first will be returned.
  * @return array The conversation details array.
  */
 public function get($wheres = array())
 {
     $sql = ET::SQL()->select("s.*")->select("c.*")->select("sm.username", "startMember")->select("sm.avatarFormat", "startMemberAvatarFormat")->select("ch.title", "channelTitle")->select("ch.description", "channelDescription")->select("ch.slug", "channelSlug")->select("ch.lft", "channelLft")->select("ch.rgt", "channelRgt")->select("GROUP_CONCAT(pv.groupId)", "channelPermissionView")->select("GROUP_CONCAT(IF(pvg.name IS NOT NULL, pvg.name, ''))", "channelPermissionViewNames")->from("conversation c")->from("channel ch", "c.channelId=ch.channelId", "left")->from("channel_group pv", "c.channelId=pv.channelId AND pv.view=1", "left")->from("group pvg", "pv.groupId=pvg.groupId", "left")->from("member_conversation s", "s.conversationId=c.conversationId AND type='member' AND s.id=:userId", "left")->bind(":userId", ET::$session->userId)->from("member sm", "sm.memberId=c.startMemberId", "left")->where($wheres)->groupBy("c.channelId")->limit(1);
     // Fetch the labels field as well.
     $this->addLabels($sql);
     // Make sure the user is allowed to view this conversation.
     $this->addAllowedPredicate($sql);
     // Fetch the user's reply and moderate permissions for this conversation.
     if (!ET::$session->isAdmin()) {
         $sql->select("BIT_OR(p.reply)", "canReply")->select("BIT_OR(p.moderate)", "canModerate")->select("BIT_OR(p.moderate)", "canDeleteConversation")->from("channel_group p", "c.channelId=p.channelId AND p.groupId IN (:groupIds)", "left")->bind(":groupIds", ET::$session->getGroupIds());
     } else {
         $sql->select("1", "canReply")->select("1", "canModerate")->select("1", "canDeleteConversation");
     }
     // Execute the query.
     $result = $sql->exec();
     if (!$result->numRows()) {
         return false;
     }
     // Get all the details from the result into an array.
     $conversation = $result->firstRow();
     // 2016/02 SWCユーザ名設定
     $conversation["startMember"] = SwcUtils::getUserName($conversation["startMemberId"]);
     // Expand the labels field into a simple array of active labels.
     $conversation["labels"] = $this->expandLabels($conversation["labels"]);
     // Convert the separate groups who have permission to view this channel ID/name fields into one.
     $conversation["channelPermissionView"] = $this->formatGroupsAllowed($conversation["channelPermissionView"], $conversation["channelPermissionViewNames"]);
     // If the conversation is locked and the user can't moderate, then they can't reply.
     if ($conversation["locked"] and !$conversation["canModerate"]) {
         $conversation["canReply"] = false;
     }
     // If the current user owns this conversation, and it's a draft, or they're the only poster,
     // then allow them to delete it. We can only know that they're the only poster if there is only
     // one post in the conversation, or if there are two and the last one is theirs. In an ideal world,
     // we would check all of the post authors, but it's probably not worth the performance hit here.
     if ($conversation["startMemberId"] == ET::$session->userId and ($conversation["countPosts"] <= 1 or $conversation["countPosts"] == 2 and $conversation["lastPostMemberId"] == ET::$session->userId)) {
         $conversation["canDeleteConversation"] = true;
     }
     return $conversation;
 }
Exemple #3
0
 /**
  * Get a full list of conversation details for a list of conversation IDs.
  *
  * @param array $conversationIDs The list of conversation IDs to fetch details for.
  * @param bool $checkForPermission Whether or not to add a check onto the query to make sure the
  * 		user has permission to view all of the conversations.
  */
 public function getResults($conversationIDs, $checkForPermission = false)
 {
     // Construct a query to get details for all of the specified conversations.
     $sql = ET::SQL()->select("s.*")->select("c.*")->select("sm.memberId", "startMemberId")->select("sm.username", "startMember")->select("sm.avatarFormat", "startMemberAvatarFormat")->select("lpm.memberId", "lastPostMemberId")->select("lpm.username", "lastPostMember")->select("lpm.email", "lastPostMemberEmail")->select("lpm.avatarFormat", "lastPostMemberAvatarFormat")->select("IF((IF(c.lastPostTime IS NOT NULL,c.lastPostTime,c.startTime)>:markedAsRead AND (s.lastRead IS NULL OR s.lastRead<c.countPosts)),(c.countPosts - IF(s.lastRead IS NULL,0,s.lastRead)),0)", "unread")->select("p.content", "firstPost")->from("conversation c")->from("member_conversation s", "s.conversationId=c.conversationId AND s.type='member' AND s.id=:memberId", "left")->from("member sm", "c.startMemberId=sm.memberId", "left")->from("member lpm", "c.lastPostMemberId=lpm.memberId", "left")->from("channel ch", "c.channelId=ch.channelId", "left")->from("post p", "c.sticky AND c.conversationId=p.conversationId AND c.startTime=p.time", "left")->bind(":markedAsRead", ET::$session->preference("markedAllConversationsAsRead"))->bind(":memberId", ET::$session->userId);
     // If we need to, filter out all conversations that the user isn't allowed to see.
     if ($checkForPermission) {
         ET::conversationModel()->addAllowedPredicate($sql);
     }
     // Add a labels column to the query.
     ET::conversationModel()->addLabels($sql);
     // Limit the results to the specified conversation IDs
     $sql->where("c.conversationId IN (:conversationIds)")->orderBy("FIELD(c.conversationId,:conversationIdsOrder)");
     $sql->bind(":conversationIds", $conversationIDs, PDO::PARAM_INT);
     $sql->bind(":conversationIdsOrder", $conversationIDs, PDO::PARAM_INT);
     $this->trigger("beforeGetResults", array(&$sql));
     // Execute the query and put the details of the conversations into an array.
     $result = $sql->exec();
     $results = array();
     $model = ET::conversationModel();
     while ($row = $result->nextRow()) {
         // XXX: 2016/02 SWCユーザ名設定
         $row["startMember"] = SwcUtils::getUserName($row["startMemberId"]);
         $row["lastPostMember"] = SwcUtils::getUserName($row["lastPostMemberId"]);
         // Expand the comma-separated label flags into a workable array of active labels.
         $row["labels"] = $model->expandLabels($row["labels"]);
         $row["replies"] = max(0, $row["countPosts"] - 1);
         $results[] = $row;
     }
     $this->trigger("afterGetResults", array(&$results));
     return $results;
 }