public function insert($data) { // Validate data if (!is_array($data)) { return false; } if (empty($data['iso_code'])) { return false; } if (empty($data['created_date'])) { $data['created_date'] = date('Y-m-d H:i:s'); } // Get all the translatable tables so that we can recreate them in the new language. $this->_db->select('SELECT * FROM `#__nooku_tables`'); $tables = $this->_db->loadObjectList('table_name'); // Get the unwrapped db $db = $this->_db->getObject(); // Copy all the translatable tables for the new language. $return = array(); foreach ($tables as $table) { $table_name = '#__' . strtolower($data['iso_code']) . '_' . $table->table_name; $syncing = $this->_db->setSyncing(false); $this->_db->execute("CREATE TABLE `{$table_name}` LIKE `#__{$table->table_name}`"); $this->_db->execute("INSERT INTO `{$table_name}` SELECT * FROM `#__{$table->table_name}`"); $status = Nooku::STATUS_MISSING; // sync node table $query = "INSERT INTO #__nooku_nodes " . " (iso_code, table_name, row_id, title, created, created_by, modified, modified_by, status, original) " . " SELECT " . " '{$data['iso_code']}' AS iso_code, " . " '{$table->table_name}' AS table_name, " . " t.{$table->unique_column} AS row_id, " . " t.{$table->title_column} AS title, " . " n.created AS created, " . " n.created_by AS created_by, " . " n.modified AS modified, " . " n.modified_by AS modified_by, " . " {$status} AS status, " . " 0 AS original" . " FROM `{$table_name}` AS t, #__nooku_nodes AS n" . " WHERE n.row_id = t.{$table->unique_column}" . " AND n.table_name = '{$table->table_name}'" . " AND n.original = 1"; $this->_db->execute($query); $this->_db->setSyncing($syncing); } return parent::insert($data); }
public function insert($data) { $this->_db->select('SELECT picman_tag_id FROM #__picman_tags WHERE tag=' . $this->_db->quote($data['tag'])); if ($id = $this->_db->loadResult()) { // the tag already exists $this->set('id', $id); return true; } $ret = parent::insert($data); $this->set('id', $this->_db->insertid()); return $ret; }
public function insert($data) { // Validate data if (!is_array($data)) { return false; } if (empty($data['table_name'])) { return false; } if (empty($data['unique_column'])) { return false; } $nooku = KFactory::get('admin::com.nooku.model.nooku'); $primary = $nooku->getPrimaryLanguage(); // Get all the languages so we can create a translated table for each. $languages = $nooku->getLanguages(); // Copy all the translatable table for all languages. $return = array(); foreach ($languages as $language) { $table_name = '#__' . $data['table_name']; if ($language->iso_code != $primary->iso_code) { $table_name = '#__' . strtolower($language->iso_code) . '_' . $data['table_name']; $syncing = $this->_db->setSyncing(false); $this->_db->execute("CREATE TABLE `{$table_name}` LIKE `#__{$data['table_name']}`"); $this->_db->execute("INSERT INTO `{$table_name}` SELECT * FROM `#__{$data['table_name']}`"); $this->_db->setSyncing($syncing); $status = Nooku::STATUS_MISSING; $original = 0; } else { $status = Nooku::STATUS_COMPLETED; $original = 1; } // sync node table $query = "INSERT INTO #__nooku_nodes " . " (iso_code, table_name, row_id, title, created, created_by, modified, modified_by, status, original) " . " SELECT " . " '{$language->iso_code}' AS iso_code, " . " '{$data['table_name']}' AS table_name, " . " {$data['unique_column']} AS row_id, " . " {$data['title_column']} AS title, " . " NOW() AS created, " . " -1 AS created_by, " . " NOW() AS modified, " . " -1 AS modified_by, " . " '{$status}' AS status, " . " {$original} AS original " . " FROM `{$table_name}`"; $this->_db->execute($query); } return parent::insert($data); }