Example #1
0
 public function delete($pk = null)
 {
     $db = JFactory::getDbo();
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     $this->load($pk);
     if ($this->home == 1 || $this->default == 1) {
         $this->setError(JText::_('COM_JUDIRECTORY_CAN_NOT_DELETE_DEFAULT_TEMPLATE_STYLE'));
         return false;
     }
     $defaultStyleObject = JUDirectoryFrontHelperTemplate::getDefaultTemplateStyle();
     $query = $db->getQuery(true);
     $query->update('#__judirectory_categories');
     $query->set('style_id = -2');
     if ($defaultStyleObject->template_id != $this->template_id) {
         $query->set('template_params = ""');
     }
     $query->where('parent_id = 0');
     $query->where('style_id = ' . $pk);
     $db->setQuery($query);
     $db->execute();
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from('#__judirectory_categories');
     $query->where('style_id = ' . $pk);
     $db->setQuery($query);
     $categoryArrayAssignedToStyle = $db->loadColumn();
     $query = $db->getQuery(true);
     $query->update('#__judirectory_categories');
     $query->set('style_id = -1');
     $query->where('parent_id != 0');
     $query->where('style_id = ' . $pk);
     $db->setQuery($query);
     $db->execute();
     foreach ($categoryArrayAssignedToStyle as $categoryIdAssignedToStyle) {
         $styleObjectOfCategory = JUDirectoryFrontHelperTemplate::getTemplateStyleOfCategory($categoryIdAssignedToStyle);
         if ($styleObjectOfCategory->template_id != $this->template_id) {
             $query = $db->getQuery(true);
             $query->update('#__judirectory_categories');
             $query->set('template_params = ""');
             $query->where('id = ' . $categoryIdAssignedToStyle);
             $db->setQuery($query);
             $db->execute();
             $query = $db->getQuery(true);
             $query->update('#__judirectory_listings AS listing');
             $query->set('listing.template_params = ""');
             $query->join('', '#__judirectory_listings_xref AS listingxref ON listing.id = listingxref.listing_id AND listingxref.main = 1');
             $query->where('listing.style_id = -1');
             $query->where('listingxref.cat_id = ' . $categoryIdAssignedToStyle);
             $db->setQuery($query);
             $db->execute();
             JUDirectoryFrontHelperTemplate::removeTemplateParamsOfInheritedStyleCatListing($categoryIdAssignedToStyle);
         }
     }
     $query = $db->getQuery(true);
     $query->select('listing.id');
     $query->select('listingxref.cat_id AS cat_id');
     $query->from('#__judirectory_listings AS listing');
     $query->join('', '#__judirectory_listings_xref AS listingxref ON listing.id = listingxref.listing_id AND listingxref.main = 1');
     $query->where('listing.style_id = ' . $pk);
     $db->setQuery($query);
     $listingObjectListAssignedToStyle = $db->loadObjectList();
     $catArrayResetTemplateParams = array();
     foreach ($listingObjectListAssignedToStyle as $listingObject) {
         $styleObjectOfCategory = JUDirectoryFrontHelperTemplate::getTemplateStyleOfCategory($listingObject->cat_id);
         if ($styleObjectOfCategory->template_id != $this->template_id) {
             $catArrayResetTemplateParams[] = $listingObject->cat_id;
         }
     }
     $catArrayResetTemplateParams = array_unique($catArrayResetTemplateParams);
     if (is_array($catArrayResetTemplateParams) && count($catArrayResetTemplateParams)) {
         $query = $db->getQuery(true);
         $query->update('#__judirectory_listings AS listing');
         $query->join('', '#__judirectory_listings_xref AS listingxref ON listing.id = listingxref.listing_id AND listingxref.main = 1');
         $query->set('listing.template_params = ""');
         $query->set('listing.style_id = -1');
         $query->where('listingxref.cat_id IN (' . implode(',', $catArrayResetTemplateParams) . ')');
         $query->where('listing.style_id = ' . $pk);
         $db->setQuery($query);
         $db->execute();
     }
     return parent::delete($pk);
 }
Example #2
0
 public function moveCats($cat_id_arr, $tocat_id, $move_option_arr)
 {
     $tocat_id = (int) $tocat_id;
     $cat_id_arr = (array) $cat_id_arr;
     if (empty($cat_id_arr)) {
         JError::raiseWarning(100, JText::_('COM_JUDIRECTORY_NO_SOURCE_CATEGORY_SELECTED'));
         return false;
     }
     if (empty($tocat_id)) {
         JError::raiseWarning(100, JText::_('COM_JUDIRECTORY_NO_TARGET_CATEGORY_SELECTED'));
         return false;
     }
     $user = JFactory::getUser();
     $table = $this->getTable();
     if (!$table->load($tocat_id)) {
         JError::raiseWarning(500, JText::_('COM_JUDIRECTORY_TARGET_CATEGORY_NOT_FOUND'));
         return false;
     }
     $assetName = 'com_judirectory.category.' . (int) $tocat_id;
     $candoCreate = $user->authorise('judir.category.create', $assetName);
     if (!$candoCreate) {
         JError::raiseError(100, JText::sprintf('COM_JUDIRECTORY_CAN_NOT_CREATE_CATEGORY_IN_CATEGORY_X', $table->title));
         return false;
     }
     set_time_limit(0);
     $total_moved_categories = 0;
     foreach ($cat_id_arr as $cat_id) {
         if (!$table->load($cat_id, true)) {
             continue;
         }
         $assetName = 'com_judirectory.category.' . (int) $cat_id;
         $candoEdit = $user->authorise('judir.category.edit', $assetName);
         if (!$candoEdit) {
             JError::raiseWarning(100, JText::_('COM_JUDIRECTORY_YOU_DONT_HAVE_PERMISSION_TO_EDIT_CAT'));
             continue;
         }
         if ($this->isChildCategory($cat_id, $tocat_id) || $tocat_id == $table->parent_id) {
             continue;
         }
         $table->setLocation($tocat_id, 'last-child');
         if (in_array('keep_extra_fields', $move_option_arr)) {
             if ($table->selected_fieldgroup == -1) {
                 $tocat_obj = JUDirectoryHelper::getCategoryByID($tocat_id);
                 if ($table->fieldgroup_id != $tocat_obj->fieldgroup_id) {
                     $table->selected_fieldgroup = $table->fieldgroup_id;
                 }
             }
         } else {
             if ($table->fieldgroup_id != 0) {
                 JUDirectoryHelper::changeInheritedFieldGroupId($table->id, 0);
                 $query = "DELETE FROM #__judirectory_fields_ordering WHERE `item_id` = " . $table->id . " AND `type` = 'category'";
                 $db = JFactory::getDbo();
                 $db->setQuery($query);
                 $db->execute();
             }
             $table->selected_fieldgroup = $table->fieldgroup_id = 0;
         }
         if (in_array('keep_rates', $move_option_arr)) {
             if ($table->selected_criteriagroup == -1) {
                 $tocat_obj = JUDirectoryHelper::getCategoryByID($tocat_id);
                 if ($table->criteriagroup_id != $tocat_obj->criteriagroup_id) {
                     $table->selected_criteriagroup = $table->criteriagroup_id;
                 }
             }
         } else {
             $table->selected_criteriagroup = $table->criteriagroup_id = 0;
             JUDirectoryHelper::changeInheritedCriteriagroupId($table->id, $table->criteriagroup_id);
         }
         if ($table->style_id == -1) {
             if ($table->parent_id != $tocat_id) {
                 $oldTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleOfCategory($table->id);
                 $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::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 {
                         $table->template_params = '';
                         JUDirectoryFrontHelperTemplate::removeTemplateParamsOfInheritedStyleCatListing($table->id);
                     }
                 }
             }
         }
         if ($table->store()) {
             $total_moved_categories++;
         }
     }
     return $total_moved_categories;
 }