| [ 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/data/validator/integervalidator.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/view/admin/adminresourceslistview.class.php" ); 10 11 /** 12 * \ingroup Action 13 * @private 14 * 15 * Massive changes resources and albums to another Album 16 */ 17 class AdminChangeGalleryItemsAlbumAction extends AdminAction 18 { 19 20 var $_resourceIds; 21 var $_albumIds; 22 var $_galleryAlbumId; 23 24 var $_successMessage; 25 var $_errorMessage; 26 var $_totalOk; 27 28 /** 29 * Constructor. If nothing else, it also has to call the constructor of the parent 30 * class, BlogAction with the same parameters 31 */ 32 function AdminChangeGalleryItemsAlbumAction( $actionInfo, $request ) 33 { 34 $this->AdminAction( $actionInfo, $request ); 35 36 $this->_totalOk = 0; 37 $this->_successMessage = ""; 38 $this->_errorMessage = ""; 39 40 // data validation 41 $this->registerFieldValidator( "resourceIds", new ArrayValidator(), true ); 42 $this->registerFieldValidator( "albumIds", new ArrayValidator(), true ); 43 $this->registerFieldValidator( "galleryAlbumId", new IntegerValidator(), true ); 44 $view = new AdminResourcesListView( $this->_blogInfo ); 45 $view->setErrorMessage( $this->_locale->tr("error_no_resources_selected")); 46 $this->setValidationErrorView( $view ); 47 } 48 49 function perform() 50 { 51 // create the view 52 $this->_view = new AdminResourcesListView( $this->_blogInfo ); 53 54 // fetch the parameters 55 $this->_resourceIds = $this->_request->getValue( "resourceIds" ); 56 $this->_albumIds = $this->_request->getValue( "albumIds" ); 57 $this->_galleryAlbumId = $this->_request->getValue( "galleryAlbumId" ); 58 59 // make sure that we're dealing with arrays! 60 if( !is_array( $this->_resourceIds)) $this->_resourceIds = Array(); 61 if( !is_array( $this->_albumIds)) $this->_albumIds = Array(); 62 63 // update the items, if any 64 $this->_updateAlbums(); 65 $this->_updateResources(); 66 67 // put error and success messages (if any) into the view 68 if( $this->_successMessage != "" ) $this->_view->setSuccessMessage( $this->_successMessage ); 69 if( $this->_errorMessage != "" ) $this->_view->setErrorMessage( $this->_errorMessage ); 70 $this->setCommonData(); 71 72 // clear the cache 73 CacheControl::resetBlogCache( $this->_blogInfo->getId(), false ); 74 75 // better to return true if everything fine 76 return true; 77 } 78 79 /** 80 * updates resources from the list 81 */ 82 function _updateResources() 83 { 84 // Chanages the resource album field by selection 85 $resources = new GalleryResources(); 86 87 foreach( $this->_resourceIds as $resourceId ) { 88 // get the resource 89 $resource = $resources->getResource( $resourceId, $this->_blogInfo->getId()); 90 91 if( $resource ) { 92 // fire the event 93 $this->notifyEvent( EVENT_PRE_RESOURCE_UPDATE, Array( "resource" => &$resource )); 94 95 // update the resource album 96 $resource->setAlbumId( $this->_galleryAlbumId ); 97 $result = $resources->updateResource( $resource ); 98 99 if( !$result ) { 100 $this->_errorMessage .= $this->_locale->pr("error_updating_resource", $resource->getFileName())."<br/>"; 101 } 102 else { 103 $this->_totalOk++; 104 if( $this->_totalOk < 2 ) 105 $this->_successMessage .= $this->_locale->pr("resource_updated_ok", $resource->getFileName()); 106 else 107 $this->_successMessage = $this->_locale->pr("resources_updated_ok", $this->_totalOk ); 108 // fire the post event 109 $this->notifyEvent( EVENT_POST_RESOURCE_UPDATE, Array( "article" => &$post )); 110 } 111 } 112 else { 113 $this->_errorMessage .= $this->_locale->pr("error_updating_resource2", $resourceId )."<br/>"; 114 } 115 } 116 } 117 118 /** 119 * update resources from the list 120 */ 121 function _updateAlbums() 122 { 123 // Chanages the album's parent album field by selection 124 $albums = new GalleryAlbums(); 125 126 foreach( $this->_albumIds as $albumId => $value ) { 127 // get the album 128 $album = $albums->getAlbum( $albumId, $this->_blogInfo->getId()); 129 130 if( $album ) 131 { 132 // fire the event 133 $this->notifyEvent( EVENT_PRE_ALBUM_UPDATE, Array( "album" => &$album )); 134 135 // update the resource album 136 $album->setParentId( $this->_galleryAlbumId ); 137 $result = $albums->updateAlbum( $album ); 138 139 if( !$result ) { 140 $this->_errorMessage .= $this->_locale->pr("error_deleting_album", $album->getName())."<br/>"; 141 } 142 else { 143 $this->_totalOk++; 144 if( $this->_totalOk < 2 ) 145 $this->_successMessage = $this->_locale->pr("album_updated_ok", $album->getName()); 146 else 147 $this->_successMessage = $this->_locale->pr("albums_updated_ok", $this->_totalOk ); 148 // fire the post event 149 $this->notifyEvent( EVENT_POST_ALBUM_UPDATE, Array( "album" => &$album )); 150 } 151 } else { 152 $this->_errorMessage .= $this->_locale->pr( "error_updating_album2", $albumId )."<br/>"; 153 } 154 } 155 } 156 } 157 ?>
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 |
|