1<?php
2
3/**
4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
5 * all the essential functionalities required for any enterprise.
6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
7 *
8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
9 * the GNU General Public License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA  02110-1301, USA
19 */
20
21/**
22 * Description of loadNextSharesAction
23 *
24 * @author aruna
25 */
26class loadNextSharesAction extends BaseBuzzAction {
27
28    /**
29     * @param sfForm $form
30     * @return
31     */
32    protected function setForm(sfForm $form) {
33        if (is_null($this->form)) {
34            $this->form = $form;
35        }
36    }
37
38    /**
39     *
40     * @param PostForm $form
41     */
42    private function setPostForm($form) {
43        $this->postForm = $form;
44    }
45
46    /**
47     *
48     * @return CreatePostForm
49     */
50    private function getPostForm() {
51        if (!($this->postForm instanceof CreatePostForm)) {
52            $this->setPostForm(new CreatePostForm());
53        }
54        return $this->postForm;
55    }
56
57    /**
58     *
59     * @param commentForm $form
60     */
61    private function setCommentForm($form) {
62        $this->commentForm = $form;
63    }
64
65    /**
66     *
67     * @return commentForm
68     */
69    private function getCommentForm() {
70        if (!($this->commentForm instanceof CommentForm)) {
71            $this->setCommentForm(new CommentForm());
72        }
73        return $this->commentForm;
74    }
75
76    /**
77     *
78     * @return commentForm
79     */
80    private function getEditForm() {
81        if (!($this->editForm instanceof CommentForm)) {
82            $this->editForm = new CommentForm();
83        }
84        return $this->editForm;
85    }
86
87    public function execute($request) {
88        try {
89            $this->setForm(new LoadMorePostsForm());
90
91            if ($request->isMethod('post')) {
92                $this->form->bind($request->getParameter($this->form->getName()));
93                if ($this->form->isValid()) {
94                    $formValues = $this->form->getValues();
95
96                    $this->loggedInUser = $this->getLogedInEmployeeNumber();
97                    $this->lastPostId = $formValues['lastPostId'];
98                    $this->buzzService = $this->getBuzzService();
99
100                    $this->nextSharesList = $this->buzzService->getMoreShares($this->getShareCount(), $this->lastPostId);
101                    $this->editForm = $this->getEditForm();
102                    $this->commentForm = $this->getCommentForm();
103                }
104            }
105        } catch (Exception $ex) {
106            $this->redirect('auth/login');
107        }
108    }
109
110    /**
111     * get share count
112     * @return Int
113     */
114    protected function getShareCount() {
115        $buzzConfigService = $this->getBuzzConfigService();
116        return $buzzConfigService->getBuzzShareCount();
117    }
118
119}
120