本文整理汇总了PHP中ZurmoRedBean::dispense方法的典型用法代码示例。如果您正苦于以下问题:PHP ZurmoRedBean::dispense方法的具体用法?PHP ZurmoRedBean::dispense怎么用?PHP ZurmoRedBean::dispense使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZurmoRedBean
的用法示例。
在下文中一共展示了ZurmoRedBean::dispense方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPDOTypesToShowTheDodginessOfNotBeingAbleToGetNumbersOut
public function testPDOTypesToShowTheDodginessOfNotBeingAbleToGetNumbersOut()
{
$wukka = ZurmoRedBean::dispense('wukka');
$wukka->integer = 69;
ZurmoRedBean::store($wukka);
$id = $wukka->id;
unset($wukka);
$pdo = new PDO(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password);
// Not Coding Standard
$statement = $pdo->prepare('select version() as version;');
$statement->execute();
$rows = $statement->fetchAll();
$mysqlVersion = substr($rows[0]['version'], 0, 3);
$phpVersion = substr(phpversion(), 0, 5);
// These is what we are interested in. They seem to be ignored in
// php 5.3 with mysql 5.1, but works in php 5.3.6 & mysql 5.5.
// Both are needed to be set false.
// Whether it is the newer php version or the newer mysql version
// or both together, and at exactly which versions it works is
// unknown. That is for some future investigation.
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$wukka = ZurmoRedBean::load('wukka', $id);
$statement = $pdo->prepare('select * from wukka;');
$statement->execute();
$rows = $statement->fetchAll();
if (($phpVersion == '5.3.6' || $phpVersion == '5.3.5' || $phpVersion == '5.5.2') && $mysqlVersion == '5.5') {
$this->assertEquals('integer', gettype($rows[0]['integer']));
// Good! This is what we want!!!
$this->assertEquals('string', gettype($wukka->integer));
// Dodgy!!!
} else {
$this->assertEquals('string', gettype($rows[0]['integer']));
// Dodgy!!!
$this->assertEquals('string', gettype($wukka->integer));
// Dodgy!!!
}
}
示例2: getTableName
public function getTableName(RedBean_OODBBean $bean = null)
{
if ($bean == null) {
$modelClassName = $this->modelClassName;
$bean = ZurmoRedBean::dispense($modelClassName::getTableName());
}
$types = array($this->bean->getMeta("type"), $bean->getMeta("type"));
return static::resolveTableNamesWithLinkName($types, $this->linkName);
}
示例3: set
/**
* Sets a configuration entry.
* @param $user id
* @param $moduleName A non-empty string identifying the module to which
* the configuration entry belongs.
* @param $key A non-empty string identifying the configuration entry.
* @param $value The value to store, of whatever desired type.
*/
public static function set($userId, $moduleName, $key, $value)
{
assert('$userId != null && is_int($userId)');
assert('is_string($moduleName)');
assert('is_string($key)');
assert('$moduleName != ""');
assert('$key != ""');
try {
$bean = UserConfiguration::getBean($userId, $moduleName, $key);
} catch (NotFoundException $e) {
$bean = ZurmoRedBean::dispense(UserConfiguration::getTableName());
$bean->userId = $userId;
$bean->moduleName = $moduleName;
$bean->key = $key;
}
$bean->value = $value;
ZurmoRedBean::store($bean);
}
示例4: actionCreateDemoImportForAnalysis
public function actionCreateDemoImportForAnalysis($firstRowIsHeaderRow = true)
{
if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
throw new NotSupportedException();
}
$import = new Import();
$serializedData['importRulesType'] = 'Accounts';
$mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'name', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'officePhone', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_2' => array('attributeIndexOrDerivedType' => 'officeFax', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_3' => array('attributeIndexOrDerivedType' => 'employees', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_4' => array('attributeIndexOrDerivedType' => 'annualRevenue', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_5' => array('attributeIndexOrDerivedType' => 'description', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_6' => array('attributeIndexOrDerivedType' => 'website', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_7' => array('attributeIndexOrDerivedType' => null, 'type' => 'importColumn', 'mappingRulesData' => array()));
$serializedData['mappingData'] = $mappingData;
$serializedData['rowColumnDelimiter'] = ',';
// Not Coding Standard
$serializedData['rowColumnEnclosure'] = '"';
$serializedData['firstRowIsHeaderRow'] = $firstRowIsHeaderRow;
$import->serializedData = serialize($serializedData);
$saved = $import->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
$this->createImportTempTable(8, $import->getTempTableName());
//Make header row
if ($firstRowIsHeaderRow) {
$newBean = ZurmoRedBean::dispense($import->getTempTableName());
$newBean->column_0 = 'Header #1';
$newBean->column_1 = 'Header #2';
$newBean->column_2 = 'Header #3';
$newBean->column_3 = 'Header #4';
$newBean->column_4 = 'Header #5';
$newBean->column_5 = 'Header #6';
$newBean->column_6 = 'Header #7';
$newBean->column_7 = 'Header #8';
ZurmoRedBean::store($newBean);
}
//Make data rows that are clean
for ($i = 0; $i < 3; $i++) {
$newBean = ZurmoRedBean::dispense($import->getTempTableName());
$newBean->column_0 = 'aa1' . $i;
$newBean->column_1 = 'aa2' . $i;
$newBean->column_2 = 'aa3' . $i;
$newBean->column_3 = 'aa4' . $i;
$newBean->column_4 = 'aa5' . $i;
$newBean->column_5 = 'aa6' . $i;
$newBean->column_6 = 'aa7' . $i;
$newBean->column_7 = 'aa8' . $i;
$newBean->analysisStatus = ImportDataAnalyzer::STATUS_CLEAN;
$analysisData = array();
$analysisData['column_0'] = array();
$analysisData['column_0'][] = 'a test message 1';
$analysisData['column_0'][] = 'a test message 2';
$analysisData['column_2'] = array();
$analysisData['column_2'][] = 'a test message 1';
$analysisData['column_2'][] = 'a test message 2';
$newBean->serializedAnalysisMessages = serialize($analysisData);
ZurmoRedBean::store($newBean);
}
//Make data rows that have a warning
for ($i = 0; $i < 3; $i++) {
$newBean = ZurmoRedBean::dispense($import->getTempTableName());
$newBean->column_0 = 'ba1' . $i;
$newBean->column_1 = 'ba2' . $i;
$newBean->column_2 = 'ba3' . $i;
$newBean->column_3 = 'ba4' . $i;
$newBean->column_4 = 'ba5' . $i;
$newBean->column_5 = 'ba6' . $i;
$newBean->column_6 = 'ba7' . $i;
$newBean->column_7 = 'ba8' . $i;
$newBean->analysisStatus = ImportDataAnalyzer::STATUS_WARN;
$analysisData = array();
$analysisData['column_0'] = array();
$analysisData['column_0'][] = 'a test message 1';
$analysisData['column_0'][] = 'a test message 2';
$analysisData['column_2'] = array();
$analysisData['column_2'][] = 'a test message 1';
$analysisData['column_2'][] = 'a test message 2';
$newBean->serializedAnalysisMessages = serialize($analysisData);
ZurmoRedBean::store($newBean);
}
//Make data rows that are skipped
for ($i = 0; $i < 10; $i++) {
$newBean = ZurmoRedBean::dispense($import->getTempTableName());
$newBean->column_0 = 'ca1' . $i;
$newBean->column_1 = 'ca2' . $i;
$newBean->column_2 = 'ca3' . $i;
$newBean->column_3 = 'ca4' . $i;
$newBean->column_4 = 'ca5' . $i;
$newBean->column_5 = 'ca6' . $i;
$newBean->column_6 = 'ca7' . $i;
$newBean->column_7 = 'ca8' . $i;
$newBean->analysisStatus = ImportDataAnalyzer::STATUS_SKIP;
$analysisData = array();
$analysisData['column_0'] = array();
$analysisData['column_0'][] = 'a test message 1';
$analysisData['column_0'][] = 'a test message 2';
$analysisData['column_2'] = array();
$analysisData['column_2'][] = 'a test message 1';
$analysisData['column_2'][] = 'a test message 2';
$newBean->serializedAnalysisMessages = serialize($analysisData);
ZurmoRedBean::store($newBean);
}
ZurmoRedBean::store($newBean);
echo 'the import id is: ' . $import->id;
//.........这里部分代码省略.........
示例5: constructDerived
/**
* @param RedBean_OODBBean $bean
* @param bool $setDefaults
*/
protected function constructDerived($bean, $setDefaults)
{
assert('$bean === null || $bean instanceof RedBean_OODBBean');
assert('is_bool($setDefaults)');
// Does a subset of what RedBeanModel::__construct does
// in order to mix in the Person - this is metadata wise,
// User doesn't get any functionality from Person.
$modelClassName = 'Person';
$tableName = $modelClassName::getTableName();
if ($bean === null) {
$personBean = ZurmoRedBean::dispense($tableName);
} else {
$userBean = $this->getClassBean('User');
$personBean = ZurmoRedBeanLinkManager::getBean($userBean, $tableName);
assert('$personBean !== null');
}
//This is a hack to recover from a bug we cannot figure out how to solve.
//Rarely the person attributes are not part of the user, memcache needs to be restarted to solve this
//problem as you can't use the system once this occurs. this check below will clear the specific cache
//that causes this. Still need to figure out what is setting the cache wrong to begin with
if (!static::isAnAttribute('lastName')) {
static::forgetBeanModel('User');
}
$this->setClassBean($modelClassName, $personBean);
$this->mapAndCacheMetadataAndSetHints($modelClassName, $personBean);
parent::constructDerived($bean, $setDefaults);
}
示例6: __construct
/**
* Constructs a new model.
* Important:
* Models are only constructed with beans by the RedBeanModel. Beans are
* never used by the application directly.
* The application can construct a new model object by constructing a
* model without specifying a bean. In other words, if Php had
* overloading a constructor with $setDefaults would be public, and
* a constructor taking a $bean and $forceTreatAsCreation would be private.
* @param $setDefaults. If false the default validators will not be run
* on construction. The Yii way is that defaults are
* filled in after the fact, which is counter the usual
* for objects.
* @param $bean A bean. Never specified by an application.
* @param $forceTreatAsCreation. Never specified by an application.
* @param $runConstruction. Sometimes a model is needed to hook in events and the construction logic
* does not necessarily need to be run.
* @see getById()
* @see makeModel()
* @see makeModels()
*/
public function __construct($setDefaults = true, RedBean_OODBBean $bean = null, $forceTreatAsCreation = false, $runConstruction = true)
{
$this->pseudoId = self::$nextPseudoId--;
$this->init();
if (!$runConstruction) {
return;
}
if ($bean === null) {
foreach (array_reverse(RuntimeUtil::getClassHierarchy(get_class($this), static::$lastClassInBeanHeirarchy)) as $modelClassName) {
if ($modelClassName::getCanHaveBean()) {
$tableName = $modelClassName::getTableName();
$newBean = ZurmoRedBean::dispense($tableName);
$this->modelClassNameToBean[$modelClassName] = $newBean;
$this->mapAndCacheMetadataAndSetHints($modelClassName, $newBean);
}
}
// The yii way of doing defaults is the the default validator
// fills in the defaults on attributes that don't have values
// when you validator, or save. This weird, since when you get
// a model the things with defaults have not been defaulted!
// We want that semantic.
if ($setDefaults) {
$this->runDefaultValidators();
}
$forceTreatAsCreation = true;
} else {
assert('$bean->id > 0');
$first = true;
foreach (RuntimeUtil::getClassHierarchy(get_class($this), static::$lastClassInBeanHeirarchy) as $modelClassName) {
if ($modelClassName::getCanHaveBean()) {
if ($first) {
$lastBean = $bean;
$first = false;
} else {
$tableName = $modelClassName::getTableName();
$lastBean = ZurmoRedBeanLinkManager::getBean($lastBean, $tableName);
if ($lastBean === null) {
throw new MissingBeanException();
}
assert('$lastBean->id > 0');
}
$this->modelClassNameToBean[$modelClassName] = $lastBean;
$this->mapAndCacheMetadataAndSetHints($modelClassName, $lastBean);
}
}
$this->modelClassNameToBean = array_reverse($this->modelClassNameToBean);
}
$this->constructDerived($bean, $setDefaults);
if ($forceTreatAsCreation) {
$this->onCreated();
} else {
$this->onLoaded();
$modelClassName = get_called_class();
if ($modelClassName::isCacheable()) {
RedBeanModelsCache::cacheModel($this);
}
}
$this->modified = false;
}
示例7: testDateTimeHinting
public function testDateTimeHinting()
{
$bean = ZurmoRedBean::dispense("wukka");
// Not Coding Standard
$bean->setMeta("hint", array("prop" => "datetime"));
// Not Coding Standard
$bean->prop = "2010-01-01 10:00:00";
// Not Coding Standard
ZurmoRedBean::store($bean);
// Not Coding Standard
$rows = ZurmoRedBean::getAll('desc wukka');
$this->assertEquals('prop', $rows[3]['Field']);
$this->assertEquals('datetime', $rows[3]['Type']);
}