forked from innovativepm/cakephp-newsletter-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewsletter_app_model.php
38 lines (33 loc) · 1.12 KB
/
newsletter_app_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* Copyright (c) 2009, Fabio Kreusch
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
* @copyright Copyright (c) 2009, Fabio Kreusch
* @link fabio.kreusch.com.br
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class NewsletterAppModel extends AppModel {
function escape($string) {
return "'$string'";
}
/**
* Reimplementation to ignore existing values
* @return
* @access
**/
function insertMulti($fields, $values, $table=null) {
if(!$table) {$table = $this->useTable;}
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$table = $db->fullTableName($table);
if (is_array($fields)) {
$fields = join(', ', array_map(array(&$db, 'name'), $fields));
}
foreach ($values as $key => $line) {
$values[$key] = '('.join(', ', array_map(array(&$this, 'escape'), $line)).')';
}
$sql_values = join(', ', $values);
$this->query("INSERT IGNORE INTO {$table} ({$fields}) VALUES {$sql_values};");
}
}