Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/controller/groupcontroller.ctrl.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

class GroupController extends Controller {

public function __construct($model, $controller, $action){
Expand Down Expand Up @@ -319,12 +319,25 @@ public function edit($id) {

public function delete($id){
if(hasRole($this->user, 'Administrator')){

$group = $this->Group->findOne($id);
$wpId = $group->wordpress_post_id;

$r = $this->Group->delete($id);
echo 'test';
$groupModel = new Group;
$imgDelete = $groupModel->deleteImage($id);

if(!$r){
$response = 'd:err';
}
else {
$response = 'd:ok';

$wpClient = new \HieuLe\WordpressXmlrpcClient\WordpressClient();
$wpClient->setCredentials(WP_XMLRPC_ENDPOINT, WP_XMLRPC_USER, WP_XMLRPC_PSWD);

$deletion = $wpClient->deletePost($wpId);
}
header('Location: /group/index/' . $response);
}
Expand Down
33 changes: 28 additions & 5 deletions app/model/group.model.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ public function findHost($id){
$stmt = $this->database->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();



return $stmt->fetch(PDO::FETCH_OBJ);
}

Expand All @@ -144,9 +141,35 @@ public function ofThisUser($id){
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();



return $stmt->fetchAll(PDO::FETCH_OBJ);
}

public function numberofParties($id){
$sql = 'SELECT COUNT(*) AS numParties FROM `events` WHERE `group`= :id';
$stmt = $this->database->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
$p = $stmt->fetchObject();
return $p->numParties;

}

public function deleteImage($id){
$sql = 'SELECT * FROM `images`
INNER JOIN `xref` ON `xref`.`object` = `images`.`idimages`
WHERE `xref`.`object_type` = 5 AND `xref`.`reference` = :id
AND `xref`.`reference_type` = 2
GROUP BY `images`.`path`';

$stmt = $this->database->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
$image = $stmt->fetchObject();

$mid_filePath = UPLOADS_URL .'mid_'.$image->path;
$thumbnail_filePath = UPLOADS_URL .'thumbnail_'.$image->path;

$midPath = unlink($mid_filePath);
$thumbnailPath = unlink($thumbnail_filePath);
}
}
10 changes: 9 additions & 1 deletion app/view/group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,27 @@
<?php } ?>
</tr>
</thead>

<tbody>
<?php foreach($list as $g){ ?>
<tr>
<td><?php echo $g->id; ?></td>
<?php
$Group = new Group;
$numberofParties = $Group->numberofParties($g->id);
?>
<td><a href="/group/edit/<?php echo $g->id; ?>" title="edit group"><?php echo $g->name; ?></a></td>
<td><?php echo $g->location . ', ' . $g->area; ?></td>
<td><?php echo $g->frequency; ?> <?php _t("Parties/Year");?></td>
<td><?php echo $g->user_list; ?></td>
<?php if(hasRole($user, 'Administrator')){ ?>
<td><a href="/group/edit/<?php echo $g->id; ?>"><i class="fa fa-pencil"></i></a></td>

<?php if($numberofParties == 0){?>
<td><a href="/group/delete/<?php echo $g->id; ?>" class="delete-control"><i class="fa fa-trash"></i></a></td>
<?php } ?>

<?php } ?>
</tr>
<?php } ?>
</tbody>
Expand Down
3 changes: 1 addition & 2 deletions lib/model.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

/** Main Model Class
* exposes the $database var (PDO OBject)
* to model classes that extend it
Expand Down Expand Up @@ -173,7 +173,6 @@ public function delete($id){
if(!is_numeric($id)){
new Error(620, 'Invalid parameter. (model.class.php, 168)');
return false;

}
else {
$sql = 'DELETE FROM `' . $this->table . '` WHERE `id' . $this->table . '` = :id';
Expand Down