/** * update a record * @param array $p array with properties (id field is required for update) * @return boolean */ public static function update($p) { parent::update($p); $p = array_intersect_key($p, static::$tableFields); $assignments = array(); $values = array($p['id']); $p['type'] = static::$type; $i = 2; foreach ($p as $k => $v) { switch ($k) { case 'id': break; case 'password': $assignments[] = "`{$k}` = MD5(CONCAT('aero', \$" . $i++ . "))"; $values[] = $v; break; default: $assignments[] = "`{$k}` = \$" . $i++; $values[] = $v; break; } } //prepare sql $sql = 'UPDATE `' . static::$tableName . '` ' . ' SET ' . implode(',', $assignments) . ' WHERE id = $1'; //add database record DB\dbQuery($sql, $values) or die(DB\dbQueryError()); $rez = DB\dbAffectedRows() > 0; return $rez; }
public static function getUpdateSqlParams($p) { $rez = parent::getUpdateSqlParams($p); $passIdx = array_search('password', $rez['fields']); if ($passIdx !== false) { $a = explode('=', $rez['assignments'][$passIdx]); $rez['assignments'][$passIdx] = $a[0] . '= MD5(CONCAT(\'aero\', ' . $a[1] . '))'; } return $rez; }
/** * delete core record form __casebox.cores table * and drop database * @param varchar $idOrName * @return boolean */ public static function delete($idOrName) { $id = static::toId($idOrName); $data = static::read($id); $rez = parent::delete($id); if ($rez) { $dbName = Config::get('prefix') . '_' . $data['name']; DB\dbQuery("DROP DATABASE `{$dbName}`") or die(DB\dbQueryError()); } return $rez; }
/** * add a record * @param array $p associative array with table field values * @return int created id */ public static function create($p) { parent::create($p); if (empty($p['name'])) { trigger_error(L\get('ErroneousInputData') . ' Empty name for GUID.', E_USER_ERROR); } //prepare params //add database record $sql = 'INSERT INTO ' . \CB\PREFIX . '_casebox.guids (`name`) VALUES ($1)'; DB\dbQuery($sql, $p['name']) or die(DB\dbQueryError()); $rez = DB\dbLastInsertId(); return $rez; }
/** * add a record * @param array $p associative array with table field values * @return int created id */ public static function create($p) { parent::create($p); //prepare params $params = array(empty($p['object_id']) ? null : $p['object_id'], empty($p['object_pid']) ? null : $p['object_pid'], empty($p['user_id']) ? null : $p['user_id'], empty($p['action_type']) ? null : $p['action_type'], empty($p['data']) ? null : $p['data'], empty($p['data']) ? null : $p['data'], empty($p['activity_data_db']) ? null : $p['activity_data_db'], empty($p['activity_data_solr']) ? null : $p['activity_data_solr']); //add database record $sql = 'INSERT INTO `' . static::$tableName . '` ( `object_id` ,`object_pid` ,`user_id` ,`action_type` ,`data` ,`activity_data_db` ,`activity_data_solr` ) VALUES ($1, $2, $3, $4, $5, $6, $7)'; DB\dbQuery($sql, $params) or die(DB\dbQueryError()); $rez = DB\dbLastInsertId(); return $rez; }
/** * add a record * @param array $p associative array with table field values * @return int created id */ public static function create($p) { \CB\raiseErrorIf(empty($p['name']), 'ErroneousInputData'); return parent::create($p); }