| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresource.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/view/admin/adminresourceslistview.class.php" ); 9 10 /** 11 * \ingroup Action 12 * @private 13 * 14 * Deletes resources and albums from the blog 15 */ 16 class AdminDeleteGalleryItemsAction extends AdminAction 17 { 18 19 var $_resourceIds; 20 var $_albumIds; 21 22 var $_successMessage; 23 var $_errorMessage; 24 var $_totalOk; 25 26 /** 27 * Constructor. If nothing else, it also has to call the constructor of the parent 28 * class, BlogAction with the same parameters 29 */ 30 function AdminDeleteGalleryItemsAction( $actionInfo, $request ) 31 { 32 $this->AdminAction( $actionInfo, $request ); 33 34 $this->_totalOk = 0; 35 $this->_successMessage = ""; 36 $this->_errorMessage = ""; 37 38 // data validation 39 $this->registerFieldValidator( "resourceIds", new ArrayValidator(), true ); 40 $this->registerFieldValidator( "albumIds", new ArrayValidator(), true ); 41 $view = new AdminResourcesListView( $this->_blogInfo ); 42 $view->setErrorMessage( $this->_locale->tr("error_no_resources_selected")); 43 $this->setValidationErrorView( $view ); 44 } 45 46 function perform() 47 { 48 // create the view 49 $this->_view = new AdminResourcesListView( $this->_blogInfo ); 50 51 // fetch the parameters 52 $this->_resourceIds = $this->_request->getValue( "resourceIds" ); 53 $this->_albumIds = $this->_request->getValue( "albumIds" ); 54 55 // make sure that we're dealing with arrays! 56 if( !is_array( $this->_resourceIds)) $this->_resourceIds = Array(); 57 if( !is_array( $this->_albumIds)) $this->_albumIds = Array(); 58 59 // remove the items, if any 60 $this->_deleteAlbums(); 61 $this->_deleteResources(); 62 63 // put error and success messages (if any) into the view 64 if( $this->_successMessage != "" ) $this->_view->setSuccessMessage( $this->_successMessage ); 65 if( $this->_errorMessage != "" ) $this->_view->setErrorMessage( $this->_errorMessage ); 66 $this->setCommonData(); 67 68 // clear the cache 69 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false ); 70 71 // better to return true if everything fine 72 return true; 73 } 74 75 /** 76 * deletes resources from the list 77 */ 78 function _deleteResources() 79 { 80 // load the resource 81 $resources = new GalleryResources(); 82 83 // loop through the array of resource ids and 84 // remove them all 85 foreach( $this->_resourceIds as $resourceId => $value ) { 86 // fetch the resource first, to get some info about it 87 $resource = $resources->getResource( $resourceId, $this->_blogInfo->getId()); 88 89 if( !$resource ) { 90 $this->_errorMessage .= $this->_locale->pr("error_deleting_resource2", $resourceId )."<br/>"; 91 } 92 else { 93 $this->notifyEvent( EVENT_PRE_RESOURCE_DELETE, Array( "resource" => &$resource )); 94 95 // and now remove it 96 $res = $resources->deleteResource( $resourceId, $this->_blogInfo->getId()); 97 if( $res ) { 98 $this->_totalOk++; 99 if( $this->_totalOk > 1 ) 100 $this->_successMessage = $this->_locale->pr("items_deleted_ok", $this->_totalOk ); 101 else 102 $this->_successMessage .= $this->_locale->pr("item_deleted_ok", $resource->getFileName()); 103 $this->notifyEvent( EVENT_PRE_RESOURCE_DELETE, Array( "resource" => &$resource )); 104 } 105 else 106 $this->_errorMessage .= $this->_locale->pr("error_deleting_resource", $resource->getFileName())."<br/>"; 107 } 108 } 109 110 return true; 111 } 112 113 /** 114 * deletes resources from the list 115 */ 116 function _deleteAlbums() 117 { 118 $albums = new GalleryAlbums(); 119 120 // loop through the array of resource ids and 121 // remove them all 122 foreach( $this->_albumIds as $albumId => $value ) { 123 // fetch the resource first, to get some info about it 124 $album = $albums->getAlbum( $albumId, $this->_blogInfo->getId()); 125 126 if( !$album ) { 127 $this->_errorMessage .= $this->_locale->pr( "error_deleting_album2", $albumId )."<br/>"; 128 } 129 else { 130 if( $album->getNumChildren() > 0 || $album->getNumResources() > 0 ) { 131 $this->_errorMessage .= $this->_locale->pr("error_album_has_children", $album->getName()."<br/>"); 132 } 133 else { 134 $this->notifyEvent( EVENT_PRE_ALBUM_DELETE, Array( "album" => &$album )); 135 136 // and now remove it 137 $res = $albums->deleteAlbum( $albumId, $this->_blogInfo->getId()); 138 if( $res ) { 139 $this->_totalOk++; 140 if( $this->_totalOk > 1 ) 141 $this->_successMessage = $this->_locale->pr("items_deleted_ok", $this->_totalOk ); 142 else 143 $this->_successMessage = $this->_locale->pr("item_deleted_ok", $album->getName()); 144 145 $this->notifyEvent( EVENT_POST_ALBUM_DELETE, Array( "album" => &$album )); 146 } 147 else 148 $this->_errorMessage .= $this->_locale->pr("error_deleting_album", $album->getName())."<br/>"; 149 } 150 } 151 } 152 153 return true; 154 } 155 } 156 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|