本文整理汇总了PHP中DBQuery::insertObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DBQuery::insertObject方法的具体用法?PHP DBQuery::insertObject怎么用?PHP DBQuery::insertObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBQuery
的用法示例。
在下文中一共展示了DBQuery::insertObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store()
{
$msg = $this->check();
if ($msg) {
return 'CForumMessage::store-check failed ' . $msg;
}
$q = new DBQuery();
if ($this->message_id) {
// First we need to remove any forum visits for this message
// otherwise nobody will see that it has changed.
$q->setDelete('forum_visits');
$q->addWhere('visit_message = ' . (int) $this->message_id);
$q->exec();
// No error if this fails, it is not important.
$q->clear();
$ret = $q->updateObject('forum_messages', $this, 'message_id', false);
// ! Don't update null values
$q->clear();
} else {
$date = new CDate();
$this->message_date = $date->format(FMT_DATETIME_MYSQL);
$new_id = $q->insertObject('forum_messages', $this, 'message_id');
## TODO handle error now
echo db_error();
## TODO handle error better
$q->clear();
$q->addTable('forum_messages');
$q->addQuery('count(message_id), MAX(message_date)');
$q->addWhere('message_forum = ' . (int) $this->message_forum);
$res = $q->exec();
echo db_error();
## TODO handle error better
$reply = $q->fetchRow();
$q->clear();
//update forum descriptor
$forum = new CForum();
$forum->forum_id = $this->message_forum;
$forum->forum_message_count = $reply[0];
$forum->forum_last_date = $reply[1];
$forum->forum_last_id = $this->message_id;
$forum->store();
## TODO handle error now
return $this->sendWatchMail(false);
}
if (!$ret) {
return 'CForumMessage::store failed ' . db_error();
} else {
return null;
}
}
示例2: store
/**
* @todo Parent store could be partially used
*/
public function store(CAppUI $AppUI = null)
{
global $AppUI;
$q = new DBQuery();
$this->w2PTrimAll();
$importing_tasks = false;
$errorMsgArray = $this->check();
if (count($errorMsgArray) > 0) {
return $errorMsgArray;
}
if ($this->task_id) {
addHistory('tasks', $this->task_id, 'update', $this->task_name, $this->task_project);
// Load and globalize the old, not yet updated task object
// e.g. we need some info later to calculate the shifting time for depending tasks
// see function update_dep_dates
global $oTsk;
$oTsk = new CTask();
$oTsk->peek($this->task_id);
$this->task_updated = $q->dbfnNow();
if ($this->task_start_date == '') {
$this->task_start_date = '0000-00-00 00:00:00';
}
if ($this->task_end_date == '') {
$this->task_end_date = '0000-00-00 00:00:00';
}
$ret = $q->updateObject('tasks', $this, 'task_id');
$q->clear();
$this->_action = 'updated';
// if task_status changed, then update subtasks
if ($this->task_status != $oTsk->task_status) {
$this->updateSubTasksStatus($this->task_status);
}
// Moving this task to another project?
if ($this->task_project != $oTsk->task_project) {
$this->updateSubTasksProject($this->task_project);
}
if ($this->task_dynamic == 1) {
$this->updateDynamics(true);
}
// shiftDependentTasks needs this done first
$this->check();
$ret = $q->updateObject('tasks', $this, 'task_id', false);
$q->clear();
// Milestone or task end date, or dynamic status has changed,
// shift the dates of the tasks that depend on this task
if ($this->task_end_date != $oTsk->task_end_date || $this->task_dynamic != $oTsk->task_dynamic || $this->task_milestone == '1') {
$this->shiftDependentTasks();
}
if (!$this->task_parent) {
$q->addTable('tasks');
$q->addUpdate('task_parent', $this->task_id);
$q->addUpdate('task_updated', $this->dbfnNow(), false, true);
$q->addWhere('task_id = ' . (int) $this->task_id);
$q->exec();
$q->clear();
}
} else {
$this->_action = 'added';
$this->task_updated = $q->dbfnNow();
$this->task_created = $q->dbfnNow();
if ($this->task_start_date == '') {
$this->task_start_date = '0000-00-00 00:00:00';
}
if ($this->task_end_date == '') {
$this->task_end_date = '0000-00-00 00:00:00';
}
$ret = $q->insertObject('tasks', $this, 'task_id');
$this->task_id = db_insert_id();
$q->clear();
addHistory('tasks', $this->task_id, 'add', $this->task_name, $this->task_project);
if (!$this->task_parent) {
$q->addTable('tasks');
$q->addUpdate('task_parent', $this->task_id);
$q->addUpdate('task_updated', $q->dbfnNow(), false, true);
$q->addWhere('task_id = ' . (int) $this->task_id);
$q->exec();
$q->clear();
} else {
// importing tasks do not update dynamics
$importing_tasks = true;
}
}
CProject::updateTaskCount($this->task_project, $this->getTaskCount($this->task_project));
$this->pushDependencies($this->task_id, $this->task_end_date);
//split out related departments and store them seperatly.
$q->setDelete('task_departments');
$q->addWhere('task_id=' . (int) $this->task_id);
$q->exec();
$q->clear();
// print_r($this->task_departments);
if (!empty($this->task_departments)) {
$departments = explode(',', $this->task_departments);
foreach ($departments as $department) {
$q->addTable('task_departments');
$q->addInsert('task_id', $this->task_id);
$q->addInsert('department_id', $department);
$q->exec();
//.........这里部分代码省略.........
示例3: store
/**
* Inserts a new row if id is zero or updates an existing row in the database table
*
* Can be overloaded/supplemented by the child class
* @return null|string null if successful otherwise returns and error message
*/
public function store($updateNulls = false)
{
global $AppUI;
$this->w2PTrimAll();
$msg = $this->check();
if ($msg) {
return get_class($this) . '::store-check failed ' . $msg;
}
$k = $this->_tbl_key;
if ($this->{$k}) {
$store_type = 'update';
$q = new DBQuery();
$ret = $q->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
$q->clear();
} else {
$store_type = 'add';
$q = new DBQuery();
$ret = $q->insertObject($this->_tbl, $this, $this->_tbl_key);
$q->clear();
}
if ($ret) {
// only record history if an update or insert actually occurs.
addHistory($this->_tbl, $this->{$k}, $store_type, $AppUI->_('ACTION') . ': ' . $store_type . ' ' . $AppUI->_('TABLE') . ': ' . $this->_tbl . ' ' . $AppUI->_('ID') . ': ' . $this->{$k});
}
return !$ret ? get_class($this) . '::store failed ' . db_error() : null;
}
示例4: store
public function store()
{
$q = new DBQuery();
$q->addQuery('billingcode_id');
$q->addTable('billingcode');
$q->addWhere('billingcode_name = \'' . $this->billingcode_name . '\'');
$q->addWhere('company_id = ' . (int) $this->company_id);
$found_id = $q->loadResult();
$q->clear();
if ($found_id && $found_id != $this->_billingcode_id) {
return 'Billing Code::code already exists';
} elseif ($this->_billingcode_id) {
$q->addTable('billingcode');
$q->addUpdate('billingcode_desc', $this->billingcode_desc);
$q->addUpdate('billingcode_name', $this->billingcode_name);
$q->addUpdate('billingcode_value', $this->billingcode_value);
$q->addUpdate('billingcode_status', $this->billingcode_status);
$q->addUpdate('company_id', $this->company_id);
$q->addWhere('billingcode_id = ' . (int) $this->_billingcode_id);
$q->exec();
$q->clear();
} elseif (!($ret = $q->insertObject('billingcode', $this, 'billingcode_id'))) {
return 'Billing Code::store failed <br />' . db_error();
} else {
return null;
}
}
示例5: store
public function store()
{
$msg = $this->check();
if ($msg) {
return get_class($this) . '::store-check failed';
}
$q = new DBQuery();
if ($this->user_id) {
// save the old password
$perm_func = 'updateLogin';
$q->addTable('users');
$q->addQuery('user_password');
$q->addWhere('user_id = ' . $this->user_id);
$pwd = $q->loadResult();
if (!$this->user_password) {
//if the user didn't provide a password keep the old one
$this->user_password = $pwd;
} elseif ($pwd != $this->user_password) {
$this->user_password = md5($this->user_password);
} else {
//if something is not right keep the old one
$this->user_password = $pwd;
}
$q->clear();
$ret = $q->updateObject('users', $this, 'user_id', false);
$q->clear();
} else {
$perm_func = 'addLogin';
$this->user_password = md5($this->user_password);
$ret = $q->insertObject('users', $this, 'user_id');
$q->clear();
}
if (!$ret) {
return get_class($this) . '::store failed' . db_error();
} else {
$acl =& $GLOBALS['AppUI']->acl();
$acl->{$perm_func}($this->user_id, $this->user_username);
//Insert Default Preferences
//Lets check if the user has allready default users preferences set, if not insert the default ones
$q->addTable('user_preferences', 'upr');
$q->addWhere('upr.pref_user = ' . $this->user_id);
$uprefs = $q->loadList();
$q->clear();
if (!count($uprefs) && $this->user_id > 0) {
//Lets get the default users preferences
$q->addTable('user_preferences', 'dup');
$q->addWhere('dup.pref_user = 0');
$w2prefs = $q->loadList();
$q->clear();
foreach ($w2prefs as $w2prefskey => $w2prefsvalue) {
$q->addTable('user_preferences', 'up');
$q->addInsert('pref_user', $this->user_id);
$q->addInsert('pref_name', $w2prefsvalue['pref_name']);
$q->addInsert('pref_value', $w2prefsvalue['pref_value']);
$q->exec();
$q->clear();
}
}
return null;
}
}
示例6: createsqluser
public function createsqluser($username, $password, $ldap_attribs = array())
{
global $db, $AppUI;
$hash_pass = MD5($password);
if (!count($ldap_attribs) == 0) {
// Contact information based on the inetOrgPerson class schema
$c = new CContact();
$c->contact_first_name = $ldap_attribs['givenname'][0];
$c->contact_last_name = $ldap_attribs['sn'][0];
$c->contact_email = $ldap_attribs['mail'][0];
$c->contact_phone = $ldap_attribs['telephonenumber'][0];
$c->contact_mobile = $ldap_attribs['mobile'][0];
$c->contact_city = $ldap_attribs['l'][0];
$c->contact_country = $ldap_attribs['country'][0];
$c->contact_state = $ldap_attribs['st'][0];
$c->contact_zip = $ldap_attribs['postalcode'][0];
$c->contact_job = $ldap_attribs['title'][0];
//print_r($c); die();
$q = new DBQuery();
$q->insertObject('contacts', $c, 'contact_id');
$q->clear();
}
$contact_id = $c->contact_id == null ? 'NULL' : $c->contact_id;
$q = new DBQuery();
$q->addTable('users');
$q->addInsert('user_username', $username);
$q->addInsert('user_password', $hash_pass);
$q->addInsert('user_type', '1');
$q->addInsert('user_contact', $c->contact_id);
$q->exec();
$user_id = $db->Insert_ID();
$this->user_id = $user_id;
$q->clear();
$acl =& $AppUI->acl();
$acl->insertUserRole($acl->get_group_id('anon'), $this->user_id);
}
示例7: store
public function store(CAppUI $AppUI = null)
{
global $AppUI;
$perms = $AppUI->acl();
$stored = false;
$errorMsgArray = $this->check();
if (count($errorMsgArray) > 0) {
return $errorMsgArray;
}
if ($this->dept_id) {
$q = new DBQuery();
$ret = $q->updateObject('departments', $this, 'dept_id', false);
addHistory('departments', $this->dept_id, 'update', $this->dept_name, $this->dept_id);
$stored = true;
} else {
$q = new DBQuery();
$ret = $q->insertObject('departments', $this, 'dept_id');
addHistory('departments', $this->dept_id, 'add', $this->dept_name, $this->dept_id);
$stored = true;
}
return $stored;
}