ScrollController.php
00001 <?php
00010 class Scroll_ScrollController extends Dsao_Controller_Action
00011 {
00012 public function preDispatch()
00013 {
00014 $this->_setDefaultModelClass('Scroll_Scroll');
00015 }
00016
00022 public function deleteAction()
00023 {
00024
00025 $this->getView()->addTemplate(false);
00026
00027
00028 $idScroll = $this->getUri()->id;
00029
00030
00031
00032 $scroll = $this->_getModel()->isParticipated
00033 ($this->getUser()->getId(), $idScroll);
00034
00035
00036 if (!$scroll || $scroll->isDeleted($this->getUser()->getId()))
00037 {
00038 $this->getLog()->err('scroll_scroll_delete_error_no_permission');
00039
00040 return;
00041 }
00042
00043
00044 $scrollThread = 'scroll_scroll';
00045
00046
00047 if ($this->getUri()->thread)
00048 {
00049 $scrollThread = 'scroll_thread';
00050 }
00051
00052
00053 if (!$this->getUri()->confirm)
00054 {
00055
00056 $uriConfirm = new Dsao_Uri_Http('/scroll/scroll/delete', array(
00057 'confirm' => true,
00058 'id' => $idScroll,
00059 ));
00060
00061
00062 if ($scrollThread == 'scroll_thread')
00063 {
00064 $uriConfirm->thread = true;
00065 }
00066
00067 $this->getView()->addConfirmationTemplate(array(
00068 'scroll_scroll_delete_confirm',
00069 array(
00070 'nameAuthor' => $scroll->nameAuthor,
00071 'scrollThread' => $scrollThread,
00072 'subject' => $scroll->subject,
00073 ), true),
00074 $uriConfirm);
00075
00076 return true;
00077 }
00078
00079
00080 if (!$this->getHelper('SessionToken')->hasValidToken())
00081 {
00082 return;
00083 }
00084
00085
00086
00087
00088 $scrolls = null;
00089
00090
00091 if ($scroll->idThread == 0)
00092 {
00093 $scrolls = $this->_getModel('Scroll_Thread')->fetchThread
00094 ($idScroll, $this->getUser()->getId());
00095 }
00096 else
00097 {
00098 $scrolls = new Dsao_Scrollset(array($scroll));
00099 }
00100
00101 $scrolls->delete($this->getUser()->getId());
00102
00103
00104 $this->getLog()->affirm
00105 (array('scroll_scroll_delete_affirmation_deleted',
00106 array('scrollThread' => $scrollThread), true));
00107 }
00108
00114 public function sendAction()
00115 {
00116 $this->getHelper('History')->setAddToHistory();
00117
00118 $scrollDataSubmitted = array
00119 (
00120 'content' => $this->getRequest()->getParam('content', false),
00121 'idThread' => $this->getRequest()->getParam('idthread', 0),
00122 'nameRecipient' => $this->getRequest()->getParam('recipient', false),
00123 'subject' => $this->getRequest()->getParam('subject', false)
00124 );
00125
00126 $scrollSubmitted = new Dsao_Scroll($scrollDataSubmitted);
00127
00128
00129 if ($this->getRequest()->isPost())
00130 {
00131
00132 if (!$this->getHelper('SessionToken')->hasValidToken())
00133 {
00134 return;
00135 }
00136
00137 $scroll = clone $scrollSubmitted;
00138
00139
00140 if (!$this->_getModel()->insertScroll($scroll)->isValid())
00141 {
00142
00143 foreach ($scroll->toArray() as $key => $value)
00144 {
00145
00146 if (false === $value)
00147 {
00148 $this->getLog()
00149 ->err('scroll_scroll_send_error_'.Dsao_Model_Abstract::underscore($key));
00150 }
00151 }
00152 }
00153 else
00154 {
00155
00156 $this->getLog()->affirm(array('scroll_scroll_send_affirmation_sent',
00157 array('username' => $scroll->nameRecipient)));
00158
00159
00160 $this->getView()->addTemplate(false);
00161
00162 return;
00163 }
00164 }
00165
00166
00167 if ($scrollSubmitted->idThread > 0)
00168 {
00169
00170 if ( ($scrollThread = $this->_getModel()->
00171 isParticipated($this->getUser()->id, $scrollSubmitted->idThread)) )
00172 {
00173 $scrollSubmitted->idThread = $scrollThread->id;
00174 $scrollSubmitted->subject = $scrollThread->subject;
00175 $scrollSubmitted->nameRecipient = $scrollThread
00176 ->getOtherUser($this->getUser()->id)->username;
00177 }
00178
00179 else
00180 {
00181 $this->getLog()->err('scroll_scroll_send_error_idthread');
00182 }
00183 }
00184
00185 $this->getView()->assign('scroll', $scrollSubmitted);
00186 }
00187 }