本文整理匯總了PHP中dibi::begin方法的典型用法代碼示例。如果您正苦於以下問題:PHP dibi::begin方法的具體用法?PHP dibi::begin怎麽用?PHP dibi::begin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dibi
的用法示例。
在下文中一共展示了dibi::begin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onSubmit
public function onSubmit(Form $form)
{
$data = $form->getValues();
// Předáme data do šablony
$this->template->values = $data;
$queueId = uniqid();
\dibi::begin();
$gallery_id = $this->gallery->insert(array("name" => $data["name"]));
// Přesumene uploadované soubory
foreach ($data["upload"] as $file) {
// $file je instance HttpUploadedFile
$newFilePath = FILESTORAGE_DIR . "/q{" . $queueId . "}__f{" . rand(10, 99) . "}__" . $file->getName();
// V produkčním módu nepřesunujeme soubory...
if (!Environment::isProduction()) {
if ($file->move($newFilePath)) {
$this->flashMessage("Soubor " . $file->getName() . " byl úspěšně přesunut!");
} else {
$this->flashMessage("Při přesouvání souboru " . $file->getName() . " nastala chyba! Pro více informací se podívejte do logů.");
}
}
$this->files->insert($file);
$this->gallery->addFile($gallery_id, $file_id);
dump($file);
}
\dibi::commit();
}
示例2: deleteMd
/**
* Metainformation catalogue
* --------------------------------------------------
*
* MICKA_LIB_INSERT.PHP for MicKa
*
* @link http://www.bnhelp.cz
* @package Micka
* @category Metadata
* @version 20101120
* @authors DZ
*/
function deleteMd($user, $type, $value, $mode, $par = NULL)
{
setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "user={$user}, {$type}={$value}, mode={$mode}, par={$par}");
$rs = FALSE;
// autorizace
if ($user == 'guest' || !canAction()) {
return $rs;
}
$record = getMdHeader($type, $value, $col = '', $fetch = array('all', '='));
if (isset($record[0]['RECNO']) && $record[0]['RECNO'] > -1) {
if (!getMdRight('edit', $user, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) {
return $rs;
} else {
$sql = array();
if ($mode == 'all') {
array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i;', $record[0]['RECNO']);
array_push($sql, 'DELETE FROM [md] WHERE [recno]=%i;', $record[0]['RECNO']);
} elseif ($mode == 'value') {
array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i AND md_id<>38;', $record[0]['RECNO']);
}
dibi::begin();
try {
dibi::query($sql);
dibi::commit();
$rs = TRUE;
} catch (DibiException $e) {
setMickaLog($e, 'ERROR', 'micka_lib_insert.php (deleteMd)');
dibi::rollback();
}
}
}
//Debug::dump($rs);
setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "return={$rs}");
return $rs;
}
示例3: createOrder
static function createOrder($values, $id_product_params, $id_lang, $user)
{
dibi::begin();
// print_r($values);exit;
dibi::query("INSERT INTO [order]", $values);
$order_id = dibi::insertId();
foreach ($id_product_params as $id_product_param => $count) {
self::insertProduct($id_product_param, $count, $order_id, $id_lang, $user);
}
dibi::commit();
return $order_id;
}
示例4: render
public function render($args = NULL)
{
parent::render($args);
$this->template->database = $this->context->database;
$this->template->subjects = $this->subjects->fetchAd($this->strict);
$this->template->type = $this->type;
$this->template->setFile(__DIR__ . "/BannerSubjects.latte");
dibi::begin();
foreach ($this->subjects as $key => $value) {
dibi::query('update subject set ad_show_count=ad_show_count+1 where id=' . $key);
}
dibi::commit();
$this->template->render();
}
示例5: updateUserRoles
/**
* update user roles [delete & insert]
*
* @param int User id
* @param int Role id
*/
public function updateUserRoles($userId, $roles)
{
try {
dibi::begin();
dibi::delete(self::ACL_USERS_2_ROLES_TABLE)->where('user_id = %i', $userId)->execute();
foreach ($roles as $role) {
dibi::insert(self::ACL_USERS_2_ROLES_TABLE, array('user_id' => $userId, 'role_id' => $role))->execute();
}
dibi::commit();
} catch (DibiDriverException $e) {
dibi::rollback();
throw $e;
}
}
示例6: deleteOne
/**
* Delete
*/
public function deleteOne($id)
{
$id = intval($id);
try {
dibi::begin();
$one = dibi::query('SELECT [lft], [rgt] FROM [:prefix:categories] WHERE [id] = %i', $id)->fetch();
$ids = array();
foreach (dibi::query('SELECT [id] FROM [:prefix:categories] WHERE [lft] >= %i', $one->lft, ' AND [rgt] <= %i', $one->rgt) as $id) {
$ids[] = intval($id->id);
}
dibi::query('DELETE FROM [:prefix:pages] WHERE [ref_id] IN %l', $ids, 'AND [ref_type] = %s', pages::CATEGORY);
dibi::query('DELETE FROM [:prefix:categories] WHERE [id] IN %l', $ids);
dibi::query('UPDATE [:prefix:categories] SET', '[lft] = [lft] - %i', intval($one->lft) - intval($one->rgt) + 1, 'WHERE [lft] > %i', $one->rgt);
dibi::query('UPDATE [:prefix:categories] SET', '[rgt] = [rgt] - %i', intval($one->lft) - intval($one->rgt) + 1, 'WHERE [rgt] > %i', $one->rgt);
dibi::commit();
return TRUE;
} catch (Exception $e) {
dibi::rollback();
return FALSE;
}
}
示例7: generateAllTimes
public function generateAllTimes($times = 30, $term_id = 0, $limit = 120)
{
$limit = new DibiDateTime(strtotime('+' . $limit . ' days', time()));
dibi::begin();
if ($term_id) {
dibi::query('DELETE FROM event_time_all WHERE event_time_id = %i', $term_id);
// smaze tabulku casu s daným ID termínu
$res = dibi::select('*, DATEDIFF(event_time.date_to, event_time.date_from) AS diff_dates')->from('event_time')->where('visible', '=', '1')->where('id', '=', $term_id)->fetchAll();
} else {
//dibi::query('TRUNCATE TABLE event_time_all'); // smaze celou tabulku casu
dibi::query('UPDATE event_time SET visible = 0 WHERE (DATEDIFF(event_time.date_from, CURDATE()) < 0 AND DATEDIFF(event_time.date_to, CURDATE()) < 0) OR (DATEDIFF(event_time.date_from, CURDATE()) < 0 AND isnull(`event_time`.`date_to`))');
// prevede vsechny starsi casy do neaktivni polohy
$res = dibi::select('*, DATEDIFF(event_time.date_to, event_time.date_from) AS diff_dates')->from('event_time')->where('visible', '=', '1')->fetchAll();
}
foreach ($res as $key => $event) {
$interval = date_diff($event->date_from, date_create());
if ($interval->days > 0 && $interval->invert) {
$date_from = $event->date_from;
//dump('od '.$date_from);
} else {
$date_from = new DibiDateTime();
//dump('od dnes');
}
$nextmonday = new DibiDateTime(date('N', strtotime('today')) == 1 ? strtotime('today') : strtotime('next monday', $date_from->getTimestamp()));
$nexttuesday = new DibiDateTime(date('N', strtotime('today')) == 2 ? strtotime('today') : strtotime('next tuesday', $date_from->getTimestamp()));
$nextwednesday = new DibiDateTime(date('N', strtotime('today')) == 3 ? strtotime('today') : strtotime('next wednesday', $date_from->getTimestamp()));
$nextthursday = new DibiDateTime(date('N', strtotime('today')) == 4 ? strtotime('today') : strtotime('next thursday', $date_from->getTimestamp()));
$nextfriday = new DibiDateTime(date('N', strtotime('today')) == 5 ? strtotime('today') : strtotime('next friday', $date_from->getTimestamp()));
$nextsaturday = new DibiDateTime(date('N', strtotime('today')) == 6 ? strtotime('today') : strtotime('next saturday', $date_from->getTimestamp()));
$nextsunday = new DibiDateTime(date('N', strtotime('today')) == 7 ? strtotime('today') : strtotime('next sunday', $date_from->getTimestamp()));
//dump($date_from);
if ($event->repeat == 1) {
if ($event->every_monday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nextmonday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
}
}
if ($event->every_tuesday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nexttuesday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
}
}
if ($event->every_wednesday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nextwednesday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
}
}
if ($event->every_thursday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nextthursday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
}
}
if ($event->every_friday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nextfriday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
}
}
if ($event->every_saturday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nextsaturday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
}
}
if ($event->every_sunday == 1) {
for ($i = 0; $i < $times * 7; $i = $i + 7) {
$day = new DibiDateTime(strtotime('+' . $i . ' days', $nextsunday->getTimestamp()));
if ($day->getTimestamp() > $limit->getTimestamp()) {
continue;
}
$query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
dibi::query($query);
//.........這裏部分代碼省略.........
示例8: save
/**
* Save given order
* @param order
* @param array
* @return bool
*/
public function save(order $order, array $products, array $visited)
{
// order data
$data = $order->__toArray();
$data['at'] = date('Y-m-d H:i:s', time());
$data['delivery_type_id'] = $data['delivery_type']->getId();
unset($data['delivery_type']);
$data['payment_type_id'] = $data['payment_type']->getId();
unset($data['payment_type']);
$data['status_id'] = $data['status']->getId();
unset($data['status']);
// start transaction
dibi::begin();
try {
$this->insert($data);
$order_id = dibi::query('SELECT LAST_INSERT_ID()')->fetchSingle();
$order->setId($order_id);
$order->dirty(order::UNDIRT);
foreach (mapper::products()->findByIds(array_keys($products)) as $product) {
dibi::query('INSERT INTO [:prefix:orders_products]', array('order_id' => $order_id, 'product_id' => $product->getId(), 'price' => $product->getPrice(), 'amount' => $products[$product->getId()]));
}
foreach ($visited as $_) {
$values = array('order_id' => $order_id);
$values['product_id'] = $_[0]->getId();
$values['visited_at'] = date('Y-m-d H:i:s', $_[1]);
dibi::query('INSERT INTO [:prefix:order_visited_products]', $values);
}
$mail = new Mail();
$mail->setFrom(Environment::expand('%shopEmail%'))->addTo(Environment::expand('%shopEmail%'))->setSubject(__('New order'))->setBody(__('Hello, new order arrived'))->send();
$mail = new Mail();
$mail->setFrom(Environment::expand('%shopEmail%'))->addTo($data['email'])->setSubject(__('Your order at %s has been accepted', Environment::expand('%shopName%')))->setBody(str_replace('\\n', "\n", __('Hello, your order has been accepted.')))->send();
} catch (Exception $e) {
dibi::rollback();
return FALSE;
}
dibi::commit();
return TRUE;
}
示例9: upgradeDB
public function upgradeDB()
{
$confDriver = ConfService::getConfStorageImpl();
$authDriver = ConfService::getAuthDriverImpl();
$logger = AJXP_Logger::getInstance();
if (is_a($confDriver, "sqlConfDriver")) {
$conf = AJXP_Utils::cleanDibiDriverParameters($confDriver->getOption("SQL_DRIVER"));
if (!is_array($conf) || !isset($conf["driver"])) {
return "Nothing to do";
}
switch ($conf["driver"]) {
case "sqlite":
case "sqlite3":
$ext = ".sqlite";
break;
case "postgre":
$ext = ".pgsql";
break;
case "mysql":
$ext = is_file($this->workingFolder . "/" . $this->dbUpgrade . ".mysql") ? ".mysql" : ".sql";
break;
default:
return "ERROR!, DB driver " . $conf["driver"] . " not supported yet in __FUNCTION__";
}
$file = $this->dbUpgrade . $ext;
if (!is_file($this->workingFolder . "/" . $file)) {
return "Nothing to do.";
}
$sqlInstructions = file_get_contents($this->workingFolder . "/" . $file);
$parts = array_map("trim", explode("/* SEPARATOR */", $sqlInstructions));
$results = array();
$errors = array();
dibi::connect($conf);
dibi::begin();
foreach ($parts as $sqlPart) {
if (empty($sqlPart)) {
continue;
}
try {
dibi::nativeQuery($sqlPart);
$results[] = $sqlPart;
} catch (DibiException $e) {
$errors[] = $sqlPart . " (" . $e->getMessage() . ")";
}
}
dibi::commit();
dibi::disconnect();
if (!count($errors)) {
return "Database successfully upgraded";
} else {
return "Database upgrade failed. <br>The following statements were executed : <br>" . implode("<br>", $results) . ",<br><br> The following statements failed : <br>" . implode("<br>", $errors) . "<br><br> You should manually upgrade your DB.";
}
}
}
示例10: insertOne
/**
* Inserts page
* @param array
* @return someting
*/
public function insertOne(array $values)
{
if (empty($values['meta_keywords'])) {
$values['meta_keywords'] = NULL;
}
if (empty($values['meta_description'])) {
$values['meta_description'] = NULL;
}
if (empty($values['content'])) {
$values['content'] = NULL;
}
if (empty($values['picture_id'])) {
$values['picture_id'] = NULL;
}
try {
dibi::begin();
dibi::query('INSERT INTO [:prefix:actualities]', array('added_at' => new DibiVariable('NOW()', 'sql')));
$id = intval(dibi::query('SELECT LAST_INSERT_ID()')->fetchSingle());
$values['ref_id'] = $id;
$values['ref_type'] = pages::ACTUALITY;
dibi::query('INSERT INTO [:prefix:pages]', $values);
dibi::commit();
return TRUE;
} catch (Exception $e) {
dibi::rollback();
return FALSE;
}
}
示例11: save
public function save()
{
$this->created = $this->created ? new DibiDateTime($this->created) : new DibiDateTime();
$this->changed = $this->changed ? new DibiDateTime($this->changed) : NULL;
// prevede data objektu na pole
$data = get_object_vars($this);
unset($data['simulation']);
unset($data['force']);
unset($data['file_prefix']);
unset($data['file_sufix']);
if ($data['user_id'] === '0') {
unset($data['user_id']);
}
dibi::begin();
// zkontroluje, zda jiz neni ulozen stejny soubor - podle code
$res = dibi::query('SELECT * FROM [file] WHERE [code] = %s', $this->code);
if ($res->getRowCount() > 0) {
throw new DibiException("File already exists with this name. Please, try upload file with different name.", 0);
}
if ($this->id > 0 && !$this->force) {
foreach ($data as $key => $value) {
if ($value == null) {
unset($data[$key]);
}
}
if ($this->simulation) {
$res = dibi::test('UPDATE [file] SET', $data, 'WHERE [id]=%i', $this->id);
} else {
$res = dibi::query('UPDATE [file] SET', $data, 'WHERE [id]=%i', $this->id);
}
} else {
if ($this->simulation) {
$res = dibi::test('INSERT INTO file', $data);
$this->id = 999999999;
} else {
if ($this->force) {
$res = dibi::query('INSERT IGNORE INTO file', $data);
} else {
$res = dibi::query('INSERT INTO file', $data);
}
$this->id = dibi::getInsertId();
}
}
dibi::commit();
}
示例12: insert
static function insert($values)
{
$user_value['name'] = @$values['name'];
$user_value['surname'] = @$values['surname'];
// $user_value['email'] = $values['email'];
$user_value['login'] = $values['login'];
$user_value['activate'] = $values['activate'];
$user_value['password'] = self::getHash($values['password']);
$user_value['fbuid'] = @$values['fbuid'];
$user_value['google_id'] = @$values['google_id'];
$user_value['newsletter'] = @$values['newsletter'];
$user_value['discount'] = @$values['discount'];
unset($values['name'], $values['surname'], $values['login'], $values['password'], $values['activate'], $values['fbuid'], $values['newsletter'], $values['discount']);
dibi::begin();
dibi::insert(TABLE_USERS, $user_value)->execute();
$values['user_id'] = dibi::insertId();
dibi::insert(TABLE_USERS_INFO, $values)->execute();
dibi::commit();
return $values['user_id'];
}
示例13: updateOne
/**
* Update
*/
public function updateOne(array $values)
{
try {
dibi::begin();
$product = array();
$product['price'] = intval($values['price']);
if (isset($values['manufacturer_id'])) {
$product['manufacturer_id'] = $values['manufacturer_id'] == 0 ? NULL : intval($values['manufacturer_id']);
}
if (isset($values['category_id'])) {
$product['category_id'] = $values['category_id'] == 0 ? NULL : intval($values['category_id']);
}
$product_id = intval($values['id']);
if (isset($values['availability_id'])) {
$product['availability_id'] = $values['availability_id'] == 0 ? NULL : intval($values['availability_id']);
}
if (isset($values['code'])) {
$product['code'] = empty($values['code']) ? NULL : $values['code'];
}
unset($values['price'], $values['manufacturer_id'], $values['category_id'], $values['availability_id'], $values['id'], $values['code']);
dibi::query('UPDATE [:prefix:products] SET', $product, 'WHERE [id] = %i', $product_id);
$change = array('product_id' => $product_id, 'price' => $product['price'], 'changed_at' => new DibiVariable('NOW()', 'sql'));
dibi::query('INSERT INTO [:prefix:price_changes]', $change);
if (isset($values['picture_id'])) {
$values['picture_id'] = $values['picture_id'] == 0 ? NULL : intval($values['picture_id']);
}
if (isset($values['meta_keywords']) && empty($values['meta_keywords'])) {
$values['meta_keywords'] = NULL;
}
if (isset($values['meta_description']) && empty($values['meta_description'])) {
$values['meta_description'] = NULL;
}
if (isset($values['content']) && empty($values['content'])) {
$values['content'] = NULL;
}
if (!empty($values)) {
$where = array();
$where['ref_id'] = $product_id;
$where['ref_type'] = pages::PRODUCT;
dibi::query('UPDATE [:prefix:pages] SET', $values, 'WHERE %and', $where);
}
dibi::commit();
//<fulltext>
fulltext::dirty($product_id, TRUE);
//</fulltext>
return TRUE;
} catch (Exception $e) {
dibi::rollback();
return FALSE;
}
}
示例14: insert
public function insert(array $data)
{
if ($this->config['useAcl']) {
// check rights
if (!$this->user->isAllowed(Acl::RESOURCE_USER, Acl::PRIVILEGE_ADD)) {
throw new OperationNotAllowedException();
}
}
$data['token'] = md5($data['email'] . $data['username']);
$data['registered'] = dibi::datetime();
if (isset($data['roles'])) {
$roles = $data['roles'];
unset($data['roles']);
}
if (isset($data['client_logo'])) {
$clientLogo = $data['client_logo'];
unset($data['client_logo']);
}
// create user and update his password - needed because getHasherParamsFromUserData() requires $userId
try {
dibi::begin();
// save random password temporarily
$realPassword = $data['password'];
$data['password'] = Basic::randomizer(40);
$userId = parent::insert($data);
$data['password'] = $realPassword;
$this->update($userId, $data);
dibi::commit();
} catch (DibiDriverException $e) {
dibi::rollback();
throw $e;
}
if (isset($roles)) {
$this->getRolesModel()->updateUserRoles($userId, (array) $roles);
}
if (!empty($clientLogo)) {
$this->saveClientLogo($userId, $clientLogo);
}
return $userId;
}
示例15: addEditOnFormSubmitted
public function addEditOnFormSubmitted(NAppForm $form)
{
$error = false;
dibi::begin();
// add action
if ($this->getAction() == 'add') {
try {
$values = $form->getValues();
$roles = $values['roles'];
unset($values['password2'], $values['roles']);
// $values['password'] = md5($values['password']);
// dibi::query('INSERT INTO ['.TABLE_USERS.'] %v;', $values);
$user_id = UserModel::insert($values);
if (count($roles)) {
foreach ($roles as $role) {
dibi::query('INSERT INTO [' . TABLE_USERS_ROLES . '] (user_id, role_id) VALUES (%i, %i);', $user_id, $role);
}
}
$this->flashMessage('The user has been added.', 'ok');
dibi::commit();
if (ACL_CACHING) {
unset($this->cache['gui_acl']);
// invalidate cache
}
$this->redirect('Users:');
} catch (Exception $e) {
$error = true;
$form->addError('The user has not been added.');
throw $e;
}
} else {
// edit action
$id = $this->getParam('id');
try {
$values = $form->getValues();
$roles = $values['roles'];
unset($values['roles']);
unset($values['password2']);
// dibi::query('UPDATE ['.TABLE_USERS.'] SET %a WHERE id=%i;', $values, $id);
UserModel::update($id, $values);
dibi::query('DELETE FROM [' . TABLE_USERS_ROLES . '] WHERE user_id=%i;', $id);
if (count($roles)) {
foreach ($roles as $role) {
dibi::query('INSERT INTO [' . TABLE_USERS_ROLES . '] (user_id, role_id) VALUES (%i, %i);', $id, $role);
}
}
$this->flashMessage('The user has been edited.', 'ok');
dibi::commit();
if (ACL_CACHING) {
unset($this->cache['gui_acl']);
// invalidate cache
}
$this->redirect('Users:');
} catch (Exception $e) {
$error = true;
$form->addError('The user has not been edited.');
throw $e;
}
}
if ($error) {
dibi::rollback();
}
}