本文整理汇总了PHP中DataObject::get方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::get方法的具体用法?PHP DataObject::get怎么用?PHP DataObject::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObject
的用法示例。
在下文中一共展示了DataObject::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReadOnlyTransaction
function testReadOnlyTransaction()
{
if (DB::get_conn()->supportsTransactions() == true && DB::get_conn() instanceof PostgreSQLDatabase) {
$page = new Page();
$page->Title = 'Read only success';
$page->write();
DB::get_conn()->transactionStart('READ ONLY');
try {
$page = new Page();
$page->Title = 'Read only page failed';
$page->write();
} catch (Exception $e) {
//could not write this record
//We need to do a rollback or a commit otherwise we'll get error messages
DB::get_conn()->transactionRollback();
}
DB::get_conn()->transactionEnd();
DataObject::flush_and_destroy_cache();
$success = DataObject::get('Page', "\"Title\"='Read only success'");
$fail = DataObject::get('Page', "\"Title\"='Read only page failed'");
//This page should be in the system
$this->assertTrue(is_object($success) && $success->exists());
//This page should NOT exist, we had 'read only' permissions
$this->assertFalse(is_object($fail) && $fail->exists());
} else {
$this->markTestSkipped('Current database is not PostgreSQL');
}
}
示例2: sort
/**
* @return string
*/
public function sort($request)
{
$service = singleton('WorkflowService');
$type = $request->postVar('type');
$order = $request->postVar('ids');
$parentId = $request->postVar('parent_id');
switch ($type) {
case 'WorkflowDefinition':
$current = $service->getDefinitions();
break;
case 'WorkflowAction':
$current = DataObject::get('WorkflowAction', sprintf('"WorkflowDefID" = %d', $parentId));
break;
case 'WorkflowTransition':
$current = DataObject::get('WorkflowTransition', sprintf('"ActionID" = %d', $parentId));
break;
default:
return $this->httpError(400, _t('AdvancedWorkflowAdmin.INVALIDSORTTYPE', 'Invalid sort type.'));
}
if (!$order || count($order) != count($current)) {
return new SS_HTTPResponse(null, 400, _t('AdvancedWorkflowAdmin.INVALIDSORT', 'An invalid sort order was specified.'));
}
$service->reorder($current, $order);
return new SS_HTTPResponse(null, 200, _t('AdvancedWorkflowAdmin.SORTORDERSAVED', 'The sort order has been saved.'));
}
示例3: UnsentSubscribers
/**
* Returns a DataObjectSet containing the subscribers who have never been sent this Newsletter
*
*/
function UnsentSubscribers()
{
// Get a list of everyone who has been sent this newsletter
$sent_recipients = DataObject::get("Newsletter_SentRecipient", "ParentID='" . $this->ID . "'");
// If this Newsletter has not been sent to anyone yet, $sent_recipients will be null
if ($sent_recipients != null) {
$sent_recipients_array = $sent_recipients->toNestedArray('MemberID');
} else {
$sent_recipients_array = array();
}
// Get a list of all the subscribers to this newsletter
$subscribers = DataObject::get('Member', "`GroupID`='" . $this->Parent()->GroupID . "'", null, "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`");
// If this Newsletter has no subscribers, $subscribers will be null
if ($subscribers != null) {
$subscribers_array = $subscribers->toNestedArray();
} else {
$subscribers_array = array();
}
// Get list of subscribers who have not been sent this newsletter:
$unsent_subscribers_array = array_diff_key($subscribers_array, $sent_recipients_array);
// Create new data object set containing the subscribers who have not been sent this newsletter:
$unsent_subscribers = new DataObjectSet();
foreach ($unsent_subscribers_array as $key => $data) {
$unsent_subscribers->push(new ArrayData($data));
}
return $unsent_subscribers;
}
示例4: run
function run($request)
{
$br = Director::is_cli() ? "\n" : "<br/>";
$verbose = true;
//TODO: include order total calculation, once that gets written
//TODO: figure out how to make this run faster
//TODO: better memory managment...the destroy calls are not enough it appears.
if ($orders = DataObject::get("Order")) {
echo $br . "Writing all order items ";
foreach ($orders as $order) {
if ($items = $order->Items()) {
foreach ($items as $item) {
if ($item->Product()) {
if ($verbose) {
echo $item->ID . " ";
}
$item->write();
//OrderItem->onBeforeWrite calls 'CalculateTotal'
}
$item->destroy();
}
}
$order->destroy();
}
echo $br . "done." . $br;
}
}
示例5: InviteForm
/**
* @return Form
*/
public function InviteForm()
{
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-metadata/jquery.metadata.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery_improvements.js');
Requirements::javascript('eventmanagement/javascript/EventInvitationField_invite.js');
if ($times = $this->form->getRecord()->DateTimes()) {
$times = $times->map('ID', 'Summary');
} else {
$times = array();
}
// Get past date times attached to the parent calendar, so we can get
// all registered members from them.
$past = DataObject::get('RegisterableDateTime', sprintf('"CalendarID" = %d AND "StartDate" < \'%s\'', $this->form->getRecord()->CalendarID, date('Y-m-d')));
if ($past) {
$pastTimes = array();
foreach ($past->groupBy('EventID') as $value) {
$pastTimes[$value->First()->EventTitle()] = $value->map('ID', 'Summary');
}
} else {
$pastTimes = array();
}
$fields = new Tab('Main', new HeaderField('Select A Date/Time To Invite To'), new DropdownField('TimeID', '', $times, null, null, true), new HeaderField('AddPeopleHeader', 'Add People To Invite From'), new SelectionGroup('AddPeople', array('From a member group' => $group = new DropdownField('GroupID', '', DataObject::get('Group')->map(), null, null, true), 'From a past event' => $time = new GroupedDropdownField('PastTimeID', '', $pastTimes, null, null, true))), new HeaderField('EmailsToSendHeader', 'People To Send Invite To'), $emails = new TableField('Emails', 'EventInvitation', array('Name' => 'Name', 'Email' => 'Email Address'), array('Name' => 'TextField', 'Email' => 'TextField')));
$group->addExtraClass(sprintf("{ link: '%s' }", $this->Link('loadfromgroup')));
$time->addExtraClass(sprintf("{ link: '%s' }", $this->Link('loadfromtime')));
$emails->setCustomSourceItems(new DataObjectSet());
$fields = new FieldSet(new TabSet('Root', $fields));
$validator = new RequiredFields('TimeID');
return new Form($this, 'InviteForm', $fields, new FieldSet(new FormAction('doInvite', 'Invite')), $validator);
}
示例6: searchFromVars
/**
* @param string $keywords
* @param array $filters [optional]
* @param array $facetSpec [optional]
* @param int $start [optional]
* @param int $limit [optional]
* @param string $sort [optional]
* @return ArrayData
*/
function searchFromVars($keywords, array $filters = array(), array $facetSpec = array(), $start = -1, $limit = -1, $sort = '')
{
$searchable = ShopSearch::get_searchable_classes();
$matches = new ArrayList();
foreach ($searchable as $className) {
$list = DataObject::get($className);
// get searchable fields
$keywordFields = $this->scaffoldSearchFields($className);
// convert that list into something we can pass to Datalist::filter
$keywordFilter = array();
if (!empty($keywords)) {
foreach ($keywordFields as $searchField) {
$name = strpos($searchField, ':') !== FALSE ? $searchField : "{$searchField}:PartialMatch";
$keywordFilter[$name] = $keywords;
}
}
if (count($keywordFilter) > 0) {
$list = $list->filterAny($keywordFilter);
}
// add in any other filters
$list = FacetHelper::inst()->addFiltersToDataList($list, $filters);
// add any matches to the big list
$matches->merge($list);
}
return new ArrayData(array('Matches' => $matches, 'Facets' => FacetHelper::inst()->buildFacets($matches, $facetSpec, (bool) Config::inst()->get('ShopSearch', 'auto_facet_attributes'))));
}
示例7: 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;
}
}
}
}
}
示例8: getRecentPosts
/**
* Get the most recent posts on a blog.
*/
function getRecentPosts($blogid, $username, $password, $numberOfPosts)
{
$member = MemberAuthenticator::authenticate(array('Email' => $username, 'Password' => $password));
// TODO Throw approriate error.
if (!$member) {
die;
}
$posts = DataObject::get('BlogEntry', '"ParentID" = ' . (int) $blogid, '"Date" DESC');
$res = array();
$postsSoFar = 0;
foreach ($posts as $post) {
if (!$post->canEdit($member)) {
continue;
}
$parr = array();
$parr['title'] = $post->Title;
$parr['link'] = $post->AbsoluteLink();
$parr['description'] = $post->Content;
$parr['postid'] = (int) $post->ID;
$res[] = $parr;
if (++$postsSoFar >= $numberOfPosts) {
break;
}
}
return $res;
}
示例9: updateRelatedProducts
/**
* @param ManyManyList $products
*/
public function updateRelatedProducts(&$products, $limit, $random)
{
$curCount = $products->count();
if ($curCount < $limit) {
$cfg = Config::inst()->forClass(get_class($this->owner));
$class = $cfg->get('related_products_class');
// look up the fields
$fields = $cfg->get('related_products_fields');
if (empty($fields)) {
return;
}
if (!is_array($fields)) {
$fields = array($fields);
}
// create a filter from the fields
$filter = array();
foreach ($fields as $f) {
$filter[$f] = $this->owner->getField($f);
}
// Convert to an array list so we can add to it
$products = new ArrayList($products->toArray());
// Look up products that match the filter
$generated = DataObject::get($class)->filterAny($filter)->exclude('ID', $this->owner->ID)->sort('RAND()')->limit($limit - $curCount);
foreach ($generated as $prod) {
$products->push($prod);
}
}
}
示例10: OrderedGalleryItems
/**
* OrderedGalleryItems()
* @note return gallery items ordered as set in admin
*/
public function OrderedGalleryItems()
{
if ($this->Visible == 1) {
return DataObject::get('DisplayAnythingFile', 'GalleryID=' . $this->ID . ' AND Visible = 1', '`File`.`Sort` ASC, `File`.`Created` DESC');
}
return FALSE;
}
示例11: finish
public function finish($data, $form)
{
parent::finish($data, $form);
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if ($steps) {
foreach ($steps as $step) {
if ($step->class == 'Page2PersonalDetailsFormStep') {
$member = new Member();
$data = $step->loadData();
if ($data) {
$member->update($data);
$member->write();
}
}
if ($step->class == 'Page2OrganisationDetailsFormStep') {
$organisation = new Organisation();
$data = $step->loadData();
if ($data) {
$organisation->update($data);
if ($member && $member->ID) {
$organisation->MemberID = $member->ID;
}
$organisation->write();
}
}
// Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
}
}
$controller = $this->getController();
$controller->redirect($controller->Link() . 'finished');
}
示例12: searchFromVars
/**
* @param string $keywords
* @param array $filters [optional]
* @param array $facetSpec [optional]
* @param int $start [optional]
* @param int $limit [optional]
* @param string $sort [optional]
* @return ArrayData
*/
function searchFromVars($keywords, array $filters = array(), array $facetSpec = array(), $start = -1, $limit = -1, $sort = '')
{
$searchable = ShopSearch::get_searchable_classes();
$matches = new ArrayList();
foreach ($searchable as $className) {
$list = DataObject::get($className);
// get searchable fields
$keywordFields = $this->getSearchFields($className);
// build the filter
$filter = array();
// Use parametrized query if SilverStripe >= 3.2
if (SHOP_SEARCH_IS_SS32) {
foreach ($keywordFields as $indexFields) {
$filter[] = array("MATCH ({$indexFields}) AGAINST (?)" => $keywords);
}
$list = $list->whereAny($filter);
} else {
foreach ($keywordFields as $indexFields) {
$filter[] = sprintf("MATCH ({$indexFields}) AGAINST ('%s')", Convert::raw2sql($keywords));
}
// join all the filters with an "OR" statement
$list = $list->where(implode(' OR ', $filter));
}
// add in any other filters
$list = FacetHelper::inst()->addFiltersToDataList($list, $filters);
// add any matches to the big list
$matches->merge($list);
}
return new ArrayData(array('Matches' => $matches, 'Facets' => FacetHelper::inst()->buildFacets($matches, $facetSpec, (bool) Config::inst()->get('ShopSearch', 'auto_facet_attributes'))));
}
示例13: MemberGroup
/**
* Returns all members of a group by ID .
*
* @param int $ID group ID
* @return DataList
*/
public function MemberGroup($ID = 1)
{
if ($group = DataObject::get('Group')->byID($ID)) {
return $group->Members();
}
return false;
}
示例14: getRandomQuestion
public function getRandomQuestion()
{
$qid = Session::get('QACaptchaField.Retry');
if (isset($qid) && $qid) {
// Retry the same question
return DataObject::get_by_id('QACaptchaQuestion', $qid);
}
// Provide empty answer field - the question has not been answered yet
$this->setValue('');
// Get a comma separated list of past questions
$backlog = Session::get('QACaptchaField.Backlog');
if (!$backlog) {
$backlog = array();
}
$sqlBacklog = implode($backlog, ', ');
// Get questions that have not been used before
$random = DataObject::get('QACaptchaQuestion', $sqlBacklog ? "\"QACaptchaQuestion\".\"ID\" NOT IN ({$sqlBacklog})" : '', DB::getConn()->random());
if (!($random && $random->exists())) {
// We have ran out of questions - reset the list
$backlog = array();
Session::clear('QACaptchaField.Backlog');
$random = DataObject::get('QACaptchaQuestion', '', DB::getConn()->random());
}
if ($random && $random->exists()) {
$q = $random->First();
// Add the question to backlog
$backlog[] = $q->ID;
Session::set('QACaptchaField.Backlog', $backlog);
return $q;
}
}
示例15: testCreateWithTransaction
public function testCreateWithTransaction()
{
if (DB::getConn()->supportsTransactions() == true) {
DB::getConn()->transactionStart();
$obj = new TransactionTest_Object();
$obj->Title = 'First page';
$obj->write();
$obj = new TransactionTest_Object();
$obj->Title = 'Second page';
$obj->write();
//Create a savepoint here:
DB::getConn()->transactionSavepoint('rollback');
$obj = new TransactionTest_Object();
$obj->Title = 'Third page';
$obj->write();
$obj = new TransactionTest_Object();
$obj->Title = 'Fourth page';
$obj->write();
//Revert to a savepoint:
DB::getConn()->transactionRollback('rollback');
DB::getConn()->transactionEnd();
$first = DataObject::get('TransactionTest_Object', "\"Title\"='First page'");
$second = DataObject::get('TransactionTest_Object', "\"Title\"='Second page'");
$third = DataObject::get('TransactionTest_Object', "\"Title\"='Third page'");
$fourth = DataObject::get('TransactionTest_Object', "\"Title\"='Fourth page'");
//These pages should be in the system
$this->assertTrue(is_object($first) && $first->exists());
$this->assertTrue(is_object($second) && $second->exists());
//These pages should NOT exist, we reverted to a savepoint:
$this->assertFalse(is_object($third) && $third->exists());
$this->assertFalse(is_object($fourth) && $fourth->exists());
} else {
$this->markTestSkipped('Current database does not support transactions');
}
}