本文整理汇总了PHP中ZurmoRedBean::batch方法的典型用法代码示例。如果您正苦于以下问题:PHP ZurmoRedBean::batch方法的具体用法?PHP ZurmoRedBean::batch怎么用?PHP ZurmoRedBean::batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZurmoRedBean
的用法示例。
在下文中一共展示了ZurmoRedBean::batch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTailEvents
public static function getTailEvents($count)
{
assert('is_int($count)');
$sql = "select id\n from\n (select id\n from auditevent\n order by id desc\n limit {$count}) as temp\n order by id";
$ids = ZurmoRedBean::getCol($sql);
$beans = ZurmoRedBean::batch('auditevent', $ids);
return self::makeModels($beans, __CLASS__);
}
示例2: getTailDistinctEventsByEventName
public static function getTailDistinctEventsByEventName($eventName, User $user, $count)
{
assert('is_string($eventName)');
assert('is_int($count)');
$sql = "select id\n from ( select id, modelclassname, modelid, datetime from auditevent where _user_id = {$user->id}\n AND eventname = '{$eventName}' order by id desc ) auditevent\n group by concat(modelclassname, modelid) order by datetime desc limit {$count}";
$ids = ZurmoRedBean::getCol($sql);
$beans = ZurmoRedBean::batch('auditevent', $ids);
return self::makeModels($beans, __CLASS__);
}
示例3: testUpdateValueOnCustomFieldRows
/**
* @depends testSetAttributesWithPostForCustomField
*/
public function testUpdateValueOnCustomFieldRows()
{
$values = array('A', 'B', 'C');
$customFieldData = CustomFieldData::getByName('updateItems');
$customFieldData->serializedData = serialize($values);
$this->assertTrue($customFieldData->save());
$id = $customFieldData->id;
$customField = new CustomField();
$customField->value = 'A';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$customField = new CustomField();
$customField->value = 'B';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$customField = new CustomField();
$customField->value = 'C';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$customField = new CustomField();
$customField->value = 'C';
$customField->data = $customFieldData;
$this->assertTrue($customField->save());
$quote = DatabaseCompatibilityUtil::getQuote();
$customFieldTableName = CustomField::getTableName();
$baseCustomFieldTableName = BaseCustomField::getTableName();
$valueAttributeColumnName = 'value';
$dataAttributeColumnName = RedBeanModel::getForeignKeyName('CustomField', 'data');
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id}";
$ids = ZurmoRedBean::getCol($sql);
$beans = ZurmoRedBean::batch($customFieldTableName, $ids);
$customFields = RedBeanModel::makeModels($beans, 'CustomField');
$this->assertEquals(4, count($customFields));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'B'";
$this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'C'";
$this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'E'";
$this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
CustomField::updateValueByDataIdAndOldValueAndNewValue($id, 'C', 'E');
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'B'";
$this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'C'";
$this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
$sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
$sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
$sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
$sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
$sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
$sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'E'";
$this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
}
示例4: constructRelatedBeansAndModels
/**
* Handles constructing the relatedBeansAndModels with special attention to the case where it is PolyOneToMany
* @param string $modelClassName
* @param mixed $sqlOrBean
*/
private function constructRelatedBeansAndModels($modelClassName, $sqlOrBean = '')
{
assert('is_string($sqlOrBean) || $sqlOrBean instanceof RedBean_OODBBean');
$tableName = $modelClassName::getTableName();
if (is_string($sqlOrBean)) {
$this->relatedBeansAndModels = array_values($beans = ZurmoRedBean::find($tableName, $sqlOrBean));
} else {
assert('$sqlOrBean instanceof RedBean_OODBBean');
$this->bean = $sqlOrBean;
try {
if ($this->bean->id > 0) {
if ($this->linkType == RedBeanModel::LINK_TYPE_POLYMORPHIC) {
$value = array();
$values['id'] = $this->bean->id;
$values['type'] = $this->bean->getMeta('type');
$this->relatedBeansAndModels = array_values(ZurmoRedBean::find($tableName, strtolower($this->linkName) . '_id = :id AND ' . strtolower($this->linkName) . '_type = :type', $values));
} else {
$relatedIds = ZurmoRedBeanLinkManager::getKeys($this->bean, $tableName, $this->resolveLinkNameForCasing());
$this->relatedBeansAndModels = array_values(ZurmoRedBean::batch($tableName, $relatedIds));
}
} else {
$this->relatedBeansAndModels = array();
}
} catch (RedBean_Exception_SQL $e) {
// SQLSTATE[42S02]: Base table or view not found...
// SQLSTATE[42S22]: Column not found...
if (!in_array($e->getSQLState(), array('42S02', '42S22'))) {
throw $e;
}
$this->relatedBeansAndModels = array();
}
}
}
示例5: getSubset
/**
* Given a table name, count, and offset get an array of beans.
* @param string $tableName
* @param integer $count
* @param integer $offset
* @return array of RedBean_OODBBean beans.
*/
public static function getSubset($tableName, $where = null, $count = null, $offset = null)
{
assert('is_string($tableName)');
assert('$offset === null || is_integer($offset) && $offset >= 0');
assert('$offset === null || is_integer($count) && $count >= 1');
$sql = 'select id from ' . $tableName;
if ($where != null) {
$sql .= ' where ' . $where;
}
if ($count !== null) {
$sql .= " limit {$count}";
}
if ($offset !== null) {
$sql .= " offset {$offset}";
}
$ids = ZurmoRedBean::getCol($sql);
return ZurmoRedBean::batch($tableName, $ids);
}
示例6: getSubset
/**
* Gets a range of models from the database of the named model type.
* @param $modelClassName
* @param $joinTablesAdapter null or instance of joinTablesAdapter.
* @param $offset The zero based index of the first model to be returned.
* @param $count The number of models to be returned.
* @param $where
* @param $orderBy - sql string. Example 'a desc' or 'a.b desc'. Currently only supports non-related attributes
* @param $modelClassName Pass only when getting it at runtime gets the wrong name.
* @return An array of models of the type of the extending model.
*/
public static function getSubset(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter = null, $offset = null, $count = null, $where = null, $orderBy = null, $modelClassName = null, $selectDistinct = false)
{
assert('$offset === null || is_integer($offset) && $offset >= 0');
assert('$count === null || is_integer($count) && $count >= 1');
assert('$where === null || is_string ($where) && $where != ""');
assert('$orderBy === null || is_string ($orderBy) && $orderBy != ""');
assert('$modelClassName === null || is_string($modelClassName) && $modelClassName != ""');
if ($modelClassName === null) {
$modelClassName = get_called_class();
}
$ids = self::getSubsetIds($joinTablesAdapter, $offset, $count, $where, $orderBy, $modelClassName, $selectDistinct);
$tableName = $modelClassName::getTableName();
$beans = ZurmoRedBean::batch($tableName, $ids);
return self::makeModels($beans, $modelClassName);
}