root/trunk/apps/snippets/modules/snippet/actions/actions.class.php

Revision 7, 3.9 kB (checked in by francois, 4 years ago)

refactored sidebar module and added latest comments in sidebar (+feed)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /**
4  * snippet actions.
5  *
6  * @package    sf_sandbox
7  * @subpackage snippet
8  * @author     Your name here
9  * @version    SVN: $Id$
10  */
11 class snippetActions extends sfActions
12 {
13   public function executeIndex()
14   {
15     $this->forward('snippet', 'list');
16   }
17
18   public function executeList()
19   {
20     $this->snippet_pager = SnippetSnippetPeer::getPager($this->getRequestParameter('page', 1), sfConfig::get('app_pager_max_per_page'), $this->getRequestParameter('sort', 'date'));
21   }
22
23   public function executeNew()
24   {
25     $this->snippet = new SnippetSnippet();
26
27     $this->setTemplate('edit');
28   }
29
30   public function executePreview()
31   {
32     $this->html = myToolkit::transformToHtml($this->getRequestParameter('body'));
33   }
34
35   public function executeSave()
36   {
37     if ($this->getRequestParameter('id'))
38     {
39       $snippet = SnippetSnippetPeer::retrieveByPk($this->getRequestParameter('id'));
40       $this->forward404Unless($snippet || $this->getUser()->getUserId() != $snippet->getSnippetUser()->getId());
41     }
42     else
43     {
44       $snippet = new SnippetSnippet();
45       $snippet->setUserId($this->getUser()->getUserId());
46     }
47
48     $snippet->setTitle($this->getRequestParameter('title'));
49     $snippet->setBody($this->getRequestParameter('body'));
50
51     $snippet->save();
52
53     $snippet->setTags($this->getRequestParameter('tags'));
54
55     return $this->redirect('snippet/show?id='.$snippet->getId());
56   }
57
58   public function executeEdit()
59   {
60     if ($this->getRequestParameter('id'))
61     {
62       $this->snippet = SnippetSnippetPeer::retrieveByPk($this->getRequestParameter('id'));
63       $this->forward404Unless($this->snippet || $this->getUser()->getUserId() != $this->snippet->getSnippetUser()->getId());
64     }
65     else
66     {
67       $this->snippet = new SnippetSnippet();
68     }
69   }
70
71   public function executeShow()
72   {
73     $this->snippet = SnippetSnippetPeer::retrieveByPk($this->getRequestParameter('id'));
74     $this->forward404Unless($this->snippet);
75
76     $this->comments = $this->snippet->getSnippetComments();
77   }
78  
79   public function executeShowByComment()
80   {
81     $this->snippet = SnippetSnippetPeer::retrieveByComment($this->getRequestParameter('id'));
82     $this->forward404Unless($this->snippet);
83
84     $this->comments = $this->snippet->getSnippetComments();
85   } 
86
87   public function executeDelete()
88   {
89     $snippet = SnippetSnippetPeer::retrieveByPk($this->getRequestParameter('id'));
90     $this->forward404Unless($snippet);
91
92     $snippet->delete();
93
94     $this->redirect('@homepage');
95   }
96
97   public function executeListByTag()
98   {
99     $this->tags = explode(' ', $this->getRequestParameter('tag'));
100     $this->snippets = SnippetSnippetPeer::getRecentByTag($this->tags, sfConfig::get('app_list_size'), $this->getRequestParameter('sort', 'date'));
101     $this->forward404Unless($this->snippets);
102
103     $this->getRequest()->setAttribute('tags', $this->tags);
104     $this->getRequest()->setAttribute('associated_tags', SnippetTagPeer::getForSnippetsWithCount($this->snippets, $this->tags));
105   }
106
107   public function executeListByUser()
108   {
109     $this->user = SnippetUserPeer::retrieveByLogin($this->getRequestParameter('login'));
110     $this->forward404Unless($this->user);
111
112     $this->snippets = SnippetSnippetPeer::getByUser($this->user, sfConfig::get('app_list_size'), $this->getRequestParameter('sort', 'date'));
113     $this->forward404Unless($this->snippets);
114   }
115
116   public function executeVoteForSnippet()
117   {
118     $this->id = $this->getRequestParameter('id');
119     $snippet = SnippetSnippetPeer::retrieveByPk($this->id);
120     if (!$snippet)
121     {
122       return sfView::NONE;
123     }
124     $mark = $this->getRequestParameter('vote');
125
126     $vote = new SnippetVote();
127     $vote->setUserId($this->getUser()->getUserId());
128     $vote->setSnippetId($snippet->getId());
129     $vote->setVote($mark);
130     $vote->save();
131
132     $this->vote = $vote->getSnippetSnippet()->getAverageVote();
133   }
134
135   public function handleErrorSave()
136   {
137     $this->forward('snippet', 'edit');
138   }
139 }
140
141 ?>
Note: See TracBrowser for help on using the browser.