本文整理汇总了PHP中DataSource::insertMulti方法的典型用法代码示例。如果您正苦于以下问题:PHP DataSource::insertMulti方法的具体用法?PHP DataSource::insertMulti怎么用?PHP DataSource::insertMulti使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSource
的用法示例。
在下文中一共展示了DataSource::insertMulti方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* create new device
*
* @param Syncroton_Model_IDevice $_device
* @return Syncroton_Model_IDevice
*/
public function create($model)
{
if (!$model instanceof $this->_modelInterfaceName) {
throw new InvalidArgumentException('$model must be instanace of ' . $this->_modelInterfaceName);
}
$data = $this->_convertModelToArray($model);
$data['id'] = sha1(mt_rand() . microtime());
//$this->_db->insert($this->_tablePrefix . $this->_tableName, $data);
$this->_db->insertMulti($this->_tablePrefix . $this->_tableName, array_keys($data), array(0 => $data));
return $this->get($data['id']);
}
示例2: _saveMulti
/**
* Saves model hasAndBelongsToMany data to the database.
*
* @param array $joined Data to save
* @param mixed $id ID of record in this model
* @param DataSource $db
* @return void
*/
protected function _saveMulti($joined, $id, $db)
{
foreach ($joined as $assoc => $data) {
if (isset($this->hasAndBelongsToMany[$assoc])) {
list($join) = $this->joinModel($this->hasAndBelongsToMany[$assoc]['with']);
$keyInfo = $this->{$join}->schema($this->{$join}->primaryKey);
$isUUID = !empty($this->{$join}->primaryKey) && ($keyInfo['length'] == 36 && ($keyInfo['type'] === 'string' || $keyInfo['type'] === 'binary'));
$newData = $newValues = array();
$primaryAdded = false;
$fields = array($db->name($this->hasAndBelongsToMany[$assoc]['foreignKey']), $db->name($this->hasAndBelongsToMany[$assoc]['associationForeignKey']));
$idField = $db->name($this->{$join}->primaryKey);
if ($isUUID && !in_array($idField, $fields)) {
$fields[] = $idField;
$primaryAdded = true;
}
foreach ((array) $data as $row) {
if (is_string($row) && (strlen($row) == 36 || strlen($row) == 16) || is_numeric($row)) {
$values = array($id, $row);
if ($isUUID && $primaryAdded) {
$values[] = String::uuid();
}
$newValues[] = $values;
unset($values);
} elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
$newData[] = $row;
} elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
$newData[] = $row[$join];
}
}
if ($this->hasAndBelongsToMany[$assoc]['unique']) {
$conditions = array($join . '.' . $this->hasAndBelongsToMany[$assoc]['foreignKey'] => $id);
if (!empty($this->hasAndBelongsToMany[$assoc]['conditions'])) {
$conditions = array_merge($conditions, (array) $this->hasAndBelongsToMany[$assoc]['conditions']);
}
$links = $this->{$join}->find('all', array('conditions' => $conditions, 'recursive' => empty($this->hasAndBelongsToMany[$assoc]['conditions']) ? -1 : 0, 'fields' => $this->hasAndBelongsToMany[$assoc]['associationForeignKey']));
$associationForeignKey = "{$join}." . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
$oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
if (!empty($oldLinks)) {
$conditions[$associationForeignKey] = $oldLinks;
$db->delete($this->{$join}, $conditions);
}
}
if (!empty($newData)) {
foreach ($newData as $data) {
$data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $id;
$this->{$join}->create($data);
$this->{$join}->save();
}
}
if (!empty($newValues)) {
$db->insertMulti($this->{$join}, $fields, $newValues);
}
}
}
}