Exemplo n.º 1
0
 public function onItemAfterSave($context, $table, $isNew)
 {
     $params = JComponentHelper::getParams('com_djcatalog2');
     $app = JFactory::getApplication();
     $data = $app->input->get('jform', array(), 'array');
     // saving additional categories
     $db = JFactory::getDbo();
     $db->setQuery('DELETE FROM #__djc2_items_categories WHERE item_id=\'' . $table->id . '\'');
     $category_limit = (int) $params->get('fed_multiple_categories_limit', 3);
     if ($db->query()) {
         if (!isset($data['categories'])) {
             $data['categories'] = array();
         }
         if ($category_limit > 0) {
             $data['categories'] = array_slice($data['categories'], 0, $category_limit);
         }
         $data['categories'][] = $table->cat_id;
         if (!empty($data['categories'])) {
             $data['categories'] = array_unique($data['categories']);
             foreach ($data['categories'] as $cat_id) {
                 if ($cat_id > 0) {
                     $db->setQuery('INSERT INTO #__djc2_items_categories VALUES (\'' . $table->id . '\', \'' . $cat_id . '\')');
                     $db->query();
                 }
             }
         }
     }
     // saving images
     if (!DJCatalog2ImageHelper::saveImages('item', $table, $params, $isNew)) {
         $app->enqueueMessage(JText::_('COM_DJCATALOG2_ERROR_SAVING_IMAGES'), 'error');
     }
     // saving attachments
     if (!DJCatalog2FileHelper::saveFiles('item', $table, $params, $isNew)) {
         $app->enqueueMessage(JText::_('COM_DJCATALOG2_ERROR_SAVING_FILES'), 'error');
     }
     // saving additional attributes
     $attribs = $app->input->get('attribute', array(), 'array');
     $model = JModelAdmin::getInstance('Itemform', 'Djcatalog2Model', array());
     if (!$model->saveAttributes($attribs, $table)) {
         $app->enqueueMessage($model->getError(), 'error');
     }
 }
Exemplo n.º 2
0
 public function onItemAfterSave($context, $table, $isNew)
 {
     $params = JComponentHelper::getParams('com_djcatalog2');
     $app = JFactory::getApplication();
     $data = $app->input->get('jform', array(), 'array');
     $task = $app->input->getCmd('task');
     // saving additional categories
     $db = JFactory::getDbo();
     if ($task == 'import') {
         if ($table->cat_id > 0) {
             $db->setQuery('DELETE FROM #__djc2_items_categories WHERE category_id=\'' . $table->cat_id . '\' AND item_id=\'' . $table->id . '\'');
             if ($db->query()) {
                 $db->setQuery('INSERT INTO #__djc2_items_categories VALUES (\'' . $table->id . '\', \'' . $table->cat_id . '\')');
                 $db->query();
             }
         }
     } else {
         $db->setQuery('DELETE FROM #__djc2_items_categories WHERE item_id=\'' . $table->id . '\'');
         if ($db->query()) {
             if (!isset($data['categories'])) {
                 $data['categories'] = array();
             }
             $data['categories'][] = $table->cat_id;
             if (!empty($data['categories'])) {
                 JArrayHelper::toInteger($data['categories']);
                 $data['categories'] = array_unique($data['categories']);
                 foreach ($data['categories'] as $cat_id) {
                     $db->setQuery('INSERT INTO #__djc2_items_categories VALUES (\'' . $table->id . '\', \'' . $cat_id . '\')');
                     $db->query();
                 }
             }
         }
     }
     if (!isset($data['group_id']) || !is_array($data['group_id'])) {
         $data['group_id'] = array();
     }
     $data['group_id'][] = 0;
     JArrayHelper::toInteger($data['group_id']);
     $data['group_id'] = array_unique($data['group_id']);
     if ($task == 'import') {
         $db->setQuery('DELETE FROM #__djc2_items_groups WHERE item_id=\'' . $table->id . '\' AND group_id IN (' . implode(',', $data['group_id']) . ')');
     } else {
         $db->setQuery('DELETE FROM #__djc2_items_groups WHERE item_id=\'' . $table->id . '\'');
     }
     if ($db->query()) {
         foreach ($data['group_id'] as $group_id) {
             $db->setQuery('INSERT INTO #__djc2_items_groups VALUES (\'' . $table->id . '\', \'' . $group_id . '\')');
             $db->query();
         }
     }
     // saving images
     if (!DJCatalog2ImageHelper::saveImages('item', $table, $params, $isNew)) {
         $app->enqueueMessage(JText::_('COM_DJCATALOG2_ERROR_SAVING_IMAGES'), 'error');
     }
     // saving attachments
     if (!DJCatalog2FileHelper::saveFiles('item', $table, $params, $isNew)) {
         $app->enqueueMessage(JText::_('COM_DJCATALOG2_ERROR_SAVING_FILES'), 'error');
     }
     // saving additional attributes
     $attribs = $app->input->get('attribute', array(), 'array');
     $model = JModelAdmin::getInstance('Item', 'Djcatalog2Model', array());
     if (!$model->saveAttributes($attribs, $table)) {
         $app->enqueueMessage($model->getError(), 'error');
     }
 }