本文整理汇总了PHP中RedBeanModel类的典型用法代码示例。如果您正苦于以下问题:PHP RedBeanModel类的具体用法?PHP RedBeanModel怎么用?PHP RedBeanModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RedBeanModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(RedBeanModel $model = null, $attributeName = null)
{
assert('$attributeName === null || is_string($attributeName)');
assert('$model === null || $model->isAttribute($attributeName)');
if ($model !== null) {
$this->attributeName = $attributeName;
$this->attributeLabels = $model->getAttributeLabelsForAllActiveLanguagesByAttributeName($attributeName);
$this->attributePropertyToDesignerFormAdapter = new AttributePropertyToDesignerFormAdapter();
$validators = $model->getValidators($attributeName);
foreach ($validators as $validator) {
if ($validator instanceof CDefaultValueValidator) {
$this->defaultValue = $validator->value;
} elseif ($validator instanceof CRequiredValidator) {
$this->isRequired = true;
$modelAttributesAdapter = new ModelAttributesAdapter($model);
if ($modelAttributesAdapter->isStandardAttribute($attributeName) && $modelAttributesAdapter->isStandardAttributeRequiredByDefault($attributeName)) {
$this->attributePropertyToDesignerFormAdapter->setUpdateRequiredFieldStatus(false);
}
}
}
if ($model instanceof Item && $attributeName != null) {
$this->isAudited = $model->isAttributeAudited($attributeName);
}
}
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:25,代码来源:AttributeForm.php
示例2: addRelatedModelAccountToModel
/**
* Copy the account from a related model to a activity items
* @param RedBeanModel $model
* @param RedBeanModel $relatedModel
*/
protected function addRelatedModelAccountToModel(RedBeanModel $model, RedBeanModel $relatedModel)
{
$metadata = Activity::getMetadata();
if ($relatedModel->isRelation('account') && isset($relatedModel->account) && $relatedModel->account->id > 0 && in_array(get_class($relatedModel->account), $metadata['Activity']['activityItemsModelClassNames'])) {
$model->activityItems->add($relatedModel->account);
}
}
开发者ID:KulturedKitsch,项目名称:kulturedkitsch.info,代码行数:12,代码来源:ActivitiesModuleController.php
示例3: processAfterCopy
public static function processAfterCopy(RedBeanModel $model, RedBeanModel $copyToModel)
{
foreach ($model->tasks as $task) {
$copyToTask = new Task();
TaskActivityCopyModelUtil::copy($task, $copyToTask);
$copyToTask->status = Task::STATUS_NEW;
$copyToModel->tasks->add($copyToTask);
}
$copyToModel->save();
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:10,代码来源:ProjectZurmoCopyModelUtil.php
示例4: getData
/**
*
* Get model properties as array.
* return array
*/
public function getData()
{
$data = array();
$data['id'] = $this->model->id;
$retrievableAttributes = static::resolveRetrievableAttributesByModel($this->model);
foreach ($this->model->getAttributes($retrievableAttributes) as $attributeName => $notUsed) {
$type = ModelAttributeToMixedArrayTypeUtil::getType($this->model, $attributeName);
$adapterClassName = $type . 'RedBeanModelAttributeValueToArrayValueAdapter';
if ($type != null && @class_exists($adapterClassName) && !($this->model->isRelation($attributeName) && $this->model->getRelationType($attributeName) != RedBeanModel::HAS_ONE)) {
$adapter = new $adapterClassName($this->model, $attributeName);
$adapter->resolveData($data);
} elseif ($this->model->isOwnedRelation($attributeName) && ($this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE || $this->model->getRelationType($attributeName) == RedBeanModel::HAS_MANY_BELONGS_TO)) {
if ($this->model->{$attributeName}->id > 0) {
$util = new ModelToArrayAdapter($this->model->{$attributeName});
$relatedData = $util->getData();
$data[$attributeName] = $relatedData;
} else {
$data[$attributeName] = null;
}
} elseif ($this->model->isRelation($attributeName) && $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE) {
if ($this->model->{$attributeName}->id > 0) {
$data[$attributeName] = array('id' => $this->model->{$attributeName}->id);
} else {
$data[$attributeName] = null;
}
}
}
return $data;
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:34,代码来源:ModelToArrayAdapter.php
示例5: getMinLengthByModelAndAttributeName
/**
* Given a model and attributeName, get the min length for that attribute as defined by the metadata rules.
* @param object $model RedBeanModel
* @param string $attributeName
*/
public static function getMinLengthByModelAndAttributeName(RedBeanModel $model, $attributeName)
{
assert('is_string($attributeName)');
$validators = $model->getValidators($attributeName);
$minLength = null;
foreach ($validators as $validator) {
if ($validator instanceof CStringValidator) {
if ($validator->min !== null) {
$minLength = $validator->min;
break;
}
}
}
return $minLength;
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:20,代码来源:StringValidatorHelper.php
示例6: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
ZurmoDatabaseCompatibilityUtil::dropStoredFunctionsAndProcedures();
SecurityTestHelper::createSuperAdmin();
SecurityTestHelper::createUsers();
SecurityTestHelper::createGroups();
SecurityTestHelper::createRoles();
RedBeanModel::forgetAll();
//do the rebuild to ensure the tables get created properly.
ReadPermissionsOptimizationUtil::rebuild();
//Manually build the test model munge tables.
ReadPermissionsOptimizationUtil::recreateTable(ReadPermissionsOptimizationUtil::getMungeTableName('OwnedSecurableTestItem'));
ReadPermissionsOptimizationUtil::recreateTable(ReadPermissionsOptimizationUtil::getMungeTableName('OwnedSecurableTestItem2'));
$benny = User::getByUsername('benny');
$model = new OwnedSecurableTestItem();
$model->member = 'test';
assert($model->save());
// Not Coding Standard
$model = new OwnedSecurableTestItem();
$model->member = 'test2';
assert($model->save());
// Not Coding Standard
$model = new OwnedSecurableTestItem();
$model->member = 'test3';
$model->owner = $benny;
assert($model->save());
// Not Coding Standard
assert(OwnedSecurableTestItem::getCount() == 3);
// Not Coding Standard
$model = new OwnedSecurableTestItem2();
$model->member = 'test5';
assert($model->save());
// Not Coding Standard
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:35,代码来源:OwnedSecurableItemReadPermissionOptimizationTest.php
示例7: generateCampaignItems
protected static function generateCampaignItems($campaign, $pageSize)
{
if ($pageSize == null) {
$pageSize = self::DEFAULT_CAMPAIGNITEMS_TO_CREATE_PAGE_SIZE;
}
$contacts = array();
$quote = DatabaseCompatibilityUtil::getQuote();
$marketingListMemberTableName = RedBeanModel::getTableName('MarketingListMember');
$campaignItemTableName = RedBeanModel::getTableName('CampaignItem');
$sql = "select {$quote}{$marketingListMemberTableName}{$quote}.{$quote}contact_id{$quote} from {$quote}{$marketingListMemberTableName}{$quote}";
// Not Coding Standard
$sql .= "left join {$quote}{$campaignItemTableName}{$quote} on ";
$sql .= "{$quote}{$campaignItemTableName}{$quote}.{$quote}contact_id{$quote} ";
$sql .= "= {$quote}{$marketingListMemberTableName}{$quote}.{$quote}contact_id{$quote}";
$sql .= "AND {$quote}{$campaignItemTableName}{$quote}.{$quote}campaign_id{$quote} = " . $campaign->id . " ";
$sql .= "where {$quote}{$marketingListMemberTableName}{$quote}.{$quote}marketinglist_id{$quote} = " . $campaign->marketingList->id;
$sql .= " and {$quote}{$campaignItemTableName}{$quote}.{$quote}id{$quote} is null limit " . $pageSize;
$ids = R::getCol($sql);
foreach ($ids as $contactId) {
$contacts[] = Contact::getById((int) $contactId);
}
if (!empty($contacts)) {
//todo: if the return value is false, then we might need to catch that since it didn't go well.
CampaignItem::registerCampaignItemsByCampaign($campaign, $contacts);
if (count($ids) < $pageSize) {
return true;
}
} else {
return true;
}
return false;
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:32,代码来源:CampaignItemsUtil.php
示例8: add
/**
* Adds a related model.
*/
public function add(RedBeanModel $model)
{
assert("\$model instanceof {$this->modelClassName}");
assert('!$this->contains($model)');
assert('($oldCount = $this->count()) > -1');
// To save the value only when asserts are enabled.
$bean = $model->getClassBean($this->modelClassName);
$this->deferredRelateBeans[] = $bean;
if (in_array($bean, $this->deferredUnrelateBeans)) {
self::array_remove_object($this->deferredUnrelateBeans, $bean);
}
$this->relatedBeansAndModels[] = $model;
$this->modified = true;
assert('$this->count() == $oldCount + 1');
assert('$this->contains($model)');
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:19,代码来源:RedBeanMutableRelatedModels.php
示例9: __construct
/**
* @param @modelClassName - the main 'from part' table is this model's table. This is considered the base table
*/
public function __construct($modelClassName)
{
assert('is_string($modelClassName)');
$tableName = RedBeanModel::getTableName($modelClassName);
$quote = DatabaseCompatibilityUtil::getQuote();
$this->baseFromTableName = $tableName;
$this->addTableCount($tableName);
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:11,代码来源:RedBeanModelJoinTablesQueryAdapter.php
示例10: save
/**
* Any changes to the model must be re-cached.
* @see RedBeanModel::save()
*/
public function save($runValidation = true, array $attributeNames = null)
{
$saved = parent::save($runValidation, $attributeNames);
if ($saved) {
GeneralCache::cacheEntry('CustomFieldData' . $this->name, $this);
}
return $saved;
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:12,代码来源:CustomFieldData.php
示例11: setUp
public function setUp()
{
parent::setUp();
RedBeanModel::forgetAll();
$this->setupServerUrl();
if (!$this->isApiTestUrlConfigured()) {
$this->markTestSkipped(Zurmo::t('ApiModule', 'API test url is not configured in perInstanceTest.php file.'));
}
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:9,代码来源:ApiBaseTest.php
示例12: __construct
/**
* Constructs a new RedBeanModels which is a collection of classes extending model.
* The models are created lazily.
* Models are only constructed with beans by the model. Beans are
* never used by the application directly.
*/
public function __construct(RedBean_OODBBean $bean, $modelClassName)
{
assert('is_string($modelClassName)');
assert('$modelClassName != ""');
$this->modelClassName = $modelClassName;
$tableName = RedBeanModel::getTableName($modelClassName);
$this->bean = $bean;
$this->relatedBeansAndModels = array_values(R::related($this->bean, $tableName));
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:15,代码来源:RedBeanManyToManyRelatedModels.php
示例13: copy
/**
* Copy attributes from one model to another. If the attributes are relations, then only copy when it is a
* HAS_ONE variant. In the case that the relation is an OwnedModel, take special consideration for CurrencyValue
* CustomField, and MultipleValuesCustomField models. If it is owned and not one of those 3, then it should just
* copy the OwnedModel nonRelation attributes. An example of that would be Address or Email
* @param RedBeanModel $model
* @param RedBeanModel $copyToModel - model to copy attribute values from $model to
*/
public static function copy(RedBeanModel $model, RedBeanModel $copyToModel)
{
$copyToModel->setIsCopied();
foreach ($model->attributeNames() as $attributeName) {
if ($attributeName == 'owner') {
continue;
}
$isReadOnly = $model->isAttributeReadOnly($attributeName);
if (!$model->isRelation($attributeName) && !$isReadOnly) {
static::copyNonRelation($model, $attributeName, $copyToModel);
} elseif ($model->isRelation($attributeName) && !$isReadOnly && $model->isRelationTypeAHasOneVariant($attributeName)) {
static::copyRelation($model, $attributeName, $copyToModel);
}
}
if ($model instanceof OwnedSecurableItem) {
static::copyRelation($model, 'owner', $copyToModel);
}
static::resolveExplicitPermissions($model, $copyToModel);
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:27,代码来源:ZurmoCopyModelUtil.php
示例14: makeMessagesByModel
/**
* Make an array of message strings by RedBeanModel errors
* @param array $errors RedBeanModel errors
*/
public static function makeMessagesByModel(RedBeanModel $model)
{
$messages = array();
foreach ($model->getErrors() as $attributeName => $errors) {
foreach ($errors as $relationAttributeName => $errorOrRelatedError) {
if (is_array($errorOrRelatedError)) {
$relationModelClassName = $model->getRelationModelClassName($attributeName);
foreach ($errorOrRelatedError as $relatedError) {
if ($relatedError != '') {
$messages[] = LabelUtil::makeModelAndAttributeNameCombinationLabel(get_class($model), $attributeName) . ' - ' . $relatedError;
}
}
} elseif ($errorOrRelatedError != '') {
$messages[] = LabelUtil::makeModelAndAttributeNameCombinationLabel(get_class($model), $attributeName) . ' - ' . $errorOrRelatedError;
}
}
}
return $messages;
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:23,代码来源:RedBeanModelErrorsToMessagesUtil.php
示例15: resolveByWorkflowIdAndModel
/**
* @param SavedWorkflow $savedWorkflow
* @param RedBeanModel $model
* @return ByTimeWorkflowInQueue
* @throws NotSupportedException
*/
public static function resolveByWorkflowIdAndModel(SavedWorkflow $savedWorkflow, RedBeanModel $model)
{
$searchAttributeData = array();
$searchAttributeData['clauses'] = array(1 => array('attributeName' => 'modelItem', 'operatorType' => 'equals', 'value' => $model->getClassId('Item')), 2 => array('attributeName' => 'savedWorkflow', 'operatorType' => 'equals', 'value' => $savedWorkflow->id), 3 => array('attributeName' => 'modelClassName', 'operatorType' => 'equals', 'value' => get_class($model)));
$searchAttributeData['structure'] = '1 and 2 and 3';
$joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('ByTimeWorkflowInQueue');
$where = RedBeanModelDataProvider::makeWhere('ByTimeWorkflowInQueue', $searchAttributeData, $joinTablesAdapter);
$models = self::getSubset($joinTablesAdapter, null, null, $where, null);
if (count($models) > 1) {
throw new NotSupportedException();
} elseif (count($models) == 1) {
return $models[0];
} else {
$byTimeWorkflowInQueue = new ByTimeWorkflowInQueue();
$byTimeWorkflowInQueue->modelClassName = get_class($model);
$byTimeWorkflowInQueue->modelItem = $model;
$byTimeWorkflowInQueue->savedWorkflow = $savedWorkflow;
return $byTimeWorkflowInQueue;
}
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:26,代码来源:ByTimeWorkflowInQueue.php
示例16: getUsersByPartialFullName
/**
* For a give User name, run a partial search by
* full name and retrieve user models.
*
*/
public static function getUsersByPartialFullName($partialName, $pageSize)
{
assert('is_string($partialName)');
assert('is_int($pageSize)');
$personTableName = RedBeanModel::getTableName('Person');
$joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('User');
$joinTablesAdapter->addFromTableAndGetAliasName($personTableName, "{$personTableName}_id");
$fullNameSql = DatabaseCompatibilityUtil::concat(array('person.firstname', '\' \'', 'person.lastname'));
$where = " (person.firstname like lower('{$partialName}%') or " . " person.lastname like lower('{$partialName}%') or " . " {$fullNameSql} like lower('{$partialName}%')) ";
return User::getSubset($joinTablesAdapter, null, $pageSize, $where, "person.firstname, person.lastname");
}
开发者ID:youprofit,项目名称:Zurmo,代码行数:16,代码来源:UserModelSearch.php
示例17: isCurrencyInUseById
/**
* Given an id of a currency model, determine if any currency values are using this currency.
* @return true if at least one currency value model is using this currency.
* @param integer $currencyId
*/
public static function isCurrencyInUseById($currencyId)
{
assert('is_int($currencyId)');
$columnName = RedBeanModel::getForeignKeyName('CurrencyValue', 'currency');
$quote = DatabaseCompatibilityUtil::getQuote();
$where = "{$quote}{$columnName}{$quote} = '{$currencyId}'";
$count = CurrencyValue::getCount(null, $where);
if ($count > 0) {
return true;
}
return false;
}
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:17,代码来源:CurrencyValue.php
示例18: getModelByExternalSystemIdAndModelClassName
/**
* Given an external system id and model class name, try to find the associated model if it exists. If it is
* not found, a NotFoundException will be thrown. Otherwise the model will be made and returned.
* @param string $id
* @param string $modelClassName
* @return RedBeanModel $model
* @throws NotFoundException
*/
public static function getModelByExternalSystemIdAndModelClassName($id, $modelClassName)
{
assert('$id != null && is_string($id)');
assert('is_string($modelClassName)');
$tableName = $modelClassName::getTableName();
$beans = ZurmoRedBean::find($tableName, ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME . " = '{$id}'");
assert('count($beans) <= 1');
if (count($beans) == 0) {
throw new NotFoundException();
}
return RedBeanModel::makeModel(end($beans), $modelClassName);
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:20,代码来源:ExternalSystemIdSuppportedSanitizerUtil.php
示例19: getModelsByFullName
public static function getModelsByFullName($modelClassName, $fullName)
{
assert('is_string($modelClassName)');
assert('is_subclass_of($modelClassName, "Person") && $modelClassName != "Person" ||' . '$modelClassName == "User"');
assert('is_string($fullName)');
$personTableName = RedBeanModel::getTableName('Person');
$joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
$joinTablesAdapter->addFromTableAndGetAliasName($personTableName, "{$personTableName}_id");
$fullNameSql = DatabaseCompatibilityUtil::concat(array('person.firstname', '\' \'', 'person.lastname'));
$where = "{$fullNameSql} = '{$fullName}'";
return $modelClassName::getSubset($joinTablesAdapter, null, null, $where);
}
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:12,代码来源:ZurmoModelSearch.php
示例20: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$super = SecurityTestHelper::createSuperAdmin();
self::$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test message', $super);
SecurityTestHelper::createUsers();
SecurityTestHelper::createGroups();
SecurityTestHelper::createRoles();
RedBeanModel::forgetAll();
//do the rebuild to ensure the tables get created properly.
ReadPermissionsOptimizationUtil::rebuild();
}
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:12,代码来源:EmailMessageMashableActivityRulesTest.php
注:本文中的RedBeanModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论