예제 #1
0
 public function delete($pk = null)
 {
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     if (parent::delete($pk)) {
         $db = JFactory::getDbo();
         $query = "DELETE FROM #__judownload_criterias_values WHERE rating_id = {$pk}";
         $db->setQuery($query);
         $db->execute();
         JUDownloadHelper::deleteLogs('rating', $pk);
         return true;
     }
     return false;
 }
예제 #2
0
 protected function _delete($comment)
 {
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
     $db = $this->_db;
     $query = "DELETE FROM #__judownload_subscriptions WHERE item_id = " . $comment->id . " AND type = 'comment'";
     $db->setQuery($query);
     $db->execute();
     $query = "DELETE FROM #__judownload_reports WHERE item_id = " . $comment->id . " AND type = 'comment'";
     $db->setQuery($query);
     $db->execute();
     $query = "SELECT r.id FROM #__judownload_rating AS r JOIN #__judownload_comments AS cm ON r.id = cm.rating_id WHERE cm.id = " . $comment->id;
     $db->setQuery($query);
     $ratingIds = $db->loadColumn();
     if ($ratingIds) {
         $ratingTable = JTable::getInstance("Rating", "JUDownloadTable");
         foreach ($ratingIds as $ratingId) {
             $ratingTable->delete($ratingId);
         }
     }
     if ($comment->parent_id == 0 && $comment->approved == 1) {
         $query = "SELECT SUM(score) AS total_ratings, COUNT(*) AS total_votes FROM #__judownload_rating AS rating LEFT JOIN #__judownload_comments AS comment ON (comment.rating_id = rating.id AND comment.approved = 1) WHERE rating.doc_id = " . $comment->doc_id;
         $db->setQuery($query);
         $score = $db->loadObject();
         $document_table = JTable::getInstance("Document", "JUDownloadTable");
         if ($document_table->load($comment->doc_id)) {
             if ($score->total_votes > 0) {
                 $document_table->rating = (double) $score->total_ratings / $score->total_votes;
             } else {
                 $document_table->rating = 0;
             }
             $document_table->total_votes = $score->total_votes;
             $document_table->store();
         }
     }
     $query = "DELETE FROM #__judownload_mailqs\r\n\t\t\t      WHERE item_id =" . $comment->id . "\r\n\t\t\t\t\t\tAND email_id IN (SELECT id FROM #__judownload_emails WHERE (`event` LIKE 'comment.%' and `event` != 'comment.delete'))";
     $db->setQuery($query);
     $db->execute();
     JUDownloadHelper::deleteLogs('comment', $comment->id);
     return true;
 }
예제 #3
0
 public function delete(&$pks)
 {
     $dispatcher = JDispatcher::getInstance();
     $pks = (array) $pks;
     $table = $this->getTable();
     JPluginHelper::importPlugin('content');
     $modelDocument = JModelLegacy::getInstance('Document', 'JUDownloadModel');
     $documentTable = JTable::getInstance("Document", "JUDownloadTable");
     $canDeleteCatIds = $canNotDeleteCatIds = $canDeleteDocIds = $canNotDeleteDocIds = array();
     $db = JFactory::getDbo();
     while (!empty($pks)) {
         $pk = array_shift($pks);
         $table->reset();
         if ($table->load($pk)) {
             $deleteCurrentCat = true;
             if ($this->canDelete($table)) {
                 $query = $db->getQuery(true);
                 $query->SELECT('doc_id');
                 $query->FROM('#__judownload_documents_xref');
                 $query->WHERE('cat_id=' . $pk . ' AND main=1');
                 $db->setQuery($query);
                 $docIds = $db->loadColumn();
                 if ($docIds) {
                     foreach ($docIds as $docId) {
                         $documentTable->reset();
                         if ($documentTable->load($docId)) {
                             if ($modelDocument->canDelete($documentTable)) {
                                 $canDeleteDocIds[] = $docId;
                             } else {
                                 $canNotDeleteDocIds[] = $docId;
                                 $deleteCurrentCat = false;
                             }
                         }
                     }
                 }
             } else {
                 $deleteCurrentCat = false;
             }
             if (!$deleteCurrentCat) {
                 $canNotDeleteCatIds[] = $pk;
             } else {
                 $canDeleteCatIds[] = $pk;
             }
             $query = $db->getQuery(true);
             $query->select('id');
             $query->from('#__judownload_categories');
             $query->where('lft > ' . (int) $table->lft);
             $query->where('rgt < ' . (int) $table->rgt);
             $query->order('lft');
             $db->setQuery($query);
             $childIds = $db->loadColumn();
             foreach ($childIds as $childId) {
                 if (!in_array($childId, $pks)) {
                     array_push($pks, $childId);
                 }
             }
         }
     }
     if ($canNotDeleteCatIds) {
         foreach ($canNotDeleteCatIds as $caNotDeleteCatId) {
             $categories = $table->getPath($caNotDeleteCatId);
             if ($categories) {
                 foreach ($categories as $category) {
                     $canDeleteCatIdIndex = array_search($category->id, $canDeleteCatIds);
                     if ($canDeleteCatIdIndex !== false) {
                         unset($canDeleteCatIds[$canDeleteCatIdIndex]);
                         $canNotDeleteCatIds[] = $category->id;
                     }
                 }
             }
         }
     }
     $canDeleteDocIds = array_unique($canDeleteDocIds);
     if ($canDeleteDocIds) {
         foreach ($canDeleteDocIds as $docId) {
             if (!$documentTable->delete($docId)) {
                 $this->setError($documentTable->getError());
                 return false;
             }
         }
     }
     $canDeleteCatIds = array_unique($canDeleteCatIds);
     if ($canDeleteCatIds) {
         foreach ($canDeleteCatIds as $pk) {
             if ($table->load($pk)) {
                 $context = $this->option . '.' . $this->name;
                 $result = $dispatcher->trigger($this->event_before_delete, array($context, $table));
                 if (in_array(false, $result, true)) {
                     $this->setError($table->getError());
                     return false;
                 }
                 if (!$table->delete($pk, false)) {
                     $this->setError($table->getError());
                     return false;
                 } else {
                     $query = "DELETE FROM #__judownload_categories_relations WHERE cat_id=" . $pk;
                     $db->setQuery($query);
                     $db->execute();
                     $query = "DELETE FROM #__judownload_documents_xref WHERE main=0 AND cat_id=" . $pk;
                     $db->setQuery($query);
                     $db->execute();
                     $query = "SELECT mod_id FROM #__judownload_moderators_xref WHERE cat_id = " . $pk;
                     $db->setQuery($query);
                     $moderatorIds = $db->loadColumn();
                     $query = "DELETE FROM #__judownload_moderators_xref WHERE cat_id=" . $pk;
                     $db->setQuery($query);
                     $db->execute();
                     if ($moderatorIds) {
                         $modTable = JTable::getInstance("Moderator", "JUDownloadTable");
                         foreach ($moderatorIds as $moderatorId) {
                             $query = $db->getQuery(true);
                             $query->select('COUNT(*)');
                             $query->from('#__judownload_moderators AS m');
                             $query->join('', '#__judownload_moderators_xref AS mxref ON m.id = mxref.mod_id');
                             $query->where('m.id =' . $moderatorId);
                             $db->setQuery($query);
                             $totalModeratedCats = $db->loadResult();
                             if ($totalModeratedCats <= 0) {
                                 $modTable->reset();
                                 if ($modTable->load(array($moderatorId))) {
                                     $modTable->delete();
                                 }
                             }
                         }
                     }
                     $images = json_decode($table->images);
                     if (is_object($images)) {
                         if ($images->intro_image) {
                             $intro_image = JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/') . $images->intro_image;
                             $ori_intro_image = JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/') . "original/" . $images->intro_image;
                             if (JFile::exists(JPATH_ROOT . "/" . $ori_intro_image)) {
                                 JFile::delete(JPATH_ROOT . "/" . $ori_intro_image);
                             }
                             if (JFile::exists(JPATH_ROOT . "/" . $intro_image)) {
                                 JFile::delete(JPATH_ROOT . "/" . $intro_image);
                             }
                         }
                         if ($images->detail_image) {
                             $detail_image = JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/') . $images->detail_image;
                             $ori_detail_image = JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/') . "original/" . $images->detail_image;
                             if (JFile::exists(JPATH_ROOT . "/" . $detail_image)) {
                                 JFile::delete(JPATH_ROOT . "/" . $detail_image);
                             }
                             if (JFile::exists(JPATH_ROOT . "/" . $ori_detail_image)) {
                                 JFile::delete(JPATH_ROOT . "/" . $ori_detail_image);
                             }
                         }
                     }
                     if ($table->level == 0 || $table->level == 1) {
                         $query = "DELETE FROM #__judownload_emails_xref WHERE cat_id = " . $table->id;
                         $db->setQuery($query);
                         $db->execute();
                     }
                     JUDownloadHelper::deleteLogs('category', $pk);
                     $query = "DELETE FROM #__judownload_fields_ordering WHERE `item_id` = " . $table->id . " AND `type` = 'category'";
                     $db->setQuery($query);
                     $db->execute();
                     $dispatcher->trigger($this->event_after_delete, array($context, $table));
                 }
             }
         }
     }
     if ($canDeleteCatIds) {
         $app = JFactory::getApplication();
         $app->enqueueMessage(JText::plural('COM_JUDOWNLOAD_CATEGORIES_N_ITEMS_DELETED', count($canDeleteCatIds)));
     }
     $canNotDeleteCatIds = array_unique($canNotDeleteCatIds);
     if ($canNotDeleteCatIds) {
         JError::raiseWarning(500, JText::plural('COM_JUDOWNLOAD_CATEGORIES_N_ITEMS_NOT_DELETED', count($canNotDeleteCatIds)));
     }
     $this->cleanCache();
     return true;
 }
예제 #4
0
 public function delete($pk = null)
 {
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     $db = JFactory::getDbo();
     $query = "DELETE FROM #__judownload_subscriptions WHERE item_id = {$pk} AND type = 'document'";
     $db->setQuery($query);
     $db->execute();
     $query = "SELECT * FROM #__judownload_comments WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $commentIds = $db->loadColumn();
     if ($commentIds) {
         $commentTable = JTable::getInstance("Comment", "JUDownloadTable");
         foreach ($commentIds as $commentId) {
             $commentTable->delete($commentId);
         }
     }
     $query = "SELECT id FROM #__judownload_rating WHERE doc_id = {$pk}";
     $db->setQuery($query);
     $ratingItemIds = $db->loadColumn();
     if ($ratingItemIds) {
         $ratingTable = JTable::getInstance("Rating", "JUDownloadTable");
         foreach ($ratingItemIds as $ratingItemId) {
             $ratingTable->delete($ratingItemId);
         }
     }
     $query = "DELETE FROM #__judownload_reports WHERE item_id = {$pk} AND type = 'document'";
     $db->setQuery($query);
     $db->execute();
     $query = "SELECT id FROM #__judownload_collections_items WHERE doc_id = {$pk}";
     $db->setQuery($query);
     $collectionItemIds = $db->loadColumn();
     if ($collectionItemIds) {
         $collectionItemTable = JTable::getInstance("CollectionItem", "JUDownloadTable");
         foreach ($collectionItemIds as $collectionItemId) {
             $collectionItemTable->delete($collectionItemId);
         }
     }
     JUDownloadHelper::deleteLogs('document', $pk);
     $query = "DELETE FROM #__judownload_mailqs\r\n\t\t\t      WHERE item_id =" . $pk . "\r\n\t\t\t\t\t\tAND email_id IN (SELECT id FROM #__judownload_emails WHERE (`event` LIKE 'document.%' AND `event` != 'document.delete'))";
     $db->setQuery($query);
     $db->execute();
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from('#__judownload_documents');
     $query->where('approved=' . -$pk);
     $db->setQuery($query);
     $tempDocIds = $db->loadColumn();
     if (count($tempDocIds)) {
         foreach ($tempDocIds as $tempDocId) {
             $this->deleteMainData($tempDocId, true);
         }
     }
     $cat_id = JUDownloadFrontHelperCategory::getMainCategoryId($this->id);
     $this->deleteMainData($pk);
     if (parent::delete($pk)) {
         $app = JFactory::getApplication();
         if ($app->isSite()) {
             $registry = new JRegistry();
             $registry->loadObject($this);
             $mailData = $registry->toArray();
             $mailData['cat_id'] = $cat_id;
             if ($this->approved < 1) {
                 JUDownloadFrontHelperMail::sendEmailByEvent('document.reject', $this->id, $mailData);
             } else {
                 JUDownloadFrontHelperMail::sendEmailByEvent('document.delete', $this->id, $mailData);
             }
         }
         return true;
     } else {
         return false;
     }
 }