From 30858802f583068656f6ebd85e45bfa32a4d211b Mon Sep 17 00:00:00 2001 From: NikhitaPaturu Date: Tue, 22 May 2018 16:48:11 +0100 Subject: [PATCH] WIP: delete the logos from db --- app/controller/groupcontroller.ctrl.php | 15 ++++++++++- app/model/group.model.php | 33 +++++++++++++++++++++---- app/view/group/index.php | 10 +++++++- lib/model.class.php | 3 +-- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/app/controller/groupcontroller.ctrl.php b/app/controller/groupcontroller.ctrl.php index 8a0b44b9..21f6012c 100644 --- a/app/controller/groupcontroller.ctrl.php +++ b/app/controller/groupcontroller.ctrl.php @@ -1,5 +1,5 @@ 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); } diff --git a/app/model/group.model.php b/app/model/group.model.php index c5d0171a..d8a49810 100644 --- a/app/model/group.model.php +++ b/app/model/group.model.php @@ -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); } @@ -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); + } } diff --git a/app/view/group/index.php b/app/view/group/index.php index 6ac1bbe4..457d542a 100644 --- a/app/view/group/index.php +++ b/app/view/group/index.php @@ -18,19 +18,27 @@ - + id; ?> + numberofParties($g->id); + ?> name; ?> location . ', ' . $g->area; ?> frequency; ?> user_list; ?> + + + + diff --git a/lib/model.class.php b/lib/model.class.php index b7d599c5..2ed2ae2f 100644 --- a/lib/model.class.php +++ b/lib/model.class.php @@ -1,5 +1,5 @@ table . '` WHERE `id' . $this->table . '` = :id';