/** * 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; }
/** * 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(); } }
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; }
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; }
/** * 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; }
/** * 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'); }
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); }
/** * @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; }
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; }
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; }
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; }
/** * 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(); } } }
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; }
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; }
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); }
function testRSSFeed() { $list = new DataObjectSet(); $list->push(new RSSFeedTest_ItemA()); $list->push(new RSSFeedTest_ItemB()); $list->push(new RSSFeedTest_ItemC()); $origServer = $_SERVER; $_SERVER['HTTP_HOST'] = 'www.example.org'; Director::setBaseURL('/'); $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); Director::setBaseURL(null); $_SERVER = $origServer; }
function FeedItems() { $output = new DataObjectSet(); include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php')); $t1 = microtime(true); $this->feed = new SimplePie($this->AbsoluteRssUrl, TEMP_FOLDER); $this->feed->init(); if($items = $this->feed->get_items(0, $this->NumberToShow)) { foreach($items as $item) { // Cast the Date $date = new Date('Date'); $date->setValue($item->get_date()); // Cast the Title $title = new Text('Title'); $title->setValue($item->get_title()); $output->push(new ArrayData(array( 'Title' => $title, 'Date' => $date, 'Link' => $item->get_link() ))); } return $output; } }
function Times() { $output = new DataObjectSet(); for ($i = 0; $i < $this->value; $i++) { $output->push(new ArrayData(array('Number' => $i + 1))); } return $output; }
function Fields() { $fields = new DataObjectSet(); foreach (DB::fieldList($this->Name) as $name => $spec) { $fields->push(new DBP_Field($this->Name . '.' . $name)); } return $fields; }
function TagsCollection() { Requirements::themedCSS("tagcloud"); $allTags = array(); $max = 0; $container = BlogTree::current(); $entries = $container->Entries(); if ($entries) { foreach ($entries as $entry) { $theseTags = split(" *, *", mb_strtolower(trim($entry->Tags))); foreach ($theseTags as $tag) { if ($tag != "") { $allTags[$tag] = isset($allTags[$tag]) ? $allTags[$tag] + 1 : 1; //getting the count into key => value map $max = $allTags[$tag] > $max ? $allTags[$tag] : $max; } } } if ($allTags) { //TODO: move some or all of the sorts to the database for more efficiency if ($this->Limit > 0) { $allTags = array_slice($allTags, 0, $this->Limit, true); } if ($this->Sortby == "alphabet") { $this->natksort($allTags); } else { uasort($allTags, array($this, "column_sort_by_popularity")); // sort by frequency } $sizes = array(); foreach ($allTags as $tag => $count) { $sizes[$count] = true; } $offset = 0; $numsizes = count($sizes) - 1; //Work out the number of different sizes $buckets = count(self::$popularities) - 1; // If there are more frequencies than buckets, divide frequencies into buckets if ($numsizes > $buckets) { $numsizes = $buckets; } else { $offset = round(($buckets - $numsizes) / 2); } foreach ($allTags as $tag => $count) { $popularity = round($count / $max * $numsizes) + $offset; $popularity = min($buckets, $popularity); $class = self::$popularities[$popularity]; $allTags[$tag] = array("Tag" => $tag, "Count" => $count, "Class" => $class, "Link" => $container->Link('tag') . '/' . urlencode($tag)); } } $output = new DataObjectSet(); foreach ($allTags as $tag => $fields) { $output->push(new ArrayData($fields)); } return $output; } return; }
function run(DataObjectSet $pages) { $pageIDs = $pages->column('ID'); foreach ($pageIDs as $pageID) { FormResponse::add("\$('Form_EditForm').reloadIfSetTo({$pageID});"); } $this->batchaction($pages, 'batchApprove', _t('BatchApprovePages.APPROVED_PAGES', 'Approved %d pages, %d failures')); return FormResponse::respond(); }
public function stageChildren() { $items = $this->getClient()->get_items(); $children = new DataObjectSet(); foreach ($items as $item) { $children->push(new RssContentItem($this, $item)); } return $children; }
/** * Returns the days of the current week as a DataObjectSet of dates. */ function I18nDaysOfWeek() { $days = new DataObjectSet(); $end = $this->I18nLastDayOfWeek()->next(); for ($day = $this->I18nFirstDayOfWeek(); $day->RAW() != $end->RAW(); $day = $day->next()) { $days->push($day); } return $days; }
/** * Creates a new optionset field. * @param name The field name * @param title The field title * @param source DataObjectSet * @param value The current value * @param form The parent form */ function __construct($name, $title = "", $addresses = null, $value = "", $form = null) { $this->addresses = $addresses; $source = array(); if ($this->addresses) { $source = $this->addresses->map("ID", "FullString"); } parent::__construct($name, $title, $source, $value, $form); }
function FacebookFriends() { $friends = Facebook::get_list_of_friends($this->owner->FacebookOAuthToken); $set = new DataObjectSet(); foreach ($friends as $friend) { $set->push(new ArrayData(array('ID' => $friend["id"], 'Name' => $friend["name"], 'PictureURL' => $friend["picture"]['data']['url']))); } return $set; }
/** * Return a DataObjectSet of SS_Report subclasses * that are available for use. * * @return DataObjectSet */ public function Reports() { $output = new DataObjectSet(); foreach (SS_Report::get_reports('ReportAdmin') as $report) { if ($report->canView()) { $output->push($report); } } return $output; }
function getTagsCollection() { $set = new DataObjectSet(); $tags = split(self::$separator, $this->owner->Tags); if($tags) foreach($tags as $tag) { $set->push(new ArrayData(array( 'Title' => $tag ))); } return $set; }
function AvailableWidgets() { $classes = ClassInfo::subclassesFor('Widget'); array_shift($classes); $widgets = new DataObjectSet(); foreach ($classes as $class) { $widgets->push(singleton($class)); } return $widgets; }
public function Items() { $this->Pages = Versioned::get_by_stage('SiteTree', 'Live'); $newPages = new DataObjectSet(); foreach ($this->Pages as $page) { // Only include pages from this host if (parse_url($page->AbsoluteLink(), PHP_URL_HOST) == $_SERVER['HTTP_HOST']) { // If the page has been set to 0 priority, we set a flag so it won't be included if (isset($page->Priority) && $page->Priority <= 0) { $page->Include = false; } else { $page->Include = true; } // The one field that isn't easy to deal with in the template is // Change frequency, so we set that here. $properties = $page->toMap(); $created = new Datetime($properties['Created']); $now = new Datetime(); $versions = $properties['Version']; $timediff = $now->format('U') - $created->format('U'); // Check how many revisions have been made over the lifetime of the // Page for a rough estimate of it's changing frequency. $period = $timediff / ($versions + 1); if ($period > 60 * 60 * 24 * 365) { // > 1 year $page->ChangeFreq = 'yearly'; } else { if ($period > 60 * 60 * 24 * 30) { // > ~1 month $page->ChangeFreq = 'monthly'; } else { if ($period > 60 * 60 * 24 * 7) { // > 1 week $page->ChangeFreq = 'weekly'; } else { if ($period > 60 * 60 * 24) { // > 1 day $page->ChangeFreq = 'daily'; } else { if ($period > 60 * 60) { // > 1 hour $page->ChangeFreq = 'hourly'; } else { // < 1 hour $page->ChangeFreq = 'always'; } } } } } $newPages->push($page); } } return $newPages; }
/** * Gets the children of this content source * * @TODO Change this to return a fixed list of categories / tags, from which the * children are subsequently retrieved * * @return DataObjectSet */ public function stageChildren() { $children = new DataObjectSet(); if ($this->BlipUser) { $items = $this->getClient()->get_videos('posts', $this->BlipUser, array('count' => 100)); foreach ($items as $item) { $children->push(new BlipTVContentItem($this, $item)); } } return $children; }