openrat-cms

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

FolderRemoveAction.class.php (1083B)


      1 <?php
      2 namespace cms\action\folder;
      3 use cms\action\FolderAction;
      4 use cms\action\Method;
      5 use cms\model\Permission;
      6 use language\Messages;
      7 use util\exception\ValidationException;
      8 
      9 
     10 class FolderRemoveAction extends FolderAction implements Method {
     11 
     12 	public function getRequiredPermission() {
     13 		return Permission::ACL_DELETE;
     14 	}
     15 
     16 
     17 	public function view() {
     18         $this->setTemplateVar( 'name',$this->folder->filename );
     19         $this->setTemplateVar( 'hasChildren', $this->folder->hasChildren() );
     20     }
     21 
     22 
     23     public function post() {
     24 
     25 		if   ( $this->folder->isRoot() )
     26 			// Could not delete the root folder on user request.
     27 			throw new ValidationException("parent",Messages::FOLDER_ROOT);
     28 
     29 		if   ( $this->folder->hasChildren() ) {
     30 			if ($this->request->isTrue('withChildren'))
     31 				$this->folder->deleteAll();  // Delete with children
     32 			else
     33 				throw new ValidationException("withChildren",Messages::CONTAINS_CHILDREN);
     34 
     35 		}
     36         else
     37             $this->folder->delete();  // Only delete current folder.
     38 
     39         $this->addNoticeFor($this->folder, Messages::DELETED);
     40     }
     41 }