public function executeEpisodes(sfWebRequest $request) { $user_id = $this->getUser()->getApiUserId(); $this->forward404Unless($user_id); $user_data = Api::getInstance()->get('user/' . $user_id); $this->user = ApiDoctrine::createQuickObject($user_data['body']); $page = $this->page = (int) $request->getParameter('page', 1); $this->forward404Unless(is_integer($page)); $page = $page == 1 || $page == 0 ? '' : '&page=' . $page; $subreddit_ids = array(); $released_data = Api::getInstance()->get('episodeassignment/released?sf_guard_user_id=' . $user_id . $page); $this->released = ApiDoctrine::createObjectArray('EpisodeAssignment', $released_data['body']); $future_data = Api::getInstance()->get('episodeassignment/future?sf_guard_user_id=' . $user_id); $this->future = ApiDoctrine::createObjectArray('EpisodeAssignment', $future_data['body']); $current_data = Api::getInstance()->get('episodeassignment/current?sf_guard_user_id=' . $user_id); $this->current = ApiDoctrine::createObjectArray('EpisodeAssignment', $current_data['body']); foreach ($this->future as $assignment) { if (!in_array($assignment->getEpisode()->getSubredditId(), $subreddit_ids)) { $subreddit_ids[] = $assignment->getEpisode()->getSubredditId(); } } foreach ($this->current as $assignment) { if (!in_array($assignment->getEpisode()->getSubredditId(), $subreddit_ids)) { $subreddit_ids[] = $assignment->getEpisode()->getSubredditId(); } } foreach ($this->released as $assignment) { if (!in_array($assignment->getEpisode()->getSubredditId(), $subreddit_ids)) { $subreddit_ids[] = $assignment->getEpisode()->getSubredditId(); } } $memberships = array(); $moderator_data = Api::getInstance()->get('membershiptype?type=moderator', true); $membership_objects = ApiDoctrine::createQuickObjectArray($moderator_data['body']); foreach ($membership_objects as $membershiptype) { $memberships[] = $membershiptype->getIncremented(); } $admin_data = Api::getInstance()->get('membershiptype?type=admin', true); $membership_objects = ApiDoctrine::createQuickObjectArray($admin_data['body']); foreach ($membership_objects as $membershiptype) { $memberships[] = $membershiptype->getIncremented(); } $approval_data = Api::getInstance()->get('subredditmembership?sf_guard_user_id=' . $this->getUser()->getApiUserId() . '&membership_id=' . implode(',', $memberships), true); $approval_memberships = ApiDoctrine::createQuickObjectArray($approval_data['body']); $this->approvals = array(); if (count($approval_memberships)) { $approval_subreddits = array(); foreach ($approval_memberships as $membership) { $approval_subreddits[] = $membership->getSubredditId(); if (!in_array($membership->getSubredditId(), $subreddit_ids)) { $subreddit_ids[] = $membership->getSubredditId(); } } $approval_episode_data = Api::getInstance()->get('episode/future?is_submitted=1&is_approved=0&subreddit_id=' . implode(',', $approval_subreddits)); $this->approvals = ApiDoctrine::createQuickObjectArray($approval_episode_data['body']); } $subreddit_data = Api::getInstance()->get('subreddit?id=' . implode(',', $subreddit_ids), true); $subreddits = ApiDoctrine::createQuickObjectArray($subreddit_data['body']); $this->subreddits = array(); foreach ($subreddits as $subreddit) { $this->subreddits[$subreddit->getId()] = $subreddit; } $deadline_data = Api::getInstance()->get('subredditdeadline?subreddit_id=' . implode(',', $subreddit_ids), true); $deadlines = ApiDoctrine::createQuickObjectArray($deadline_data['body']); $this->deadlines = array(); foreach ($deadlines as $deadline) { if (!array_key_exists($deadline->getSubredditId(), $this->deadlines)) { $this->deadlines[$deadline->getSubredditId()] = array(); } $this->deadlines[$deadline->getSubredditId()][$deadline->getAuthorTypeId()] = $deadline->getSeconds(); } }
protected function getIndexEpisodes() { $subreddit_ids = array(); $subreddit_data = Api::getInstance()->get('subreddit/defaultfeed', true); $subreddits = ApiDoctrine::createQuickObjectArray($subreddit_data['body']); foreach ($subreddits as $subreddit) { if (!in_array($subreddit->getIncremented(), $subreddit_ids)) { $subreddit_ids[] = $subreddit->getIncremented(); } } $episodes = array(); if (count($subreddit_ids)) { $episode_data = Api::getInstance()->get('episode/released?nwfw=&subreddit_id=' . implode(',', $subreddit_ids), true); $episodes = ApiDoctrine::createObjectArray('Episode', $episode_data['body']); } return $episodes; }
protected function getUserEpisodes($user_id) { $subreddit_ids = array(); $membership_data = Api::getInstance()->get('membershiptype?' . 'sf_guard_user_id=' . $user_id . '&type=admin,moderator,user', true); $memberships = ApiDoctrine::createObjectArray('sfGuardUserSubredditMembership', $membership_data['body']); foreach ($memberships as $membership) { if (!in_array($membership->getSubredditId(), $subreddit_ids)) { $subreddit_ids[] = $membership->getSubredditId(); } } $episodes = array(); if (count($subreddit_ids)) { $episode_data = Api::getInstance()->get($this->_episode_location . '?subreddit_id=' . implode(',', $subreddit_ids), true); $episodes = ApiDoctrine::createQuickObjectArray($episode_data['body']); } $assignment_ids = array(); foreach ($episodes as $episode) { if (!in_array($episode->getEpisodeAssignmentId(), $assignment_ids)) { $assignment_ids[] = $episode->getEpisodeAssignmentId(); } } $assignment_data = Api::getInstance()->get('episodeassignment?id=' . implode(',', $assignment_ids), true); $assignments = ApiDoctrine::createQuickObjectArray($assignment_data['body']); $user_ids = array(); $this->_assignments = array(); foreach ($assignments as $assignment) { $this->_assignments[$assignment->getIncremented()] = $assignment; if (!in_array($assignment->getSfGuardUserId(), $user_ids)) { $user_ids[] = $assignment->getSfGuardUserId(); } } $user_data = Api::getInstance()->get('user?id=' . implode(',', $user_ids), true); $users = ApiDoctrine::createQuickObjectArray($user_data['body']); $this->_users = array(); foreach ($users as $user) { $this->_users[$user->getIncremented()] = $user; } return $episodes; }