本文整理汇总了PHP中Streams::db方法的典型用法代码示例。如果您正苦于以下问题:PHP Streams::db方法的具体用法?PHP Streams::db怎么用?PHP Streams::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Streams
的用法示例。
在下文中一共展示了Streams::db方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* Does necessary preparations for saving a stream in the database.
* @method beforeSave
* @param {array} $modifiedFields
* The array of fields
* @return {array}
* @throws {Exception}
* If mandatory field is not set
*/
function beforeSave($modifiedFields)
{
if (empty($this->attributes)) {
$this->attributes = '{}';
}
if (!$this->retrieved) {
// Generate a unique name for the stream
if (!isset($modifiedFields['name'])) {
$this->name = $modifiedFields['name'] = Streams::db()->uniqueId(Streams_Stream::table(), 'name', array('publisherId' => $this->publisherId), array('prefix' => $this->type . '/Q'));
}
// we don't want user to update private fields but will set initial values to them
$privateFieldNames = self::getConfigField($this->type, 'private', array());
// magic fields are handled by parent method
$magicFieldNames = array('insertedTime', 'updatedTime');
$privateFieldNames = array_diff($privateFieldNames, $magicFieldNames);
$streamTemplate = $this->getStreamTemplate('Streams_Stream');
$fieldNames = Streams_Stream::fieldNames();
if ($streamTemplate) {
// if template exists copy all non-PK and non-magic fields from template
foreach (array_diff($fieldNames, $this->getPrimaryKey(), $magicFieldNames) as $field) {
if (in_array($field, $privateFieldNames) || !array_key_exists($field, $modifiedFields)) {
$this->{$field} = $modifiedFields[$field] = $streamTemplate->{$field};
}
}
} else {
// otherwise (no template) set all private fields to defaults
foreach ($privateFieldNames as $field) {
$defaults = self::getConfigField($this->type, 'defaults', Streams_Stream::$DEFAULTS);
$this->{$field} = $modifiedFields[$field] = Q::ifset($defaults, $field, null);
}
}
// Assign default values to fields that haven't been set yet
foreach (array_diff($fieldNames, $magicFieldNames) as $field) {
if (!array_key_exists($field, $this->fields) and !array_key_exists($field, $modifiedFields)) {
$defaults = self::getConfigField($this->type, 'defaults', Streams_Stream::$DEFAULTS);
$this->{$field} = $modifiedFields[$field] = Q::ifset($defaults, $field, null);
}
}
// Get all access templates and save corresponding access
$type = true;
$accessTemplates = $this->getStreamTemplate('Streams_Access', $type);
for ($i = 1; $i <= 3; ++$i) {
foreach ($accessTemplates[$i] as $template) {
$access = new Streams_Access();
$access->copyFrom($template->toArray());
$access->publisherId = $this->publisherId;
$access->streamName = $this->name;
if (!$access->save(true)) {
return false;
// JUNK: this leaves junk in the database, but preserves consistency
}
}
}
}
/**
* @event Streams/Stream/save/$streamType {before}
* @param {Streams_Stream} stream
* @return {false} To cancel further processing
*/
$params = array('stream' => $this, 'modifiedFields' => $modifiedFields);
if (false === Q::event("Streams/Stream/save/{$this->type}", $params, 'before')) {
return false;
}
foreach ($this->fields as $name => $value) {
if (!empty($this->fieldsModified[$name])) {
$modifiedFields[$name] = $value;
}
}
$this->beforeSaveExtended($modifiedFields);
$result = parent::beforeSave($modifiedFields);
// Assume that the stream's name is not being changed
$fields = array('Streams/user/firstName' => false, 'Streams/user/lastName' => false, 'Streams/user/username' => 'username', 'Streams/user/icon' => 'icon');
if (!isset($fields[$this->name])) {
return $result;
}
$field = $this->name === 'Streams/user/icon' ? 'icon' : 'content';
$wasModified = !empty($this->fieldsModified[$field]) or !empty($this->fieldsModified['readLevel']);
if (!$wasModified) {
return $result;
}
if ($publicField = $fields[$this->name] and !Q::eventStack('Db/Row/Users_User/saveExecute')) {
Streams::$beingSaved[$publicField] = $this;
try {
$user = Users_User::fetch($this->publisherId, true);
$user->{$publicField} = $modifiedFields[$field];
$user->save();
} catch (Exception $e) {
Streams::$beingSaved[$publicField] = array();
throw $e;
}
Streams::$beingSaved[$publicField] = array();
//.........这里部分代码省略.........