本文整理汇总了PHP中DataObjectSet类的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectSet类的具体用法?PHP DataObjectSet怎么用?PHP DataObjectSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataObjectSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: PublisherMembers
/**
* Returns a DataObjectSet of all the members that can publish this page
*/
public function PublisherMembers()
{
if ($this->owner->CanPublishType == 'OnlyTheseUsers') {
$groups = $this->owner->PublisherGroups();
$members = new DataObjectSet();
if ($groups) {
foreach ($groups as $group) {
$members->merge($group->Members());
}
}
// Default to ADMINs, if something goes wrong
if (!$members->Count()) {
$group = Permission::get_groups_by_permission('ADMIN')->first();
$members = $group->Members();
}
return $members;
} elseif ($this->owner->CanPublishType == 'Inherit') {
if ($this->owner->Parent()->Exists()) {
return $this->owner->Parent()->PublisherMembers();
} else {
return SiteConfig::current_site_config()->PublisherMembers();
}
} elseif ($this->owner->CanPublishType == 'LoggedInUsers') {
return Permission::get_members_by_permission('CMS_ACCESS_CMSMain');
} else {
$group = Permission::get_groups_by_permission('ADMIN')->first();
return $group->Members();
}
}
示例3: sourceItems
function sourceItems()
{
if ($this->sourceItems) {
return $this->sourceItems;
}
$limitClause = '';
if (isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) {
$limitClause = $_REQUEST['ctf'][$this->Name()]['start'] . ", {$this->pageSize}";
} else {
$limitClause = "0, {$this->pageSize}";
}
$dataQuery = $this->getQuery($limitClause);
$records = $dataQuery->execute();
$items = new DataObjectSet();
foreach ($records as $record) {
if (!get_class($record)) {
$record = new DataObject($record);
}
$items->push($record);
}
$dataQuery = $this->getQuery();
$records = $dataQuery->execute();
$unpagedItems = new DataObjectSet();
foreach ($records as $record) {
if (!get_class($record)) {
$record = new DataObject($record);
}
$unpagedItems->push($record);
}
$this->unpagedSourceItems = $unpagedItems;
$this->totalCount = $this->unpagedSourceItems ? $this->unpagedSourceItems->TotalItems() : null;
return $items;
}
示例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: get
/**
* Return Facebook events for the given username with a limit.
*
* @param string $name Facebook username to get events from
* @param int $limit Number of events to get
* @param array Query parameters to filter events e.g. "since" => "yesterday" (future events) or "until" => "yesterday" (past events)
*/
public static function get($name, $limit, $query = array())
{
$api = new FBAPI();
$results = $api->graph($name, 'events', $query);
if ($results instanceof FBAPI_Exception) {
return false;
}
// return false when there's no data
if (empty($results['data'])) {
return false;
}
$output = new DataObjectSet();
$count = 0;
foreach ($results['data'] as $record) {
if ($limit && $count >= $limit) {
break;
}
// we have to do another request to get the detail of the event.
$detail = $api->graph($record['id']);
$record = array_merge($record, $detail);
$output->push(new FBEvent($record));
$count++;
}
return $output;
}
示例6: displaytable
/**
* Returns the table of results to be displayed in the table of
* details loaded from the file
*/
function displaytable()
{
// Check that a file was uploaded
$tempFile = fopen($_FILES['ImportFile']['tmp_name'], 'r');
// display some error if the file cannot be opened
if (!$tempFile) {
return 'The selected file did not arrive at the server';
}
$this->clientFileName = $_FILES['ImportFile']['name'];
$table = $sessionTable = array();
while (($row = fgetcsv($tempFile)) !== false) {
if (!$this->tableColumns) {
$this->parseTableHeader($row);
} else {
$newRow = array();
$newSessionTableRow = array();
foreach ($row as $cell) {
$newRow[] = $this->parseCSVCell($cell);
$newSessionTableRow[] = $cell;
}
$cells = new DataObjectSet($newRow);
$table[] = $cells->customise(array('Cells' => $cells));
$sessionTable[] = $newSessionTableRow;
}
}
fclose($tempFile);
$this->table = new DataObjectSet($table);
Session::set("ImportFile.{$_REQUEST['ID']}", $sessionTable);
return $this->renderWith('Newsletter_RecipientImportField_Table');
}
示例7: execute
function execute()
{
set_error_handler('exception_error_handler');
$results = false;
$msg = array('text' => $this->type() == 'SELECT' ? 'no records' : 'no errors', 'type' => 'good');
try {
$results = DB::getConn()->query($this->query, E_USER_NOTICE);
} catch (Exception $e) {
$msg = array('text' => htmlentities($e->getMessage()), 'type' => 'error');
}
restore_error_handler();
$fields = new DataObjectSet();
$records = new DataObjectSet();
if (isset($results) && $results instanceof SS_Query) {
foreach ($results as $result) {
$record = new DBP_Record();
$data = array();
foreach ($result as $field => $val) {
if (!$fields->find('Label', $field)) {
$fields->push(new DBP_Field($field));
}
$data[$field] = strlen($val) > 64 ? substr($val, 0, 63) . '<span class="truncated">…</span>' : $val;
}
$record->Data($data);
$records->push($record);
}
}
return array('Query' => $this->query, 'Fields' => $fields, 'Records' => $records, 'Message' => $msg);
}
示例8: updateMembers
/**
* @param DataObjectSet All members to check
* @param Int
* @return DataObjectSet
*/
protected function updateMembers($members, $minSpamScore = 0)
{
$checker = $this->getChecker();
$checks = $checker->update($members);
$spamMembers = new DataObjectSet();
if ($checks) {
foreach ($checks as $id => $check) {
// TODO More expressive error reporting - easy for the task to "get stuck" on one member
if (!$id) {
continue;
}
$member = $members->find('ID', $id);
// Its important to fall back to a rating of 0, to avoid querying the same members successively
// (e.g. when service APIs fail to respond).
// TODO Add a way to force re-checking of members
$member->SpamCheckScore = $check['score'] ? $check['score'] : 0;
$memberData = $member->SpamCheckData ? (array) json_decode($member->SpamCheckData) : array();
$memberData[get_class($this)] = (array) $check['data'];
$member->SpamCheckData = json_encode($memberData);
$member->write();
if ($member->SpamCheckScore > $minSpamScore) {
$spamMembers->push($member);
}
}
}
return $spamMembers;
}
示例9: get
public static function get($name, $limit)
{
if (!$name) {
return false;
}
$api = new FBAPI();
$results = $api->graph($name, 'photos');
// @todo figure out what to do with exceptions. Log them using SS_Log::log()?
if ($results instanceof FBAPI_Exception) {
return false;
}
// return false when there's no data
if (empty($results['data'])) {
return false;
}
$output = new DataObjectSet();
$count = 0;
foreach ($results['data'] as $record) {
if ($limit && $count >= $limit) {
break;
}
$output->push(new FBPhoto($record));
$count++;
}
return $output;
}
示例10: Photos
function Photos()
{
Requirements::javascript("flickrservice/javascript/prototype.js");
Requirements::javascript("flickrservice/javascript/effects.js");
Requirements::javascript("flickrservice/javascript/lightwindow.js");
Requirements::css("flickrservice/css/FlickrGallery.css");
Requirements::css("flickrservice/css/lightwindow.css");
if ($pos = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
$version = substr($_SERVER['HTTP_USER_AGENT'], $pos + 5, 3);
if ($version < 7) {
Requirements::css("flickrservice/css/lightwindowIE6.css");
}
}
$flickr = new FlickrService();
try {
$photos = $flickr->getPhotos(NULL, $this->User, $this->NumberToShow, 1, $this->Sortby);
} catch (Exception $e) {
return false;
}
$output = new DataObjectSet();
foreach ($photos->PhotoItems as $photo) {
$output->push(new ArrayData(array("Title" => htmlentities($photo->title), "Link" => "http://farm1.static.flickr.com/" . $photo->image_path . ".jpg", "Image" => "http://farm1.static.flickr.com/" . $photo->image_path . "_s.jpg")));
}
return $output;
}
示例11: getCMSFields
function getCMSFields()
{
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
if (!$subsites) {
$subsites = new DataObjectSet();
}
if (Subsite::hasMainSitePermission(null, array("CMS_ACCESS_CMSMain"))) {
$subsites->push(new ArrayData(array('Title' => 'Main site', "\"ID\"" => 0)));
}
if ($subsites->Count()) {
$subsiteSelectionField = new DropdownField("CopyContentFromID_SubsiteID", "Subsite", $subsites->toDropdownMap('ID', 'Title'), $this->CopyContentFromID ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID'));
}
// Setup the linking to the original page.
$pageSelectionField = new SubsitesTreeDropdownField("RelatedPageID", _t('VirtualPage.CHOOSE', "Choose a page to link to"), "SiteTree", "ID", "MenuTitle");
if (isset($_GET['RelatedPageID_SubsiteID'])) {
$pageSelectionField->setSubsiteID($_GET['RelatedPageID_SubsiteID']);
}
$pageSelectionField->setFilterFunction(create_function('$item', 'return $item->ClassName != "VirtualPage";'));
if ($subsites->Count()) {
$fields = new FieldSet($subsiteSelectionField, $pageSelectionField);
} else {
$fields = new FieldSet($pageSelectionField);
}
return $fields;
}
示例12: PublisherMembers
/**
* Returns a DataObjectSet of all the members that can publish pages
* on this site by default
*/
public function PublisherMembers()
{
if ($this->owner->CanPublishType == 'OnlyTheseUsers') {
$groups = $this->owner->PublisherGroups();
$members = new DataObjectSet();
if ($groups) {
foreach ($groups as $group) {
$members->merge($group->Members());
}
}
// Default to ADMINs, if something goes wrong
if (!$members->Count()) {
$group = Permission::get_groups_by_permission('ADMIN')->first();
$members = $group->Members();
}
return $members;
} else {
if ($this->owner->CanPublishType == 'LoggedInUsers') {
// We don't want to return every user in the CMS....
return Permission::get_members_by_permission('CMS_ACCESS_CMSMain');
} else {
$group = Permission::get_groups_by_permission('ADMIN')->first();
return $group->Members();
}
}
}
示例13: getCMSFields
function getCMSFields()
{
$fields = parent::getCMSFields();
$subsites = DataObject::get('Subsite');
if (!$subsites) {
$subsites = new DataObjectSet();
}
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
$subsiteSelectionField = new DropdownField("CopyContentFromID_SubsiteID", "Subsite", $subsites->toDropdownMap('ID', 'Title'), $this->CopyContentFromID ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID'));
$fields->addFieldToTab('Root.Content.Main', $subsiteSelectionField, 'CopyContentFromID');
// Setup the linking to the original page.
$pageSelectionField = new SubsitesTreeDropdownField("CopyContentFromID", _t('VirtualPage.CHOOSE', "Choose a page to link to"), "SiteTree", "ID", "MenuTitle");
$pageSelectionField->setFilterFunction(create_function('$item', 'return !($item instanceof VirtualPage);'));
if (Controller::has_curr() && Controller::curr()->getRequest()) {
$subsiteID = Controller::curr()->getRequest()->getVar('CopyContentFromID_SubsiteID');
$pageSelectionField->setSubsiteID($subsiteID);
}
$fields->replaceField('CopyContentFromID', $pageSelectionField);
// Create links back to the original object in the CMS
if ($this->CopyContentFromID) {
$editLink = "admin/show/{$this->CopyContentFromID}/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID;
$linkToContent = "\n\t\t\t\t<a class=\"cmsEditlink\" href=\"{$editLink}\">" . _t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . "</a>";
$fields->removeByName("VirtualPageContentLinkLabel");
$fields->addFieldToTab("Root.Content.Main", $linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent), 'Title');
$linkToContentLabelField->setAllowHTML(true);
}
$fields->addFieldToTab('Root.Content.Metadata', new TextField('CustomMetaTitle', 'Title (overrides inherited value from the source)'), 'MetaTitle');
$fields->addFieldToTab('Root.Content.Metadata', new TextareaField('CustomMetaKeywords', 'Keywords (overrides inherited value from the source)'), 'MetaKeywords');
$fields->addFieldToTab('Root.Content.Metadata', new TextareaField('CustomMetaDescription', 'Description (overrides inherited value from the source)'), 'MetaDescription');
$fields->addFieldToTab('Root.Content.Metadata', new TextField('CustomExtraMeta', 'Custom Meta Tags (overrides inherited value from the source)'), 'ExtraMeta');
return $fields;
}
示例14: 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;
}
示例15: testRSSFeed
function testRSSFeed()
{
$list = new DataObjectSet();
$list->push(new RSSFeedTest_ItemA());
$list->push(new RSSFeedTest_ItemB());
$list->push(new RSSFeedTest_ItemC());
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->feedContent();
//Debug::message($content);
$this->assertContains('<link>http://www.example.org/item-a/</link>', $content);
$this->assertContains('<link>http://www.example.com/item-b.html</link>', $content);
$this->assertContains('<link>http://www.example.com/item-c.html</link>', $content);
$this->assertContains('<title>ItemA</title>', $content);
$this->assertContains('<title>ItemB</title>', $content);
$this->assertContains('<title>ItemC</title>', $content);
$this->assertContains('<description>ItemA Content</description>', $content);
$this->assertContains('<description>ItemB Content</description>', $content);
$this->assertContains('<description>ItemC Content</description>', $content);
// Feed #2 - put Content() into <title> and AltContent() into <description>
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description", "Content", "AltContent");
$content = $rssFeed->feedContent();
$this->assertContains('<title>ItemA Content</title>', $content);
$this->assertContains('<title>ItemB Content</title>', $content);
$this->assertContains('<title>ItemC Content</title>', $content);
$this->assertContains('<description>ItemA AltContent</description>', $content);
$this->assertContains('<description>ItemB AltContent</description>', $content);
$this->assertContains('<description>ItemC AltContent</description>', $content);
}