openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

FolderCreatepageAction.class.php (1468B)


      1 <?php
      2 namespace cms\action\folder;
      3 use cms\action\Action;
      4 use cms\action\FolderAction;
      5 use cms\action\Method;
      6 use cms\model\BaseObject;
      7 use cms\model\Page;
      8 use cms\model\Permission;
      9 use cms\model\Project;
     10 use language\Messages;
     11 use util\exception\ValidationException;
     12 
     13 
     14 class FolderCreatepageAction extends FolderAction implements Method {
     15 
     16 	public function getRequiredPermission() {
     17 		return Permission::ACL_CREATE_PAGE;
     18 	}
     19 
     20 
     21 
     22 	public function view() {
     23         $project = new Project( $this->folder->projectid );
     24 
     25         $all_templates = $project->getTemplates();
     26 		$this->setTemplateVar('templates' ,$all_templates          );
     27 		$this->setTemplateVar('objectid'  ,$this->folder->objectid );
     28 
     29 		if	( count($all_templates) == 0 )
     30 			$this->addWarningFor($this->folder,Messages::NO_TEMPLATES_AVAILABLE );
     31     }
     32 
     33 
     34     public function post() {
     35 		$name    = $this->request->getText('name'   );
     36 		$filename    = $this->request->getText('filename'   );
     37 		$description = $this->request->getText('description');
     38 
     39 		$page = new Page();
     40 		$page->filename   = BaseObject::urlify( $name );
     41 		$page->templateid = $this->request->getRequiredNumber('templateid');
     42 
     43 		$page->parentid   = $this->folder->objectid;
     44 		$page->projectid  = $this->folder->projectid;
     45 
     46 
     47 		$page->persist();
     48 		$page->setNameForAllLanguages( $name,$description );
     49 
     50 		$this->addNoticeFor( $page, Messages::ADDED );
     51 		$this->setTemplateVar('objectid',$page->objectid);
     52 
     53 		$this->folder->setTimestamp();
     54     }
     55 }