private $user_id;
public function setUserId($user_id){
$this->user_id=(int)$user_id;
}
if($oPosts->save()){
$oPosts->date=date('Y-m-d');
$oPosts->time=date('H:i:s');
$oPosts->user_id=$this->user_id;
if($oPosts->save()){
public function findListByUser($user_id){
return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE user_id=?',$user_id);
}
$tPosts=model_Posts::getInstance()->findAll();
$tPosts=model_Posts::getInstance()->findListByUser($this->user_id);
public function _posts(){
$oView=new _view('mainPrivate::posts');
$this->oLayout->add('main',$oView);
}
public function _posts(){
$oModulePosts=new module_Posts;
$oModulePosts->setUserId( _root::getAuth()->getAccount()->id );
//recupere la vue du module
$oView=$oModulePosts->_new();
//assigner la vue retournee a votre layout
$this->oLayout->add('main',$oView);
//recupere la vue du module
$oView=$oModulePosts->_list();
//assigner la vue retournee a votre layout
$this->oLayout->add('main',$oView);
}
$oView->tGroups=model_Groups::getInstance()->findListByUser( $this->user_id);
public function _new(){
$tMessage=$this->processSave();
$oPosts=new row_Posts;
$oView=new _view('Posts::new');
$oView->oPosts=$oPosts;
$oView->tGroups=model_Groups::getInstance()->findListByUser( $this->user_id);
$oPluginXsrf=new plugin_xsrf();
$oView->token=$oPluginXsrf->getToken();
$oView->tMessage=$tMessage;
return $oView;
}
<?php $oPluginHtml=new plugin_html?>
<form action="" method="POST" >
<input type="hidden" name="formmodule" value="Posts" />
<table class="tb_new">
<tr>
<th>title</th>
<td><input name="title" /><?php if($this->tMessage and isset($this->tMessage['title'])): echo implode(',',$this->tMessage['title']); endif;?></td>
</tr>
<tr>
<th>body</th>
<td><textarea name="body"></textarea><?php if($this->tMessage and isset($this->tMessage['body'])): echo implode(',',$this->tMessage['body']); endif;?></td>
</tr>
</table>
<?if($this->tGroups):?>
<?php foreach($this->tGroups as $oGroups):?>
<input type="checkbox" name="tGroup_id[]" value="<?php echo $oGroups->id?>"/> <?php echo $oGroups->name ?><br />
<?php endforeach;?>
<?php endif;?>
<input type="hidden" name="token" value="<?php echo $this->token?>" />
<?php if($this->tMessage and isset($this->tMessage['token'])): echo $this->tMessage['token']; endif;?>
<input type="submit" value="Ajouter" /> <a href="<?php echo module_Posts::getLink('list')?>">Annuler</a>
</form>
public function shareUserPostWithGroups($user_id,$post_id,$tGroup_id){
if($tGroup_id){
foreach($tGroup_id as $group_id){
$oGroups=new row_Share;
$oGroups->user_id=(int)$user_id;
$oGroups->post_id=(int)$post_id;
$oGroups->group_id=(int)$group_id;
$oGroups->date=date('Y-m-d');
$oGroups->save();
}
}
}
$oPosts->date=date('Y-m-d');
$oPosts->time=date('H:i:s');
$oPosts->user_id=$this->user_id;
if($oPosts->save()){
$oPosts->date=date('Y-m-d');
$oPosts->time=date('H:i:s');
$oPosts->user_id=$this->user_id;
if($oPosts->save()){
//partage du post avec les groups
model_Share::getInstance()->shareUserPostWithGroups($this->user_id,$oPosts->id,_root::getParam('tGroup_id'));
public function findListByUser($user_id){
return $this->findMany('SELECT * FROM '.$this->sTable.' WHERE user_id=?',$user_id);
}
public function findListByUser($user_id){
return $this->findMany('
SELECT distinct Posts.*
FROM Posts, Share, UsersGroup
WHERE
Posts.id = Share.post_id
AND UsersGroup.group_id = Share.group_id
AND (Share.user_id = ? OR UsersGroup.user_id = ?)
',$user_id,$user_id
);
}
public function getListIndexed(){
$tUsers=$this->findAll();
$tIndexed=array();
foreach($tUsers as $oUser){
$tIndexed[$oUser->id]=$oUser;
}
return $tIndexed;
}
public function _list(){
$tPosts=model_Posts::getInstance()->findListByUser($this->user_id);
$oView=new _view('Posts::list');
$oView->tPosts=$tPosts;
$oView->tIndexdUsers=model_Users::getInstance()->getListIndexed();
return $oView;
}
<hr/>
<?php if($this->tPosts):?>
<?php foreach($this->tPosts as $oPosts):?>
<div>
<div style="float:right;padding:5px;border:2px solid gray;border-radius: 5px;width:400px">
<h1 style="text-align:right"><?php echo $oPosts->title ?></h1>
<p style="font-style:italic;margin:0px;text-align:right">le <?php echo $oPosts->date ?> à <?php echo $oPosts->time ?> </p>
<p><?php echo $oPosts->body ?></p>
</div>
<div style="float:right;margin-right:10px;text-align:right">
<h1><?php echo $this->tIndexdUsers[$oPosts->user_id]->firstname ?> <?php echo $this->tIndexdUsers[$oPosts->user_id]->lastname ?></h1>
<img style="width:50px" src="<?php echo $this->tIndexdUsers[$oPosts->user_id]->profilPicture ?>"/>
</div>
<div style="clear:both"></div>
</div>
<?php endforeach;?>
<?php endif;?>
<?php $oPluginHtml=new plugin_html?>
<form action="" method="POST" >
<input type="hidden" name="formmodule" value="Posts" />
<div style="margin-bottom:10px;float:right;padding:5px;border:2px solid gray;border-radius: 5px;width:400px">
<div>
Titre<br/>
<input style="width:100%;border:1px solid gray" name="title" /><?php if($this->tMessage and isset($this->tMessage['title'])): echo implode(',',$this->tMessage['title']); endif;?></td>
</div>
<div>
Message<br/>
<textarea name="body" style="width:100%;height:50px;border:1px solid gray"></textarea><?php if($this->tMessage and isset($this->tMessage['body'])): echo implode(',',$this->tMessage['body']); endif;?></td>
</div>
<?if($this->tGroups):?>
<?php foreach($this->tGroups as $oGroups):?>
<input type="checkbox" name="tGroup_id[]" value="<?php echo $oGroups->id?>"/> <?php echo $oGroups->name ?><br />
<?php endforeach;?>
<?php endif;?>
<input type="hidden" name="token" value="<?php echo $this->token?>" />
<?php if($this->tMessage and isset($this->tMessage['token'])): echo $this->tMessage['token']; endif;?>
<p style="text-align:right"><input type="submit" value="Ajouter" /></p>
</div>
<div style="clear:both"></div>
</form>
Lire la suite : VIII Partie privée : administrez vos photos