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


PHP DataObject::get_by_id方法代码示例

本文整理汇总了PHP中DataObject::get_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::get_by_id方法的具体用法?PHP DataObject::get_by_id怎么用?PHP DataObject::get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataObject的用法示例。


在下文中一共展示了DataObject::get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCMSFields

 public function getCMSFields()
 {
     $fields = new FieldList(new TabSet('Root'));
     $fields->addFieldToTab('Root.Main', new TextField('Title', $this->fieldLabel('Title')));
     $filter = '';
     $reqParent = isset($_REQUEST['ParentID']) ? (int) $_REQUEST['ParentID'] : 0;
     $attachTo = $this->ActionID ? $this->ActionID : $reqParent;
     if ($attachTo) {
         $action = DataObject::get_by_id('WorkflowAction', $attachTo);
         if ($action && $action->ID) {
             $filter = '"WorkflowDefID" = ' . (int) $action->WorkflowDefID;
         }
     }
     $actions = DataObject::get('WorkflowAction', $filter);
     $options = array();
     if ($actions) {
         $options = $actions->map();
     }
     $defaultAction = $action ? $action->ID : "";
     $typeOptions = array('Active' => _t('WorkflowTransition.Active', 'Active'), 'Passive' => _t('WorkflowTransition.Passive', 'Passive'));
     $fields->addFieldToTab('Root.Main', new DropdownField('ActionID', $this->fieldLabel('ActionID'), $options, $defaultAction));
     $fields->addFieldToTab('Root.Main', $nextActionDropdownField = new DropdownField('NextActionID', $this->fieldLabel('NextActionID'), $options));
     $nextActionDropdownField->setEmptyString(_t('WorkflowTransition.SELECTONE', '(Select one)'));
     $fields->addFieldToTab('Root.Main', new DropdownField('Type', _t('WorkflowTransition.TYPE', 'Type'), $typeOptions));
     $members = Member::get();
     $fields->findOrMakeTab('Root.RestrictToUsers', _t('WorkflowTransition.TabTitle', 'Restrict to users'));
     $fields->addFieldToTab('Root.RestrictToUsers', new CheckboxSetField('Users', _t('WorkflowDefinition.USERS', 'Restrict to Users'), $members));
     $fields->addFieldToTab('Root.RestrictToUsers', new TreeMultiselectField('Groups', _t('WorkflowDefinition.GROUPS', 'Restrict to Groups'), 'Group'));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
开发者ID:Neumes,项目名称:advancedworkflow,代码行数:31,代码来源:WorkflowTransition.php

示例2: Breadcrumbs

 public function Breadcrumbs($unlinked = false)
 {
     $items = parent::Breadcrumbs($unlinked);
     //special case for building the breadcrumbs when calling the listchildren Pages ListView action
     if ($parentID = $this->getRequest()->getVar('ParentID')) {
         $page = DataObject::get_by_id('SiteTree', $parentID);
         //build a reversed list of the parent tree
         $pages = array();
         while ($page) {
             array_unshift($pages, $page);
             //add to start of array so that array is in reverse order
             $page = $page->Parent;
         }
         //turns the title and link of the breadcrumbs into template-friendly variables
         $params = array_filter(array('view' => $this->getRequest()->getVar('view'), 'q' => $this->getRequest()->getVar('q')));
         foreach ($pages as $page) {
             $params['ParentID'] = $page->ID;
             $item = new StdClass();
             $item->Title = $page->Title;
             $item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params));
             $items->push(new ArrayData($item));
         }
     }
     return $items;
 }
开发者ID:kamrandotpk,项目名称:silverstripe-cms,代码行数:25,代码来源:CMSPagesController.php

示例3: convertToCurrency

 /** 
  * convertToCurrency
  * Convert the provided string/number to a number_format() string using configuration of the given currency.
  *
  * @param int $number The number we are to convert to the currency defined in $currency.
  * @param int $currency The database id of the currency to display. If blank, defaults to the system default.
  *
  * @return float
  */
 public static function convertToCurrency($number, $currency = 1)
 {
     //Fetch the config for the currency provided
     $conf = DataObject::get_by_id("StoreCurrency", $currency);
     //Return our currency.
     return number_format($number, $conf->DecimalPlaces, $conf->DecimalSeperator, $conf->ThousandsSeperator);
 }
开发者ID:micschk,项目名称:torindul-silverstripe-shop,代码行数:16,代码来源:StoreCurrency.php

示例4: getTask

 public function getTask()
 {
     $Params = $this->getURLParams();
     if (is_numeric($Params['ID']) && ($task = DataObject::get_by_id('Task', $Params['ID']))) {
         return $task;
     }
 }
开发者ID:micschk,项目名称:SilverProject,代码行数:7,代码来源:addTaskPage.php

示例5: testAddingHasManyData

	function testAddingHasManyData() {
		$this->logInWithPermission('ADMIN');
		
		$team = DataObject::get_one('ComplexTableFieldTest_Team', "\"Name\" = 'The Awesome People'");
		
		$this->post('ComplexTableFieldTest_Controller/HasManyForm/field/Sponsors/AddForm', array(
			'Name' => 'Jim Beam',
			'ctf' => array(
				'ClassName' => 'ComplexTableFieldTest_Sponsor',
				'hasManyRelation' => 'Sponsors',
				'parentClass' => 'ComplexTableFieldTest_Team',
				'sourceID' => $team->ID
			)
		));

		$newSponsor = DataObject::get_one('ComplexTableFieldTest_Sponsor', "\"Name\" = 'Jim Beam'");
		$this->assertNotNull($newSponsor, 'A new ComplexTableFieldTest_Sponsor record was created, Name = "Jim Beam"');
		$this->assertEquals($newSponsor->TeamID, $team->ID, 'Automatic has-many/has-one relation was set correctly on the sponsor');
		$this->assertEquals($newSponsor->getComponent('Team')->ID, $team->ID, 'Automatic has-many/has-one relation was set correctly on the sponsor');
		
		$team = DataObject::get_by_id('ComplexTableFieldTest_Team', $team->ID);
		$sponsor = DataObject::get_by_id('ComplexTableFieldTest_Sponsor', $newSponsor->ID);
		$this->assertEquals($newSponsor->ID, $sponsor->ID, 'The sponsor is the same as the one we added');
		$foundTeam = $sponsor->getComponent('Team');
		$this->assertEquals($team->ID, $foundTeam->ID, 'The team ID matches on the other side of the relation');
	}
开发者ID:redema,项目名称:sapphire,代码行数:26,代码来源:ComplexTableFieldTest.php

示例6: alternateFilepathForErrorcode

 /**
  * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites 
  *
  * @see Error::get_filepath_for_errorcode()
  *
  * FIXME since {@link Subsite::currentSubsite()} partly relies on Session, viewing other sub-site (including main site) between 
  * opening ErrorPage in the CMS and publish ErrorPage causes static error page to get generated incorrectly. 
  */
 function alternateFilepathForErrorcode($statusCode, $locale = null)
 {
     $static_filepath = Object::get_static($this->owner->ClassName, 'static_filepath');
     $subdomainPart = "";
     // Try to get current subsite from session
     $subsite = Subsite::currentSubsite(false);
     // since this function is called from Page class before the controller is created, we have to get subsite from domain instead
     if (!$subsite) {
         $subsiteID = Subsite::getSubsiteIDForDomain();
         if ($subsiteID != 0) {
             $subsite = DataObject::get_by_id("Subsite", $subsiteID);
         } else {
             $subsite = null;
         }
     }
     if ($subsite) {
         $subdomain = $subsite->domain();
         $subdomainPart = "-{$subdomain}";
     }
     if (singleton('SiteTree')->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) {
         $filepath = $static_filepath . "/error-{$statusCode}-{$locale}{$subdomainPart}.html";
     } else {
         $filepath = $static_filepath . "/error-{$statusCode}{$subdomainPart}.html";
     }
     return $filepath;
 }
开发者ID:hafriedlander,项目名称:silverstripe-config-experiment,代码行数:34,代码来源:ErrorPageSubsite.php

示例7: Field

 public function Field($properties = array())
 {
     if (!$this->config['readonly']) {
         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
         Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
         Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/src/jquery.selector.affectedby.js');
         Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery.ui.core.js');
         Requirements::javascript('linkableobjects/javascript/DataObjectPicker.js');
     }
     Requirements::css('linkableobjects/css/DataObjectPicker.css');
     $current = $this->Value() ? DataObject::get_by_id($this->classToPick(), $this->Value()) : false;
     if ($current) {
         $sf = $this->summaryFields();
         $full = array();
         foreach ($sf as $f) {
             if ($current->{$f}) {
                 $full[] = $current->{$f};
             }
         }
         if (empty($full)) {
             $full[] = 'undefined dataobject';
         }
         $nice = implode(',', $full);
     } else {
         $nice = '-- none selected --';
     }
     $html = "<p><em class='DataObjectPickerMessage'>Type to search.</em></p>" . $this->createTag('input', array('type' => 'hidden', 'class' => 'DataObjectPicker', 'id' => $this->id(), 'name' => $this->getName(), 'value' => $this->Value()));
     if ($this->config['readonly']) {
         $html .= $this->createTag('span', array('class' => 'DataObjectPickerHelper text readonly' . ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id() . '_helper', 'tabindex' => !!$this->getAttribute('tabindex'), 'readonly' => 'readonly'), $nice);
     } else {
         $html .= $this->createTag('input', array('type' => 'text', 'autocomplete' => 'off', 'class' => 'DataObjectPickerHelper text' . ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id() . '_helper', 'name' => $this->getName() . '_helper', 'value' => $nice, 'tabindex' => !!$this->getAttribute('tabindex'), 'maxlength' => $this->maxLength ? $this->maxLength : null, 'size' => $this->maxLength ? min($this->maxLength, 30) : null, 'rel' => $this->form ? $this->Link() : 'admin/EditForm/field/' . $this->getName())) . $this->createTag('ul', array('class' => 'DataObjectPickerSuggestions', 'id' => $this->id() . '_suggestions'));
     }
     return $html . $this->createTag('div', array('style' => 'clear:both;'));
 }
开发者ID:helpfulrobot,项目名称:sam-costigan-linkableobjects,代码行数:34,代码来源:DataObjectPicker.php

示例8: index

 public function index($request)
 {
     $id = $request->param('ID');
     $token = $request->getVar('token');
     if (!$id || !ctype_digit($id)) {
         $this->httpError(404, 'A member ID was not specified.');
     }
     $member = DataObject::get_by_id('Member', $id);
     if (!$member) {
         $this->httpError(404, 'The specified member could not be found.');
     }
     if (!$member->canEdit()) {
         return Security::permissionFailure();
     }
     if ($token != $member->ValidationKey) {
         $this->httpError(400, 'An invalid token was specified.');
     }
     if (!$member->NeedsApproval) {
         $title = _t('MemberProfiles.ALREADYAPPROVED', 'Already Approved');
         $content = _t('MemberProfiles.ALREADYAPPROVEDNOTE', 'This member has already been approved');
         return $this->render(array('Title' => $title, 'Content' => "<p>{$content}</p>"));
     }
     $member->NeedsApproval = false;
     $member->write();
     $title = _t('MemberProfiles.MEMBERAPPROVED', 'Member Approved');
     $content = _t('MemberProfiles.MEMBERAPPROVEDCONTENT', 'The member "%s" has been approved and can now log in.');
     $content = sprintf($content, Convert::raw2xml("{$member->Name} <{$member->Email}>"));
     return $this->render(array('Title' => $title, 'Content' => $content));
 }
开发者ID:helpfulrobot,项目名称:ajshort-silverstripe-memberprofiles,代码行数:29,代码来源:MemberApprovalController.php

示例9: processRecord

 public function processRecord($record, $columnMap, &$results, $preview = false)
 {
     $objID = parent::processRecord($record, $columnMap, $results, $preview);
     $_cache_groupByCode = array();
     // Add to predefined groups
     $member = DataObject::get_by_id($this->objectClass, $objID);
     foreach ($this->groups as $group) {
         // TODO This isnt the most memory effective way to add members to a group
         $member->Groups()->add($group);
     }
     // Add to groups defined in CSV
     if (isset($record['Groups']) && $record['Groups']) {
         $groupCodes = explode(',', $record['Groups']);
         foreach ($groupCodes as $groupCode) {
             $groupCode = Convert::raw2url($groupCode);
             if (!isset($_cache_groupByCode[$groupCode])) {
                 $group = Group::get()->filter('Code', $groupCode)->first();
                 if (!$group) {
                     $group = new Group();
                     $group->Code = $groupCode;
                     $group->Title = $groupCode;
                     $group->write();
                 }
                 $member->Groups()->add($group);
                 $_cache_groupByCode[$groupCode] = $group;
             }
         }
     }
     $member->destroy();
     unset($member);
     return $objID;
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:32,代码来源:MemberCsvBulkLoader.php

示例10: parse_Lightbox

 static function parse_Lightbox($arguments, $content = null, $parser, $tagName = null)
 {
     $lightbox = DataObject::get_by_id('Lightbox', $arguments['id']);
     if ($lightbox && ($link = $lightbox->Link())) {
         return "{$link}";
     }
 }
开发者ID:silverstripe-terraformers,项目名称:silverstripe-lightbox,代码行数:7,代码来源:LightboxShortCodeParser.php

示例11: getParent

 /**
  * Returns the parent {@link DataObject} this comment is attached too
  *
  * @return DataObject
  */
 public function getParent()
 {
     if (!$this->BaseClass) {
         $this->BaseClass = "SiteTree";
     }
     return DataObject::get_by_id($this->BaseClass, $this->ParentID);
 }
开发者ID:roed,项目名称:silverstripe-comments,代码行数:12,代码来源:Comment.php

示例12: testSaveTreeNodeParentID

	public function testSaveTreeNodeParentID() {
		$this->loginWithPermission('ADMIN');

		$page1 = $this->objFromFixture('LeftAndMainTest_Object', 'page1');
		$page2 = $this->objFromFixture('LeftAndMainTest_Object', 'page2');
		$page3 = $this->objFromFixture('LeftAndMainTest_Object', 'page3');
		$page31 = $this->objFromFixture('LeftAndMainTest_Object', 'page31');
		$page32 = $this->objFromFixture('LeftAndMainTest_Object', 'page32');

		// Move page2 into page3, between page3.1 and page 3.2
		$siblingIDs = array(
			$page31->ID,
			$page2->ID,
			$page32->ID
		);
		$data = array(
			'SiblingIDs' => $siblingIDs,
			'ID' => $page2->ID,
			'ParentID' => $page3->ID
		);
		$response = $this->post('LeftAndMainTest_Controller/savetreenode', $data);
		$this->assertEquals(200, $response->getStatusCode());
		$page2 = DataObject::get_by_id('LeftAndMainTest_Object', $page2->ID, false);
		$page31 = DataObject::get_by_id('LeftAndMainTest_Object', $page31->ID, false);
		$page32 = DataObject::get_by_id('LeftAndMainTest_Object', $page32->ID, false);

		$this->assertEquals($page3->ID, $page2->ParentID, 'Moved page gets new parent');
		$this->assertEquals(1, $page31->Sort, 'Children pages before insertaion are unaffected');
		$this->assertEquals(2, $page2->Sort, 'Moved page is correctly sorted');
		$this->assertEquals(3, $page32->Sort, 'Children pages after insertion are resorted');
	}
开发者ID:redema,项目名称:sapphire,代码行数:31,代码来源:LeftAndMainTest.php

示例13: __construct

 public function __construct($controller, $name, $order)
 {
     /* Store Settings Object */
     $conf = StoreSettings::get_settings();
     /* Comments Box, if enabled */
     if ($conf->CheckoutSettings_OrderComments) {
         $comments = TextareaField::create("CustomerComments", "Order Comments");
         $comments->setRightTitle("These comments will be seen by staff.");
     } else {
         $comments = HiddenField::create("CustomerComments", "");
     }
     /* Terms and Conditions, if enabled */
     if ($conf->CheckoutSettings_TermsAndConditions) {
         $terms = CheckboxField::create("Terms", "I agree to " . $conf->StoreSettings_StoreName . "'s " . "<a href=" . DataObject::get_by_id("SiteTree", $conf->CheckoutSettings_TermsAndConditionsSiteTree)->URLSegment . ">" . "Terms &amp; Conditions</a>.");
     } else {
         $terms = HiddenField::create("Terms", "");
     }
     /* Fields */
     $fields = FieldList::create($comments, OptionsetField::create("PaymentMethod", "Payment Method", Gateway::create()->getGateways($order)), $terms ? HeaderField::create("Terms and Conditions", 5) : HiddenField::create("TermsHeaderField", ""), $terms);
     /* Actions */
     $actions = FieldList::create(FormAction::create('payment', 'Place Order &amp; Continue to Payment'));
     /* Required Fields */
     $required = new RequiredFields(array("PaymentMethod", $terms ? "Terms" : null));
     /*
      * Now we create the actual form with our fields and actions defined 
      * within this class.
      */
     return parent::__construct($controller, $name, $fields, $actions, $required);
 }
开发者ID:micschk,项目名称:torindul-silverstripe-shop,代码行数:29,代码来源:OrderPaymentForm.php

示例14: execute

 /**
  * Execute this method invocation object. If there are problems, throws an exception,
  * including if user_error is called during the call (suppressed user_error, but detects
  * if a user_error was ignored).
  *
  * @param MessageFrame $msgframe		The message received
  * @param Map $config					Interface configuration if called
  *										from MessageQueue.
  * @return whatever the underlying method returns
  */
 function execute(&$msgFrame, &$config)
 {
     $lastError = error_get_last();
     switch ($this->invokeType) {
         case "static":
             $res = @call_user_func_array(array($this->objectOrClass, $this->method), $this->args);
             break;
         case "dataobject":
             $obj = DataObject::get_by_id($this->objectOrClass, $this->id);
             if (!$obj) {
                 throw new Exception("Can not execute non-existent Data object {$this->objectOrClass}->{$this->id}");
             }
             $res = @call_user_func_array(array($obj, $this->method), $this->args);
             break;
         case "object":
             $res = @call_user_func_array(array($this->objectOrClass, $this->method), $this->args);
             break;
         default:
             throw new Exception("Invalid method invocation type '{$this->invokeType}'");
     }
     // OK, see if there has been an error, because we have suppressed the calls with @.
     // We need to compare it with $lastError, which was the status before we made the call,
     // and only barf if the error is new. Sigh. Oh, ignore warnings and notices.
     $err = error_get_last();
     if ($err && !in_array($err['type'], self::$ignored_error_types) && (!$lastError || $err["type"] != $lastError["type"] || $err["message"] != $lastError["message"] || $err["file"] != $lastError["file"] || $err["line"] != $lastError["line"])) {
         throw new Exception("Error detected in method invocation:" . print_r($err, true));
     }
     return $res;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-messagequeue,代码行数:39,代码来源:MethodInvocationMessage.php

示例15: testEventDetailsChangedNotificationEmail

 /**
  * @covers RegisterableDateTime::onBeforeWrite()
  */
 public function testEventDetailsChangedNotificationEmail()
 {
     $event = $this->objFromFixture('RegisterableEvent', 'event');
     $datetime = $this->objFromFixture('RegisterableDateTime', 'datetime');
     // First test that no emails are sent out for trivial changes.
     $datetime->StartTime = 0;
     $datetime->write();
     $this->assertNull($this->findEmail('test@example.com'));
     $this->assertNull($this->findEmail('canceled@example.com'));
     // Now do a non-emailed change and check they're still not send.
     $datetime->EndTime = '12:00:00';
     $datetime->write();
     $this->assertNull($this->findEmail('test@example.com'));
     $this->assertNull($this->findEmail('canceled@example.com'));
     // Now change a property that users are notified of a change in and
     // check an email is sent.
     $datetime->StartDate = '2011-01-02';
     $datetime->write();
     $this->assertEmailSent('test@example.com');
     $this->assertNull($this->findEmail('canceled@example.com'));
     $this->clearEmails();
     // Now disable notification and do the same and check no emails are
     // sent.
     $event->EmailNotifyChanges = false;
     $event->write();
     $datetime->StartDate = '2011-01-03';
     $datetime->flushCache();
     $datetime = DataObject::get_by_id('RegisterableDateTime', $datetime->ID);
     $datetime->write();
     $this->assertNull($this->findEmail('test@example.com'));
     $this->assertNull($this->findEmail('canceled@example.com'));
 }
开发者ID:nyeholt,项目名称:silverstripe-eventmanagement,代码行数:35,代码来源:RegisterableDateTimeTest.php


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