private $user_id;
public function setUserId($user_id){
$this->user_id=(int)$user_id;
}
if($oAlbums->save()){
//on force le user_id avec la propriete de notre module
$oAlbums->user_id=$this->user_id;
if($oAlbums->save()){
public function findAllByUser($user_id){
return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE user_id=?',$user_id);
}
$tAlbums=model_Albums::getInstance()->findAll();
$tAlbums=model_Albums::getInstance()->findAllByUser($this->user_id);
public function _pictures(){
$oModuleAlbums=new module_Albums;
//on initialise ici le profil à utiliser avec l'id du user connecte
$oModuleAlbums->setUserId( _root::getAuth()->getAccount()->id );
//recupere la vue du module
$oView=$oModuleAlbums->_index();
$this->oLayout->add('main',$oView);
}
<h1>Album <?php echo $this->oAlbums->name ?></h1>
<form action="" method="POST" enctype="multipart/form-data">
Choisir une photo <input type="file" name="path" /><input type="submit" value="Uploader"/>
</form>
<p><a href="<?php echo module_Albums::getLink('list')?>">Retour</a></p>
public function findListByAlbum($album_id){
return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE album_id=?',$album_id);
}
public function _show(){
$oAlbums=model_Albums::getInstance()->findById( module_Albums::getParam('id') );
$oView=new _view('Albums::show');
$oView->oAlbums=$oAlbums;
$oView->tPictures=model_Pictures::getInstance()->findListByAlbum($oAlbums->id);
if(_root::getRequest()->isPost() and isset($_FILES['path'])){
$sNewFileName='../data/upload/album_'.$oAlbums->id.'_'.date('Ymdhis');
$oPluginUpload=new plugin_upload('path');
if($oPluginUpload->isValid()){
$oPluginUpload->saveAs($sNewFileName);
$oPicture=new row_Pictures();
$oPicture->album_id=$oAlbums->id;
$oPicture->path=$oPluginUpload->getPath();
$oPicture->save();
_root::redirect('mainPrivate::pictures',array('mode'=>'show','id'=>$oAlbums->id));
}
}
return $oView;
}
<h1>Album <?php echo $this->oAlbums->name ?></h1>
<form action="" method="POST" enctype="multipart/form-data">
Choisir une photo <input type="file" name="path" /><input type="submit" value="Uploader"/>
</form>
<?php foreach($this->tPictures as $oPicture):?>
<img style="width:100px;height:100px;border:4px solid gray" src="<?php echo $oPicture->path?>" />
<?php endforeach;?>
<p><a href="<?php echo module_Albums::getLink('list')?>">Retour</a></p>
public function findListByAlbum($album_id){
return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE album_id=?',$album_id);
}
public function findListAlbumsIndexedByAlbum($album_id){
$tSharedGroup=$this->findListByAlbum($album_id);
$tIndexed=array();
foreach($tSharedGroup as $oShare){
$tIndexed[$oShare->group_id]=$oShare;
}
return $tIndexed;
}
//recuperons les groupes
$oView->tGroups=model_Groups::getInstance()->findListByUser( $this->user_id);
//recuperons les groupes avec lesquels on partage cet album
$oView->tSharedGroups=model_Share::getInstance()->findListAlbumsIndexedByAlbum( $oAlbums->id);
<script>
function hidePicture(){
var a=getById('popup');
if(a){
a.style.display='none';
}
}
function showPicture(sPath){
var a=getById('popup');
if(a){
a.style.display='block';
var b=getById('img');
if(b){
b.innerHTML='<img src="'+sPath+'"/>';
}
}
}
</script>
<h1>Album <?php echo $this->oAlbums->name ?></h1>
<form action="" method="post" enctype="multipart/form-data">
Choisir une photo <input type="file" name="path" /><input type="submit" value="Uploader"/>
</form>
<?php foreach($this->tPictures as $oPicture):?>
<a href="#" onclick="showPicture('<?php echo $oPicture->path?>');"><img style="width:100px;height:100px;border:4px solid gray" src="<?php echo $oPicture->path?>" /></a>
<?php endforeach;?>
<form action="" method="POST">
<input type="hidden" name="share" value="1"/>
<?php foreach($this->tGroups as $oGroups):?>
<input <?php if(isset($this->tSharedGroups[$oGroups->id])):?>checked="checked"<?php endif;?> type="checkbox" name="tGroup[]" value="<?php echo $oGroups->id?>"/><?php echo $oGroups->name?><br />
<?php endforeach;?>
<p><input type="submit" value="partager"/></p>
</form>
<div id="popup" style="position:absolute;display:none;border:1px solid gray;background:white">
<p style="margin:0px;background:black;text-align:right"><a style="color:white" href="#" onclick="hidePicture()" >Fermer</a></p>
<div id="img"></div>
</div>
<p><a href="<?php echo module_Albums::getLink('list')?>">Retour</a></p>
public function shareUserAlbumsWithGroups($user_id,$album_id,$tGroup_id){
//on supprime d'abord tous les partages pour les recreer ensuite
$this->execute('DELETE FROM '.$this->sTable.' WHERE user_id=? AND album_id=?',$user_id,$album_id);
if($tGroup_id){
foreach($tGroup_id as $group_id){
$oGroups=new row_Share;
$oGroups->user_id=(int)$user_id;
$oGroups->album_id=(int)$album_id;
$oGroups->group_id=(int)$group_id;
$oGroups->date=date('Y-m-d');
$oGroups->save();
}
}
}
public function _show(){
$oAlbums=model_Albums::getInstance()->findById( module_Albums::getParam('id') );
$oView=new _view('Albums::show');
$oView->oAlbums=$oAlbums;
$oView->tPictures=model_Pictures::getInstance()->findListByAlbum($oAlbums->id);
//recuperons les groupes
$oView->tGroups=model_Groups::getInstance()->findListByUser( $this->user_id);
//recuperons les groupes avec lesquels on partage cet album
$oView->tSharedGroups=model_Share::getInstance()->findListAlbumsIndexedByAlbum( $oAlbums->id);
if(_root::getRequest()->isPost() and isset($_FILES['path'])){
$sNewFileName='../data/upload/album_'.$oAlbums->id.'_'.date('Ymdhis');
$oPluginUpload=new plugin_upload('path');
if($oPluginUpload->isValid()){
$oPluginUpload->saveAs($sNewFileName);
$oPicture=new row_Pictures();
$oPicture->album_id=$oAlbums->id;
$oPicture->path=$oPluginUpload->getPath();
$oPicture->save();
_root::redirect('mainPrivate::pictures',array('mode'=>'show','id'=>$oAlbums->id));
}
}
if(_root::getParam('share')){
$tPostedGroups=_root::getParam('tGroup');
model_Share::getInstance()->shareUserAlbumsWithGroups($this->user_id,$oAlbums->id,$tPostedGroups);
self::redirect('show',array('id'=>$oAlbums->id));
}
return $oView;
}
Lire la suite : IX Profil partagé