本文整理汇总了PHP中DBField::create方法的典型用法代码示例。如果您正苦于以下问题:PHP DBField::create方法的具体用法?PHP DBField::create怎么用?PHP DBField::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBField
的用法示例。
在下文中一共展示了DBField::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Dates
function Dates()
{
Requirements::themedCSS('archivewidget');
$results = new DataObjectSet();
$container = BlogTree::current();
$ids = $container->BlogHolderIDs();
$stage = Versioned::current_stage();
$suffix = !$stage || $stage == 'Stage' ? "" : "_{$stage}";
$monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")';
$yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")';
$sqlResults = DB::query("\n\t\t\tSELECT DISTINCT CAST({$monthclause} AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", {$yearclause} AS \"Year\"\n\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\tORDER BY \"Year\" DESC, \"Month\" DESC;");
if ($this->ShowLastYears == 0) {
$cutOffYear = 0;
} else {
$cutOffYear = (int) date("Y") - $this->ShowLastYears;
}
$years = array();
if (Director::get_current_page()->ClassName == 'BlogHolder') {
$urlParams = Director::urlParams();
$yearParam = $urlParams['ID'];
$monthParam = $urlParams['OtherID'];
} else {
$date = new DateTime(Director::get_current_page()->Date);
$yearParam = $date->format("Y");
$monthParam = $date->format("m");
}
if ($sqlResults) {
foreach ($sqlResults as $sqlResult) {
$isMonthDisplay = true;
$year = $sqlResult['Year'] ? (int) $sqlResult['Year'] : date('Y');
$isMonthDisplay = $year > $cutOffYear;
// $dateFormat = 'Month'; else $dateFormat = 'Year';
$monthVal = isset($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1;
$month = $isMonthDisplay ? $monthVal : 1;
$date = DBField::create('Date', array('Day' => 1, 'Month' => $month, 'Year' => $year));
if ($isMonthDisplay) {
$link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal);
} else {
$link = $container->Link('date') . '/' . $sqlResult['Year'];
}
if ($isMonthDisplay || !$isMonthDisplay && !in_array($year, $years)) {
$years[] = $year;
$current = false;
$children = new DataObjectSet();
$LinkingMode = "link";
if ($isMonthDisplay && $yearParam == $year && $monthParam == $month || !$isMonthDisplay && $yearParam == $year) {
$LinkingMode = "current";
$current = true;
if ($this->ShowChildren && $isMonthDisplay) {
$filter = $yearclause . ' = ' . $year . ' AND ' . $monthclause . ' = ' . $month;
$children = DataObject::get('BlogEntry', $filter, "Date DESC");
}
}
$results->push(new ArrayData(array('Date' => $date, 'Year' => $year, 'Link' => $link, 'NoMonth' => !$isMonthDisplay, 'LinkingMode' => $LinkingMode, 'Children' => $children)));
unset($children);
}
}
}
return $results;
}
示例2: testToDialect
public function testToDialect()
{
$expression = Expression::containsIp(IpRange::create('127.0.0.1-127.0.0.5'), IpAddress::create('127.0.0.3'));
$this->assertEquals("'127.0.0.3' <<= '127.0.0.1-127.0.0.5'", $expression->toDialectString(PostgresDialect::me()));
$expression = Expression::containsIp(DBField::create('range'), '192.168.1.1');
$this->assertEquals('\'192.168.1.1\' <<= "range"', $expression->toDialectString(PostgresDialect::me()));
}
示例3: testLoadWithCustomHeaderAndRelation
/**
* Test import with manual column mapping and custom column names
*/
function testLoadWithCustomHeaderAndRelation()
{
$loader = new CsvBulkLoader('CsvBulkLoaderTest_Player');
$filepath = Director::baseFolder() . '/sapphire/tests/dev/CsvBulkLoaderTest_PlayersWithCustomHeaderAndRelation.csv';
$file = fopen($filepath, 'r');
$compareCount = $this->getLineCount($file);
fgetcsv($file);
// pop header row
$compareRow = fgetcsv($file);
$loader->columnMap = array('first name' => 'FirstName', 'bio' => 'Biography', 'bday' => 'Birthday', 'teamtitle' => 'Team.Title', 'teamsize' => 'Team.TeamSize', 'salary' => 'Contract.Amount');
$loader->hasHeaderRow = true;
$loader->relationCallbacks = array('Team.Title' => array('relationname' => 'Team', 'callback' => 'getTeamByTitle'));
$results = $loader->load($filepath);
// Test that right amount of columns was imported
$this->assertEquals(1, $results->Count(), 'Test correct count of imported data');
// Test of augumenting existing relation (created by fixture)
$testTeam = DataObject::get_one('CsvBulkLoaderTest_Team', null, null, 'Created DESC');
$this->assertEquals('20', $testTeam->TeamSize, 'Augumenting existing has_one relation works');
// Test of creating relation
$testContract = DataObject::get_one('CsvBulkLoaderTest_PlayerContract');
$testPlayer = Dataobject::get_one("CsvBulkLoaderTest_Player", "FirstName = 'John'");
$this->assertEquals($testPlayer->ContractID, $testContract->ID, 'Creating new has_one relation works');
// Test nested setting of relation properties
$contractAmount = DBField::create('Currency', $compareRow[5])->RAW();
$this->assertEquals($testPlayer->Contract()->Amount, $contractAmount, 'Setting nested values in a relation works');
fclose($file);
}
示例4: Dates
function Dates()
{
Requirements::themedCSS('archivewidget');
$results = new DataObjectSet();
$container = BlogTree::current();
$ids = $container->BlogHolderIDs();
$stage = Versioned::current_stage();
$suffix = !$stage || $stage == 'Stage' ? "" : "_{$stage}";
$monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")';
$yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")';
if ($this->DisplayMode == 'month') {
$sqlResults = DB::query("\n\t\t\t\tSELECT DISTINCT CAST({$monthclause} AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", {$yearclause} AS \"Year\"\n\t\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\t\tORDER BY \"Year\" DESC, \"Month\" DESC;");
} else {
$sqlResults = DB::query("\n\t\t\t\tSELECT DISTINCT {$yearclause} AS \"Year\" \n\t\t\t\tFROM \"SiteTree{$suffix}\" INNER JOIN \"BlogEntry{$suffix}\" ON \"SiteTree{$suffix}\".\"ID\" = \"BlogEntry{$suffix}\".\"ID\"\n\t\t\t\tWHERE \"ParentID\" IN (" . implode(', ', $ids) . ")\n\t\t\t\tORDER BY \"Year\" DESC");
}
if ($sqlResults) {
foreach ($sqlResults as $sqlResult) {
$isMonthDisplay = $this->DisplayMode == 'month';
$monthVal = isset($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1;
$month = $isMonthDisplay ? $monthVal : 1;
$year = $sqlResult['Year'] ? (int) $sqlResult['Year'] : date('Y');
$date = DBField::create('Date', array('Day' => 1, 'Month' => $month, 'Year' => $year));
if ($isMonthDisplay) {
$link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal);
} else {
$link = $container->Link('date') . '/' . $sqlResult['Year'];
}
$results->push(new ArrayData(array('Date' => $date, 'Link' => $link)));
}
}
return $results;
}
示例5: Form
function Form()
{
$fields = new FieldSet();
$source = array();
$fields->push(new HeaderField('Header', _t('RemoveOrphanedPagesTask.HEADER', 'Remove all orphaned pages task')));
$fields->push(new LiteralField('Description', $this->description));
$orphans = $this->getOrphanedPages($this->orphanedSearchClass);
if ($orphans) {
foreach ($orphans as $orphan) {
$latestVersion = Versioned::get_latest_version($this->orphanedSearchClass, $orphan->ID);
$latestAuthor = DataObject::get_by_id('Member', $latestVersion->AuthorID);
$stageRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Stage', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID));
$liveRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Live', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID));
$label = sprintf('<a href="admin/show/%d">%s</a> <small>(#%d, Last Modified Date: %s, Last Modifier: %s, %s)</small>', $orphan->ID, $orphan->Title, $orphan->ID, DBField::create('Date', $orphan->LastEdited)->Nice(), $latestAuthor ? $latestAuthor->Title : 'unknown', $liveRecord ? 'is published' : 'not published');
$source[$orphan->ID] = $label;
}
}
if ($orphans && $orphans->Count()) {
$fields->push(new CheckboxSetField('OrphanIDs', false, $source));
$fields->push(new LiteralField('SelectAllLiteral', sprintf('<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a> ', _t('RemoveOrphanedPagesTask.SELECTALL', 'select all'))));
$fields->push(new LiteralField('UnselectAllLiteral', sprintf('<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>', _t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all'))));
$fields->push(new OptionSetField('OrphanOperation', _t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'), array('rebase' => _t('RemoveOrphanedPagesTask.OPERATION_REBASE', sprintf('Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.', $this->rebaseHolderTitle())), 'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)')), 'rebase'));
$fields->push(new LiteralField('Warning', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.DELETEWARNING', 'Warning: These operations are not reversible. Please handle with care.'))));
} else {
$fields->push(new LiteralField('NotFoundLabel', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.NONEFOUND', 'No orphans found'))));
}
$form = new Form($this, 'Form', $fields, new FieldSet(new FormAction('doSubmit', _t('RemoveOrphanedPagesTask.BUTTONRUN', 'Run'))));
if (!$orphans || !$orphans->Count()) {
$form->makeReadonly();
}
return $form;
}
示例6: updateForAjax
function updateForAjax(array &$js)
{
$total = DBField::create('EcommerceCurrency', $this->Total())->Nice();
$js[] = array('id' => $this->TableTotalID(), 'parameter' => 'innerHTML', 'value' => $total);
$js[] = array('id' => $this->CartTotalID(), 'parameter' => 'innerHTML', 'value' => $total);
$js[] = array('id' => $this->CartQuantityID(), 'parameter' => 'innerHTML', 'value' => $this->Quantity);
$js[] = array('name' => $this->QuantityFieldName(), 'parameter' => 'value', 'value' => $this->Quantity);
}
示例7: init
/**
* Initialise the controller
*/
function init()
{
Requirements::themedCSS('Forum');
$member = $this->Member() ? $this->Member() : null;
$nicknameText = $member ? $member->Nickname . '\'s ' : '';
$this->Title = DBField::create('HTMLText', Convert::raw2xml($nicknameText) . _t('ForumMemberProfile.USERPROFILE', 'User Profile'));
parent::init();
}
示例8: testToDialect
public function testToDialect()
{
$dialect = $this->getDbByType('PgSQL')->getDialect();
$expression = Expression::containsIp(IpRange::create('127.0.0.1-127.0.0.5'), IpAddress::create('127.0.0.3'));
$this->assertEquals("'127.0.0.3' <<= '127.0.0.1-127.0.0.5'", $expression->toDialectString($dialect));
$expression = Expression::containsIp(DBField::create('range'), '192.168.1.1');
$this->assertEquals('\'192.168.1.1\' <<= "range"', $expression->toDialectString($dialect));
}
示例9: process
/**
* @return JoinCapableQuery
**/
public function process(Criteria $criteria, JoinCapableQuery $query)
{
$dao = call_user_func(array($this->className, 'dao'));
foreach ($dao->getFields() as $field) {
$this->subProcess($query, DBField::create($field, $dao->getTable()));
}
return $query;
}
示例10: ConfirmTimeLimit
/**
* @return SS_Datetime
*/
public function ConfirmTimeLimit()
{
$unconfirmed = $this->Status == 'Unconfirmed';
$limit = $this->Time()->Event()->ConfirmTimeLimit;
if ($unconfirmed && $limit) {
return DBField::create('SS_Datetime', strtotime($this->Created) + $limit);
}
}
示例11: testLongDate
function testLongDate()
{
$this->assertEquals('1 April 2008', DBField::create('Date', 1206968400)->Long(), "Date->Long() works with numeric timestamp");
$this->assertEquals('1 April 2008', DBField::create('Date', '1206968400')->Long(), "Date->Long() works with string timestamp");
$this->assertEquals('31 March 2008', DBField::create('Date', 1206882000)->Long(), "Date->Long() works with numeric timestamp");
$this->assertEquals('31 March 2008', DBField::create('Date', '1206882000')->Long(), "Date->Long() works with numeric timestamp");
$this->assertEquals('3 April 2003', DBField::create('Date', '2003-4-3')->Long(), "Date->Long() works with YYYY-M-D");
$this->assertEquals('3 April 2003', DBField::create('Date', '3/4/2003')->Long(), "Date->Long() works with D/M/YYYY");
}
示例12: saveInto
/**
* SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
* initiates a new LinkField class object to pass through the values to the setter method.
*/
public function saveInto(DataObjectInterface $dataObject)
{
$fieldName = $this->name;
if ($dataObject->hasMethod("set{$fieldName}")) {
$dataObject->{$fieldName} = DBField::create('LinkField', array("PageID" => $this->fieldPageID->Value(), "CustomURL" => $this->fieldCustomURL->Value()));
} else {
$dataObject->{$fieldName}->setPageID($this->fieldPageID->Value());
$dataObject->{$fieldName}->setCustomURL($this->fieldCustomURL->Value());
}
}
示例13: saveInto
/**
* SaveInto checks if set-methods are available and use them instead of setting the values directly. saveInto
* initiates a new LinkField class object to pass through the values to the setter method.
*/
function saveInto(DataObjectInterface $dataObject)
{
$fieldName = $this->name;
if ($dataObject->hasMethod("set{$fieldName}")) {
$dataObject->{$fieldName} = DBField::create('AlternativeField', array("SelectedValue" => $this->fieldSelectedValue->Value(), "AlternativeValue" => $this->fieldAlternativeValue->Value()));
} else {
$dataObject->{$fieldName}->setSelectedValue($this->fieldSelectedValue->Value());
$dataObject->{$fieldName}->setAlternativeValue($this->fieldAlternativeValue->Value());
}
}
示例14: getExpiryDateTime
/**
* @return SS_Datetime
*/
public function getExpiryDateTime()
{
if ($this->getSession()->RegistrationID) {
$created = strtotime($this->getSession()->Registration()->Created);
$limit = $this->controller->getDateTime()->Event()->RegistrationTimeLimit;
if ($limit) {
return DBField::create('SS_Datetime', $created + $limit);
}
}
}
示例15: saveInto
/**
* 30/06/2009 - Enhancement:
* SaveInto checks if set-methods are available and use them
* instead of setting the values in the money class directly. saveInto
* initiates a new Money class object to pass through the values to the setter
* method.
*
* (see @link MoneyFieldTest_CustomSetter_Object for more information)
*/
function saveInto($dataObject)
{
$fieldName = $this->name;
if ($dataObject->hasMethod("set{$fieldName}")) {
$dataObject->{$fieldName} = DBField::create('Money', array("Currency" => $this->fieldCurrency->Value(), "Amount" => $this->fieldAmount->Value()));
} else {
$dataObject->{$fieldName}->setCurrency($this->fieldCurrency->Value());
$dataObject->{$fieldName}->setAmount($this->fieldAmount->Value());
}
}