예제 #1
0
 public function saveCategoryChangeFieldGroup($tableBeforeSave, $table, $isNew)
 {
     if (!$isNew) {
         $db = JFactory::getDbo();
         if ($tableBeforeSave->fieldgroup_id != $table->fieldgroup_id) {
             $docId_arr = JUDownloadHelper::getDocumentIdsByCatId($table->id);
             foreach ($docId_arr as $docId) {
                 JUDownloadHelper::deleteFieldValuesOfDocument($docId);
             }
             $query = "DELETE FROM #__judownload_fields_ordering WHERE item_id = {$table->id} AND type = 'category'";
             $db->setQuery($query);
             $db->execute();
             JUDownloadHelper::changeInheritedFieldGroupId($table->id, $table->fieldgroup_id);
         }
     }
 }
예제 #2
0
 public function moveDocuments($document_id_arr, $tocat_id, $move_option_arr = array())
 {
     $dispatcher = JDispatcher::getInstance();
     $user = JFactory::getUser();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
     $catTable = JTable::getInstance("Category", "JUDownloadTable");
     if ($tocat_id) {
         if (!$catTable->load($tocat_id)) {
             JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_TARGET_CATEGORY_NOT_FOUND'));
             return false;
         }
         $table = $this->getTable();
         $db = JFactory::getDbo();
         $assetName = 'com_judownload.category.' . (int) $tocat_id;
         $query = 'SELECT id FROM #__assets WHERE name="' . $assetName . '"';
         $db->setQuery($query);
         $tocat_asset_id = $db->loadResult();
         $canCreate = $user->authorise('judl.document.create', $assetName);
         if (!$canCreate) {
             JError::raiseError(100, JText::sprintf('COM_JUDOWNLOAD_CAN_NOT_CREATE_DOCUMENT_IN_THIS_CATEGORY', $catTable->title));
             return false;
         }
     } else {
         JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_NO_TARGET_CATEGORY_SELECTED'));
         return false;
     }
     if (empty($document_id_arr)) {
         JError::raiseError(100, JText::_('COM_JUDOWNLOAD_NO_ITEM_SELECTED'));
         return false;
     }
     set_time_limit(0);
     $moved_documents = array();
     foreach ($document_id_arr as $doc_id) {
         if (!$table->load($doc_id)) {
             continue;
         }
         $assetName = 'com_judownload.document.' . (int) $doc_id;
         $canDoEdit = $user->authorise('judl.document.edit', $assetName);
         if (!$canDoEdit) {
             if (!$user->id) {
                 JError::raiseWarning(100, JText::sprintf('COM_JUDOWNLOAD_YOU_DONT_HAVE_PERMISSION_TO_ACCESS_DOCUMENT', $table->title));
                 continue;
             } else {
                 if ($user->id == $table->created_by) {
                     $canDoEditOwn = $user->authorise('judl.document.edit.own', $assetName);
                     if (!$canDoEditOwn) {
                         JError::raiseWarning(100, JText::sprintf('COM_JUDOWNLOAD_YOU_DONT_HAVE_PERMISSION_TO_ACCESS_DOCUMENT', $table->title));
                         continue;
                     }
                 }
             }
         }
         $query = "SELECT cat_id FROM #__judownload_documents_xref WHERE doc_id = " . $doc_id . " AND main=1";
         $db->setQuery($query);
         $cat_id = $db->loadResult();
         if ($tocat_id == $cat_id) {
             continue;
         }
         $result = $dispatcher->trigger($this->onContentBeforeMove, array($this->option . '.' . $this->name, $table, $tocat_id, $move_option_arr));
         if (in_array(false, $result, true)) {
             $this->setError($table->getError());
             return false;
         }
         if ($table->style_id == -1) {
             $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($cat_id);
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($tocat_id);
             if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
                 if (in_array('keep_template_params', $move_option_arr)) {
                     $table->style_id = $oldTemplateStyleObject->id;
                 } else {
                     $query = "UPDATE #__judownload_documents SET template_params = '' WHERE id=" . $doc_id;
                     $db->setQuery($query);
                     $db->execute();
                 }
             }
         }
         $query = "SELECT COUNT(*) FROM #__judownload_documents_xref WHERE cat_id=" . $tocat_id . " AND doc_id=" . $doc_id . " AND main=0";
         $db->setQuery($query);
         $is_secondary_cat = $db->loadResult();
         if ($is_secondary_cat) {
             $query = "DELETE FROM #__judownload_documents_xref WHERE doc_id=" . $doc_id . " AND main=1";
             $db->setQuery($query);
             $db->execute();
             $query = "UPDATE #__judownload_documents_xref SET main=1 WHERE cat_id=" . $tocat_id . " AND doc_id=" . $doc_id;
             $db->setQuery($query);
             $db->execute();
         } else {
             $query = "UPDATE #__judownload_documents_xref SET cat_id=" . $tocat_id . " WHERE doc_id=" . $doc_id . " AND main=1";
             $db->setQuery($query);
             $db->execute();
         }
         if (in_array('keep_permission', $move_option_arr)) {
             $query = 'UPDATE #__assets SET `parent_id` = ' . $tocat_asset_id . ' WHERE name="com_judownload.document.' . $doc_id . '"';
             $db->setQuery($query);
             $db->execute();
         } else {
             $query = 'UPDATE #__assets SET `parent_id` = ' . $tocat_asset_id . ', `rules` = "{}" WHERE name="com_judownload.document.' . $doc_id . '"';
             $db->setQuery($query);
             $db->execute();
         }
         $moved_documents[] = $doc_id;
         $this->cleanCache();
         $dispatcher->trigger($this->onContentAfterMove, array($this->option . '.' . $this->name, $table, $tocat_id, $move_option_arr));
     }
     $total_moved_documents = count($moved_documents);
     if ($total_moved_documents) {
         $old_field_groupid = JUDownloadHelper::getCategoryById($cat_id)->fieldgroup_id;
         $new_field_groupid = JUDownloadHelper::getCategoryById($tocat_id)->fieldgroup_id;
         $keep_extra_fields = in_array("keep_extra_fields", $move_option_arr);
         if ($keep_extra_fields) {
             $keep_extra_fields = $old_field_groupid == $new_field_groupid ? true : false;
         }
         if (!$keep_extra_fields) {
             foreach ($moved_documents as $doc_id) {
                 JUDownloadHelper::deleteFieldValuesOfDocument($doc_id);
             }
         }
         $old_criteria_groupid = JUDownloadHelper::getCategoryById($cat_id)->criteriagroup_id;
         $new_criteria_groupid = JUDownloadHelper::getCategoryById($tocat_id)->criteriagroup_id;
         $keep_rates = in_array("keep_rates", $move_option_arr);
         if ($keep_rates) {
             $keep_rates = $old_criteria_groupid == $new_criteria_groupid ? true : false;
         }
         if (!$keep_rates) {
             JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables");
             $ratingTable = JTable::getInstance("Rating", "JUDownloadTable");
             foreach ($moved_documents as $doc_id) {
                 $query = "SELECT id FROM #__judownload_rating WHERE doc_id = " . $doc_id;
                 $db->setQuery($query);
                 $ratingIds = $db->loadColumn();
                 foreach ($ratingIds as $ratingId) {
                     $ratingTable->delete($ratingId);
                 }
             }
         }
     }
     return $total_moved_documents;
 }
예제 #3
0
 public function deleteMainData($pk, $deleteSelf = false)
 {
     $db = JFactory::getDbo();
     JUDownloadHelper::deleteFieldValuesOfDocument($pk);
     $query = "DELETE FROM #__judownload_documents_relations WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $db->execute();
     $query = "DELETE FROM #__judownload_changelogs WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $db->execute();
     $query = "DELETE FROM #__judownload_files WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $db->execute();
     $query = "DELETE FROM #__judownload_versions WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $db->execute();
     $file_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/") . $pk . "/";
     if (JFolder::exists($file_dir)) {
         JFolder::delete($file_dir);
     }
     $query = "DELETE FROM #__judownload_documents_xref WHERE doc_id = " . $pk;
     $db->setQuery($query);
     $db->execute();
     if ($deleteSelf) {
         return parent::delete($pk);
     }
     return true;
 }