public function executeEdit()
 {
     $this->setPage();
     $this->forward404Unless($this->page);
     $this->forward403Unless($this->canView);
     // Generate the username (this is done by the Revision model)
     $tmp_revision = new nahoWikiRevision();
     $tmp_revision->initUserName();
     $this->userName = $tmp_revision->getUserName();
     // Save changes
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         // Here we must be able to edit
         $this->forward403Unless($this->canEdit);
         if (!$this->page->isNew()) {
             $this->revision->archiveContent();
             $this->initNewRevision();
         }
         $this->revision->setContent($this->getRequestParameter('content'));
         $this->revision->setComment($this->getRequestParameter('comment'));
         if (!$this->getRequestParameter('request-preview')) {
             $this->revision->save();
         }
         $this->page->setLatestRevision($this->revision->getRevision());
         if (!$this->getRequestParameter('request-preview')) {
             $this->page->save();
             // save the object the wiki page relates to (so that it can trigger actions)
             $page_name = $this->page->getName();
             list($rel_obj_type, $rel_obj_id) = split("_", $page_name);
             switch ($rel_obj_type) {
                 case 'atto':
                     $rel_obj_model = 'OppAtto';
                     break;
                 case 'votazione':
                     $rel_obj_model = 'OppVotazione';
                     break;
                 case 'emendamento':
                     $rel_obj_model = 'OppEmendamento';
                     break;
             }
             $rel_obj = call_user_func($rel_obj_model . 'Peer::retrieveByPK', $rel_obj_id);
             $rel_obj->save();
             // $this->redirect('nahoWiki/view?page=' . $this->page->getName());
             $referer = $this->getUser()->getAttribute('referer', 'nahoWiki/view?page=' . $this->page->getName());
             $this->getUser()->getAttributeHolder()->remove('referer');
             $this->redirect($referer);
         }
     }
     return sfView::SUCCESS;
 }
 /**
  * initialize a wiki page (with content and revision), for a given object
  *
  * @return void
  * @author Guglielmo Celata
  **/
 public static function add_wiki_description($object, $name_prefix = "", $description = "Wiki description", $comment = "Comment")
 {
     if ($name_prefix == "") {
         $name_prefix = get_class($object);
     }
     $page = new nahoWikiPage();
     $page->setName($name_prefix . '_' . $object->getId());
     $page->setLatestRevision(1);
     $page->save();
     $content = new nahoWikiContent();
     $content->setContent($description);
     $content->save();
     $revision = new nahoWikiRevision();
     $revision->setNahoWikiPage($page);
     $revision->setNahoWikiContent($content);
     $revision->setRevision(1);
     $revision->setComment($comment);
     $revision->setUserName("admin");
     $revision->save();
 }
 public function addnahoWikiRevision(nahoWikiRevision $l)
 {
     $this->collnahoWikiRevisions[] = $l;
     $l->setnahoWikiContent($this);
 }
 public function executeEdit()
 {
     $this->setPage();
     // Do not reject here if not canEdit, cause it then fallbacks on "view source" feature
     $this->forward403Unless($this->canView);
     // Generate the username (this is done by the Revision model)
     $tmp_revision = new nahoWikiRevision();
     $tmp_revision->initUserName();
     $this->userName = $tmp_revision->getUserName();
     // Save changes
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         // Here we must be able to edit
         $this->forward403Unless($this->canEdit);
         if (!$this->page->isNew()) {
             $this->revision->archiveContent();
             $this->initNewRevision();
         }
         $this->revision->setContent($this->getRequestParameter('content'));
         $this->revision->setComment($this->getRequestParameter('comment'));
         if (!$this->getRequestParameter('request-preview')) {
             $this->revision->save();
         }
         $this->page->setLatestRevision($this->revision->getRevision());
         if (!$this->getRequestParameter('request-preview')) {
             $this->page->save();
             $this->redirect('nahoWiki/view?page=' . $this->page->getName());
         }
     }
     return sfView::SUCCESS;
 }