コード例 #1
0
 public function duplicate($pk)
 {
     $app = JFactory::getApplication();
     $db = $this->getDbo();
     $title = $app->input->getString('duplicate_title', '');
     $user = JFactory::getUser();
     if (!$user->authorise('core.create', COM_CCK)) {
         throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
     }
     $table = $this->getTable();
     $table->load($pk, true);
     if ($table->id) {
         $table->id = 0;
         if ($title) {
             $table->title = $title;
         } else {
             $table->title .= ' (2)';
         }
         $table->name = '';
         if (!$table->check()) {
             throw new Exception($table->getError());
         }
         $prefix = JCck::getConfig_Param('development_prefix', '');
         if ($prefix) {
             $table->name = $prefix . '_' . $table->name;
         }
         // Template Styles
         $clients = array('search', 'filter', 'list', 'item');
         $styles = JCckDatabase::loadObjectList('SELECT * FROM #__template_styles WHERE id IN (' . (int) $table->template_search . ',' . (int) $table->template_filter . ',' . (int) $table->template_list . ',' . (int) $table->template_item . ')', 'id');
         foreach ($clients as $client) {
             $property = 'template_' . $client;
             $style = $styles[$table->{$property}];
             if (!(is_object($style) && $style->id)) {
                 $style = Helper_Workshop::getDefaultStyle($client == 'list' ? 'seb_table' : 'seb_one');
             }
             $table->{$property} = Helper_Workshop::getTemplateStyleInstance($style->id, $style->template, $style->template, $style->params, $table->name . ' (' . $client . ')', true);
         }
         if (!$table->store()) {
             throw new Exception($table->getError());
         }
         if (!$table->id) {
             return 0;
         }
         // Fields
         $query = 'SELECT a.*, b.storage_table FROM #__cck_core_search_field AS a LEFT JOIN #__cck_core_fields AS b ON b.id = a.fieldid WHERE a.searchid = ' . (int) $pk;
         $string = $this->_table_no_key_batch('query', $query, '#__cck_core_search_field', 'searchid', $table->id, array('storage_table'));
         // Positions
         $string = $this->_table_no_key_batch('where', 'searchid = ' . (int) $pk, '#__cck_core_search_position', 'searchid', $table->id);
     }
 }