当前位置: 首页>>代码示例>>PHP>>正文


PHP DBField::create方法代码示例

本文整理汇总了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;
 }
开发者ID:helpfulrobot,项目名称:exadium-blogarchivemenuwidget,代码行数:60,代码来源:BlogArchiveMenuWidget.php

示例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()));
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:7,代码来源:Ip4ContainsExpressionTest.class.php

示例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);
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:30,代码来源:CsvBulkLoaderTest.php

示例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;
 }
开发者ID:nicmart,项目名称:comperio-site,代码行数:32,代码来源:ArchiveWidget.php

示例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>&nbsp;', _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;
 }
开发者ID:hamishcampbell,项目名称:silverstripe-sapphire,代码行数:32,代码来源:RemoveOrphanedPagesTask.php

示例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);
 }
开发者ID:riddler7,项目名称:silverstripe-ecommerce,代码行数:8,代码来源:OrderItem.php

示例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();
 }
开发者ID:nicmart,项目名称:comperio-site,代码行数:11,代码来源:ForumMemberProfile.php

示例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));
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:8,代码来源:IpDBTest.class.php

示例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;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:11,代码来源:ClassProjection.class.php

示例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);
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-eventmanagement,代码行数:11,代码来源:EventRegistration.php

示例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");
 }
开发者ID:comperio,项目名称:silverstripe-framework,代码行数:9,代码来源:DateTest.php

示例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());
     }
 }
开发者ID:helpfulrobot,项目名称:lrc-silverstripe-link-field,代码行数:14,代码来源:LinkFormField.php

示例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());
     }
 }
开发者ID:helpfulrobot,项目名称:leapfrognz-alternative-field,代码行数:14,代码来源:AlternativeFormField.php

示例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);
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-eventmanagement,代码行数:13,代码来源:EventRegisterForm.php

示例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());
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:19,代码来源:MoneyField.php


注:本文中的DBField::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。