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


PHP DataObject::get_one方法代码示例

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


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

示例1: SaveProfile

 function SaveProfile($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         //Get InfusionSoft Api
         $app = $this->getInfusionSoftApi();
         $returnFields = array('Id');
         $conInfo = $app->findByEmail($data['Email'], $returnFields);
         //Check for another member with the same email address
         if ($member = DataObject::get_one("Member", "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
             $form->addErrorMessage("Email", 'Sorry, that Email address already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return $this->redirectBack();
         } elseif ($CurrentMember->Email != $data['Email'] && !empty($conInfo)) {
             $form->addErrorMessage("Email", 'Sorry, that Email address already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return $this->redirectBack();
         } else {
             //Update the InfusionSoft contact details
             $isConID = $CurrentMember->ISContactID;
             $conDat = array('FirstName' => $data['FirstName'], 'LastName' => $data['Surname'], 'Email' => $data['Email']);
             $app->updateCon($isConID, $conDat);
             //Update the member on site
             $form->saveInto($CurrentMember);
             $CurrentMember->write();
             $this->setMessage('Success', 'Your profile has been saved!');
             return $this->redirectBack();
         }
     } else {
         return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:');
     }
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:32,代码来源:EditProfilePage.php

示例2: notifySubscribers

 /**
  * Send email to subscribers, notifying them the thread has been created or post added.
  */
 public function notifySubscribers()
 {
     // all members id except current user
     $member_id = Member::currentUserID();
     $list = DataObject::get("Forum_Subscribers", "\"ForumID\" = '" . $this->owner->ForumID . "' AND \"MemberID\" != '{$member_id}'");
     if ($list) {
         foreach ($list as $obj) {
             $SQL_id = Convert::raw2sql((int) $obj->MemberID);
             // Get the members details
             $member = DataObject::get_one("Member", "\"Member\".\"ID\" = '{$SQL_id}'");
             if ($member) {
                 //error_log("email sent ".$member->Email);
                 $type = $obj->Type;
                 switch ($type) {
                     // send all email notification
                     case 'all':
                         $this->createEmail($member);
                         break;
                         // send new thread only email notification
                     // send new thread only email notification
                     case 'thread':
                         //if($this->owner->isFirstPost()){
                         $this->createEmail($member);
                         //}
                         break;
                         //
                     //
                     default:
                         break;
                 }
             }
         }
     }
 }
开发者ID:liquidedge,项目名称:forum_subscribe,代码行数:37,代码来源:ForumPostEmailSubscribers.php

示例3: testAddressBookWithReadonlyFieldForCountry

 public function testAddressBookWithReadonlyFieldForCountry()
 {
     $member = $this->objFromFixture("Member", "joebloggs");
     $this->logInAs($member);
     $this->controller->init();
     //reinit to connect up member
     // setup a single-country site
     $siteconfig = DataObject::get_one('SiteConfig');
     $siteconfig->AllowedCountries = "NZ";
     $siteconfig->write();
     $singlecountry = SiteConfig::current_site_config();
     $this->assertEquals("NZ", $singlecountry->getSingleCountry(), "Confirm that the website is setup as a single country site");
     // Open the Address Book page to test form submission with a readonly field
     $page = $this->get("account/addressbook/");
     // goto address book page
     $this->assertEquals(200, $page->getStatusCode(), "a page should load");
     $this->assertContains("Form_CreateAddressForm_Country_readonly", $page->getBody(), "The Country field is readonly");
     $this->assertNotContains("<option value=\"NZ\">New Zealand</option>", $page->getBody(), "Dropdown field is not shown");
     // Create an address
     $data = array("Address" => "234 Hereford Street", "City" => "Christchurch", "State" => "Canterbury", "PostalCode" => "8011");
     $this->submitForm("Form_CreateAddressForm", "action_saveaddress", $data);
     $this->assertEquals(200, $page->getStatusCode(), "a page should load");
     $nz_address = Address::get()->filter('PostalCode', '8011')->sort('ID')->last();
     $this->assertEquals("NZ", $nz_address->Country, "New address successfully saved; even with a Country readonly field in the form");
     $this->assertEquals("234 Hereford Street", $nz_address->Address, "Ensure that the Address is 234 Hereford Street");
 }
开发者ID:burnbright,项目名称:silverstripe-shop,代码行数:26,代码来源:AccountPageTest.php

示例4: testOneToManyAssociationWithDecorator

	function testOneToManyAssociationWithDecorator() {
		// Fails in RestfulServerTest
		// Error: Object::__call() Method 'RelatedObjects' not found in class 'RestfulServerTest_Comment' 
		$contact = new DataObjectDecoratorTest_Member();
		$contact->Website = "http://www.example.com";
		
		$object = new DataObjectDecoratorTest_RelatedObject();
		$object->FieldOne = "Lorem ipsum dolor";
		$object->FieldTwo = "Random notes";
		
		// The following code doesn't currently work:
		// $contact->RelatedObjects()->add($object);
		// $contact->write();
		
		// Instead we have to do the following
		$contact->write();
		$object->ContactID = $contact->ID;
		$object->write();
		
		unset($contact);
		
		$contact = DataObject::get_one("DataObjectDecoratorTest_Member", "Website='http://www.example.com'");
		
		$this->assertType('DataObjectDecoratorTest_RelatedObject', $contact->RelatedObjects()->First());
		$this->assertEquals("Lorem ipsum dolor", $contact->RelatedObjects()->First()->FieldOne);
		$this->assertEquals("Random notes", $contact->RelatedObjects()->First()->FieldTwo);
		$contact->delete();
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:28,代码来源:DataObjectDecoratorTest.php

示例5: current_module_manager

 /**
  * Get the current site's ModuleManager, and creates a new one through 
  * {@link make_module_manager()} if none is found.
  *
  * @return ModuleManager
  */
 public static function current_module_manager()
 {
     if ($moduleManager = DataObject::get_one('ModuleManager')) {
         return $moduleManager;
     }
     return self::make_module_manager();
 }
开发者ID:jaedb,项目名称:modulemanager,代码行数:13,代码来源:ModuleManager.php

示例6: orderfromid

 /**
  * Get the order via url 'ID' or form submission 'OrderID'.
  * It will check for permission based on session id or member id.
  *
  * @return the order
  */
 public function orderfromid($extrafilter = null)
 {
     $orderid = Director::urlParam('ID');
     if (!$orderid) {
         $orderid = isset($_POST['OrderID']) ? $_POST['OrderID'] : null;
     }
     if (!is_numeric($orderid)) {
         return null;
     }
     $order = null;
     $filter = $this->orderfilter();
     if ($extrafilter) {
         $filter .= " AND {$extrafilter}";
     }
     $idfilter = $orderid ? " AND \"ID\" = {$orderid}" : "";
     //security filter to only allow viewing orders associated with this session, or member id
     $order = DataObject::get_one('Order', "\"Status\" NOT IN('Cart','AdminCancelled','MemberCancelled') AND " . $filter . $idfilter, true, "Created DESC");
     //if no id, then get first of latest orders for member or session id?
     /*
      //TODO: permission message on failure
     if(!$order){
     	//order doesn't exist, or don't have permission
     	$this->setSessionMessage($reason,'bad');
     }
     */
     return $order;
 }
开发者ID:riddler7,项目名称:silverstripe-ecommerce,代码行数:33,代码来源:OrderManipulation.php

示例7: find_or_make

 /**
  * Find the given folder or create it both as {@link Folder} database records
  * and on the filesystem. If necessary, creates parent folders as well.
  * 
  * @param $folderPath string Absolute or relative path to the file.
  *  If path is relative, its interpreted relative to the "assets/" directory.
  * @return Folder
  */
 public static function find_or_make($folderPath)
 {
     // Create assets directory, if it is missing
     if (!file_exists(ASSETS_PATH)) {
         Filesystem::makeFolder(ASSETS_PATH);
     }
     $folderPath = trim(Director::makeRelative($folderPath));
     // replace leading and trailing slashes
     $folderPath = preg_replace('/^\\/?(.*)\\/?$/', '$1', $folderPath);
     $parts = explode("/", $folderPath);
     $parentID = 0;
     $item = null;
     foreach ($parts as $part) {
         if (!$part) {
             continue;
         }
         // happens for paths with a trailing slash
         $item = DataObject::get_one("Folder", sprintf("\"Name\" = '%s' AND \"ParentID\" = %d", Convert::raw2sql($part), (int) $parentID));
         if (!$item) {
             $item = new Folder();
             $item->ParentID = $parentID;
             $item->Name = $part;
             $item->Title = $part;
             $item->write();
         }
         if (!file_exists($item->getFullPath())) {
             Filesystem::makeFolder($item->getFullPath());
         }
         $parentID = $item->ID;
     }
     return $item;
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:40,代码来源:Folder.php

示例8: default_group

 /**
  * Check for default group, and if it doesn't exist, create it
  * Should be run under "requireDefaultRecords"
  * @param string $code
  * @param string $title
  * @param string $parent
  * @param array $permissions
  */
 public static function default_group($code, $title, $parentCode = null, $permissions = array())
 {
     $group = null;
     $action = null;
     if (!DataObject::get_one('Group', "Code = '" . $code . "'")) {
         $action = 'create';
         $group = new Group();
     } else {
         $action = 'update';
         $group = DataObject::get_one('Group', "Code = '" . $code . "'");
     }
     $group->Title = $title;
     $group->Code = $code;
     if ($parentCode) {
         $parentObj = DataObject::get_one("Group", "Code = '" . $parentCode . "'");
         $group->ParentID = $parentObj->ID;
     }
     $group->write();
     if (!empty($permissions)) {
         foreach ($permissions as $p) {
             Permission::grant($group->ID, $p);
         }
     }
     if ($action == 'create') {
         DB::alteration_message('Group ' . $title . ' (' . $code . ') has been created.', "created");
     }
     if ($action == 'update') {
         DB::alteration_message('Group ' . $title . ' (' . $code . ') has been updated.', "updated");
     }
     return $group;
 }
开发者ID:titledk,项目名称:silverstripe-defaultgroups,代码行数:39,代码来源:DefaultGroupsHelper.php

示例9: testMultipleRowInsert

 public function testMultipleRowInsert()
 {
     $query = SQLInsert::create('"SQLInsertTestBase"');
     $query->addRow(array('"Title"' => 'First Object', '"Age"' => 10, '"Description"' => 'First the worst'));
     $query->addRow(array('"Title"' => 'Second object', '"Age"' => 12));
     $sql = $query->sql($parameters);
     // Only test this case if using the default query builder
     if (get_class(DB::get_conn()->getQueryBuilder()) === 'DBQueryBuilder') {
         $this->assertSQLEquals('INSERT INTO "SQLInsertTestBase" ("Title", "Age", "Description") VALUES (?, ?, ?), (?, ?, ?)', $sql);
     }
     $this->assertEquals(array('First Object', 10, 'First the worst', 'Second object', 12, null), $parameters);
     $query->execute();
     $this->assertEquals(2, DB::affected_rows());
     // Check inserted objects are correct
     $firstObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'First Object'), false);
     $this->assertNotEmpty($firstObject);
     $this->assertEquals($firstObject->Title, 'First Object');
     $this->assertEquals($firstObject->Age, 10);
     $this->assertEquals($firstObject->Description, 'First the worst');
     $secondObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'Second object'), false);
     $this->assertNotEmpty($secondObject);
     $this->assertEquals($secondObject->Title, 'Second object');
     $this->assertEquals($secondObject->Age, 12);
     $this->assertEmpty($secondObject->Description);
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:25,代码来源:SQLInsertTest.php

示例10: run

 function run($request)
 {
     $orderStatusLogClassName = "OrderStatusLog";
     $submittedOrderStatusLogClassName = EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order");
     if ($submittedOrderStatusLogClassName) {
         $sampleSubmittedStatusLog = DataObject::get_one($submittedOrderStatusLogClassName);
         if ($sampleSubmittedStatusLog) {
             $lastOrderStep = DataObject::get_one("OrderStep", "", "\"Sort\" DESC");
             if ($lastOrderStep) {
                 $joinSQL = "INNER JOIN \"{$orderStatusLogClassName}\" ON \"{$orderStatusLogClassName}\".\"OrderID\" = \"Order\".\"ID\"";
                 $whereSQL = "WHERE \"StatusID\" <> " . $lastOrderStep->ID . " AND \"{$orderStatusLogClassName}\".ClassName = '{$submittedOrderStatusLogClassName}'";
                 $count = DB::query("\r\n\t\t\t\t\t\tSELECT COUNT (\"Order\".\"ID\")\r\n\t\t\t\t\t\tFROM \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t")->value();
                 $do = DB::query("\r\n\t\t\t\t\t\tUPDATE \"Order\"\r\n\t\t\t\t\t\t{$joinSQL}\r\n\t\t\t\t\t\tSET \"StatusID\" = " . $lastOrderStep->ID . "\r\n\t\t\t\t\t\t{$whereSQL}\r\n\t\t\t\t\t");
                 if ($count) {
                     DB::alteration_message("NOTE: {$count} records were updated.", "created");
                 } else {
                     DB::alteration_message("No records were updated.");
                 }
             } else {
                 DB::alteration_message("Could not find the last order step.", "deleted");
             }
         } else {
             DB::alteration_message("Could not find any submitted order logs.", "deleted");
         }
     } else {
         DB::alteration_message("Could not find a class name for submitted orders.", "deleted");
     }
 }
开发者ID:nieku,项目名称:silverstripe-ecommerce,代码行数:28,代码来源:EcommerceTaskArchiveAllSubmittedOrders.php

示例11: transform

 public function transform($item, $parentObject, $duplicateStrategy)
 {
     $folderChildren = $item->stageChildren();
     $newFolder = new Folder();
     $parentId = $parentObject ? $parentObject->ID : 0;
     $existing = DataObject::get_one('File', '"ParentID" = \'' . Convert::raw2sql($parentId) . '\' and "Name" = \'' . Convert::raw2sql($item->Title) . '\'');
     if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
         // just return the existing children
         return new TransformResult($existing, $folderChildren);
     } else {
         if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) {
             $newFolder = $existing;
         }
     }
     $newFolder->Name = $item->Title;
     $newFolder->Title = $item->Title;
     $newFolder->MenuTitle = $item->Title;
     $newFolder->ParentID = $parentObject->ID;
     $newFolder->Sort = 0;
     $newFolder->write();
     if (!file_exists($newFolder->getFullPath())) {
         mkdir($newFolder->getFullPath(), Filesystem::$folder_create_mask);
     }
     return new TransformResult($newFolder, $folderChildren);
 }
开发者ID:nyeholt,项目名称:silverstripe-filesystem-connector,代码行数:25,代码来源:FileSystemFolderImporter.php

示例12: doRegister

 function doRegister($data, Form $form)
 {
     //Check for existing member email address
     if ($member = DataObject::get_one("Member", "`Email` = '" . Convert::raw2sql($data['Email']) . "'")) {
         //Set error message
         $form->sessionMessage($data['Email'] . ". Sorry, that email address already exists. Please choose another.", 'bad');
         //Return back to form
         return $this->redirectBack();
         //return Director::redirectBack();
     } else {
         //Otherwise create new member and log them in
         $Member = new Member();
         $form->saveInto($Member);
         $Member->write();
         $Member->login();
         //Find or create the 'user' group
         if (!($userGroup = DataObject::get_one('Group', "Code = 'users'"))) {
             $userGroup = new Group();
             $userGroup->Code = "users";
             $userGroup->Title = "users";
             $userGroup->Write();
             $userGroup->Members()->add($Member);
         }
         //Add member to user group
         $userGroup->Members()->add($Member);
         //Get profile page
         if ($ProfilePage = DataObject::get_one('EditProfilePage')) {
             //echo "profile page exists";
             //Redirect to profile page with success message
             return $this->redirect($ProfilePage->Link());
         }
     }
 }
开发者ID:helpfulrobot,项目名称:phuongle-silverstripe-member-registration,代码行数:33,代码来源:RegistrationPage.php

示例13: Authenticate

 /**
  * Tries to logon using the credentials in the SilverStripe database
  *
  * @access public
  *
  * @param  string $source Authentication source to be used 
  * @param  string $external_uid    The ID entered
  * @param  string $external_passwd The password of the user
  *
  * @return boolean  True if the authentication was a success, false 
  *                  otherwise
  */
 public function Authenticate($RAW_source, $RAW_external_uid, $RAW_external_passwd)
 {
     $SQL_identity = Convert::raw2sql($RAW_external_uid);
     // Default login (see Security::setDefaultAdmin())
     if (Security::check_default_admin($RAW_external_uid, $RAW_external_passwd)) {
         ExternalAuthenticator::AuthLog($RAW_external_uid . '.sstripe - Logging on with an Administrator account');
         $member = Security::findAnAdministrator();
     } else {
         $SQL_source = Convert::raw2sql($RAW_source);
         ExternalAuthenticator::AuthLog($RAW_external_uid . '.sstripe - Searching for user with source ' . $SQL_source . ' in database');
         $member = DataObject::get_one("Member", "\"Member\".\"External_UserID\" = '{$SQL_identity}'" . " AND \"Member\".\"External_SourceID\" = '{$SQL_source}'" . " AND \"Password\" IS NOT NULL");
         if ($member) {
             ExternalAuthenticator::AuthLog($RAW_external_uid . '.sstripe - User was found in database');
             if ($member->checkPassword($RAW_external_passwd) == false) {
                 ExternalAuthenticator::AuthLog($RAW_external_uid . '.sstripe - Password authentication failed');
                 $member = null;
             } else {
                 ExternalAuthenticator::AuthLog($RAW_external_uid . '.sstripe - Password authentication succeeded');
             }
         } else {
             ExternalAuthenticator::AuthLog($RAW_external_uid . '.sstripe - User was NOT found in database');
         }
     }
     if ($member) {
         return true;
     } else {
         ExternalAuthenticator::setAuthMessage(_t('ExternalAuthenticator.Failed'));
         return false;
     }
 }
开发者ID:hamishcampbell,项目名称:silverstripe-auth-external,代码行数:42,代码来源:SSTRIPE.php

示例14: transform

 public function transform($item, $parentObject, $duplicateStrategy)
 {
     $newFile = $this->getTypeForFile($item->Name);
     $folderPath = $parentObject->getRelativePath();
     $parentId = $parentObject ? $parentObject->ID : 0;
     $filter = 'ParentID = \'' . Convert::raw2sql($parentId) . '\' and Title = \'' . Convert::raw2sql($item->Name) . '\'';
     $existing = DataObject::get_one('File', $filter);
     if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
         // just return the existing children
         return new TransformResult($existing, null);
     } else {
         if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) {
             $newFile = $existing;
         }
     }
     //
     $newFile->Name = $item->Name;
     $newFile->Title = $item->Name;
     $newFile->MenuTitle = $item->Name;
     //
     $size = filesize($item->FilePath);
     $details = array('size' => $size, 'name' => $item->Name, 'tmp_name' => $item->FilePath);
     $upload = new FileLoader();
     $folderPath = trim(substr($folderPath, strpos($folderPath, '/')), '/');
     try {
         $upload->loadIntoFile($details, $newFile, $folderPath);
     } catch (ValidationException $ve) {
         // ignore for now, there should really be a proper error reporting mechanism though...
         SS_Log::log("File import failed: " . $ve->getMessage(), SS_Log::WARN);
     }
     return new TransformResult($newFile, null);
 }
开发者ID:nyeholt,项目名称:silverstripe-filesystem-connector,代码行数:32,代码来源:FileSystemFileImporter.php

示例15: transform

 public function transform($item, $parentObject, $duplicateStrategy)
 {
     $pageChildren = $item->stageChildren();
     // okay, first we'll create the new page item,
     // and map a bunch of child information across
     $newFolder = new Folder();
     $parentId = $parentObject ? $parentObject->ID : 0;
     $existing = DataObject::get_one('File', '"ParentID" = \'' . Convert::raw2sql($parentId) . '\' and "Name" = \'' . Convert::raw2sql($item->Title) . '\'');
     if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
         // just return the existing children
         return new TransformResult($existing, $pageChildren);
     } else {
         if ($existing && $duplicateStrategy == ExternalContentTransformer::DS_OVERWRITE) {
             $newFolder = $existing;
         }
     }
     $newFolder->Name = $item->Title;
     $newFolder->Title = $item->Title;
     $newFolder->MenuTitle = $item->MenuTitle;
     // what else should we map across?
     // $newPage->MatrixId = $item->id;
     // $newPage->OriginalProperties = serialize($item->getRemoteProperties());
     $newFolder->ParentID = $parentObject->ID;
     $newFolder->Sort = 0;
     $newFolder->write();
     if (!file_exists($newFolder->getFullPath())) {
         mkdir($newFolder->getFullPath(), Filesystem::$folder_create_mask);
     }
     return new TransformResult($newFolder, $pageChildren);
 }
开发者ID:nyeholt,项目名称:silverstripe-cmis-connector,代码行数:30,代码来源:CmisFolderToFolderTransformer.php


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