Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
51 dashboards/code/controllers/DashboardController.php
@@ -103,33 +103,47 @@ public function init() {
}
public static function set_allowed_dashlets($dashlets) {
+ self::$allowed_dashlets = $dashlets;
+ }
+
+ protected $allowedDashlets = null;
+
+ public static function get_allowed_dashlets() {
+ return self::$allowed_dashlets;
+ }
+
+ public function getDashletsList() {
+ if ($this->allowedDashlets) {
+ return $this->allowedDashlets;
+ }
+
+ // prune any that have specific requirements
+ foreach (self::$allowed_dashlets as $cls => $title) {
+ $clazz = is_int($cls) ? $title : $cls;
+ $dummy = singleton($clazz);
+ if (!$dummy->canCreate()) {
+ unset(self::$allowed_dashlets[$cls]);
+ }
+ }
+
+ $dashlets = self::$allowed_dashlets;
+
$keys = array_keys($dashlets);
if (count($keys) && is_int($keys[0])) {
foreach (array_values($dashlets) as $dashletClass) {
$title = Object::get_static($dashletClass, 'title');
if (!$title) {
FormField::name_to_label($dashletClass);
}
- self::$allowed_dashlets[$dashletClass] = $title;
+ $this->allowedDashlets[$dashletClass] = $title;
}
} else {
- self::$allowed_dashlets = $dashlets;
+ $this->allowedDashlets = self::$allowed_dashlets;
}
- // prune any that have specific requirements
- foreach (self::$allowed_dashlets as $cls => $title) {
- $dummy = singleton($cls);
- if (!$dummy->canCreate()) {
- unset(self::$allowed_dashlets[$cls]);
- }
- }
+ return $this->allowedDashlets;
}
-
- public static function get_allowed_dashlets() {
- return self::$allowed_dashlets;
- }
-
-
+
public function index() {
$page = $this->currentDashboard ? $this->currentDashboard : $this->getDashboard();
if (!$page || !$page->exists()) {
@@ -218,10 +232,7 @@ public function adddashlet() {
public function AddDashletForm() {
$dashlets = array();
- $allowed = self::get_allowed_dashlets();
- foreach($allowed as $class) {
- $dashlets[$class] = $class::$title == 'Widget Title' ? $class : $class::$title;
- }
+ $dashlets = $this->getDashletsList();
asort($dashlets);
@@ -235,7 +246,7 @@ public function AddDashletForm() {
}
public function doAddDashlet($data, $form) {
- $classes = self::get_allowed_dashlets();
+ $classes = $this->getDashletsList();
$type = $data['DashletClass'];
if(isset($classes[$type])) {
View
8 microblog/_config.php
@@ -6,4 +6,10 @@
Object::add_extension('Image', 'MaximumSizeImageExtension');
-DashboardUser::$default_dashlets = array(array('TimelineDashlet'), array('UserProfileDashlet'));
+DashboardController::set_allowed_dashlets(array(
+ 'TimelineDashlet',
+ 'UserProfileDashlet',
+ 'FriendsDashlet'
+));
+
+DashboardUser::$default_dashlets = array(array('TimelineDashlet'), array('UserProfileDashlet'));
View
57 microblog/code/dashlets/FriendsDashlet.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * @author marcus@silverstripe.com.au
+ * @license BSD License http://silverstripe.org/bsd-license/
+ */
+class FriendsDashlet extends Dashlet {
+ public static $title = "Friends";
+
+
+}
+
+class FriendsDashlet_Controller extends Dashlet_Controller {
+ public $microBlogService;
+ public $securityContext;
+
+ static $dependencies = array(
+ 'microBlogService' => '%$MicroBlogService',
+ 'securityContext' => '%$SecurityContext',
+ );
+
+ public function init() {
+ parent::init();
+
+ Requirements::javascript(THIRDPARTY_DIR . '/jquery-form/jquery.form.js');
+ Requirements::javascript('microblog/javascript/friends.js');
+ }
+
+ public function FriendSearchForm() {
+ $fields = new FieldList(
+ new TextField('Term', _t('MicroBlog.SEARCH_FOR_FRIENDS', 'Find new'))
+ );
+
+ $actions = new FieldList(new FormAction('find', _t('MicroBlog.GO', 'Go')));
+
+ $form = new Form($this, 'FriendSearchForm', $fields, $actions);
+
+ return $form;
+ }
+
+ public function find($data, Form $form) {
+ $term = isset($data['Term']) ? $data['Term'] : null;
+
+ if ($term) {
+ if ($this->request->isAjax()) {
+ $possible = $this->microBlogService->findMember($term);
+ if ($possible) {
+ $output = $this->customise(array('Items' => $possible))->renderWith('FriendsResultList');
+ return $output;
+ }
+ }
+ }
+
+ $this->redirectBack();
+ }
+
+}
View
19 microblog/code/dataobjects/Friendship.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * Describes a relationship between users
+ *
+ * @author marcus@silverstripe.com.au
+ * @license BSD License http://silverstripe.org/bsd-license/
+ */
+class Friendship extends DataObject {
+
+ public static $db = array(
+ 'Status' => "Enum('Approved,Pending')",
+ );
+
+ public static $has_one = array(
+ 'Initiator' => 'Member',
+ 'Other' => 'Member',
+ );
+}
View
9 microblog/code/extensions/MicroBlogMember.php
@@ -46,4 +46,13 @@ public function memberFolder() {
return $this->owner->UploadFolder();
}
+
+ public function Friends() {
+
+ }
+
+ public function Link() {
+ $microblog = DataObject::get_one('SiteDashboardPage', '"ParentID" = 0');
+ return $microblog->Link('board/main/' . $this->owner->ID);
+ }
}
View
38 microblog/code/services/MicroBlogService.php
@@ -5,6 +5,16 @@
* @license BSD License http://silverstripe.org/bsd-license/
*/
class MicroBlogService {
+
+ /**
+ * @var DataService
+ */
+ public $dataService;
+
+ public static $dependencies = array(
+ 'dataService' => '%$DataService',
+ );
+
public function __construct() {
}
@@ -23,7 +33,7 @@ public function webEnabledMethods() {
*/
public function globalFeed($number = 20) {
$number = (int) $number;
- return singleton('DataService')->getAllMicroPost(null, '"Created" DESC', '', '0,' . $number);
+ return $this->dataService->getAllMicroPost(null, '"Created" DESC', '', '0,' . $number);
}
/**
@@ -63,7 +73,7 @@ public function getStatusUpdates(DataObject $member, $sinceTime = null, $beforeP
$filter['ID:LessThan'] = $beforePost;
}
- $posts = singleton('DataService')->getAllMicroPost($filter, '"Created" DESC', '', '0, ' . $number);
+ $posts = $this->dataService->getAllMicroPost($filter, '"Created" DESC', '', '0, ' . $number);
return $posts;
}
}
@@ -99,9 +109,31 @@ public function getTimeline(DataObject $member, $sinceTime = null, $beforePost =
$filter['ID:LessThan'] = $beforePost;
}
- $posts = singleton('DataService')->getAllMicroPost($filter, '"Created" DESC', '', '0, ' . $number);
+ $posts = $this->dataService->getAllMicroPost($filter, '"Created" DESC', '', '0, ' . $number);
return $posts;
}
+
+ /**
+ * Search for a member or two
+ *
+ * @param string $searchTerm
+ */
+ public function findMember($searchTerm) {
+ $term = Convert::raw2sql($searchTerm);
+ $filter = '"FirstName" LIKE \'%' . $term .'%\' OR "Surname" LIKE \'%' . $term . '%\'';
+
+ $items = $this->dataService->getAllMember($filter);
+
+ return $items;
+
+// $filter = array(
+// 'FirstName:PartialMatch' => $searchTerm,
+// 'Surname:PartialMatch' => $searchTerm,
+// 'Email:PartialMatch' => $searchTerm,
+// );
+//
+// $list = DataList::create('Member')->dataQuery()->
+ }
public function addFollower(DataObject $member, DataObject $follower) {
$follower->follow($member);
View
21 microblog/javascript/friends.js
@@ -0,0 +1,21 @@
+
+;(function ($) {
+ $.entwine('microblog', function ($) {
+ $('#Form_FriendSearchForm').entwine({
+ onmatch: function () {
+ this.ajaxForm(function (data) {
+ $('.friendsSearchList').empty();
+ $('.friendsSearchList').append(data);
+ return false;
+ })
+ }
+ })
+
+ $('input.addFriendButton').entwine({
+ onclick: function () {
+
+ }
+ })
+ })
+
+})(jQuery);
View
20 microblog/templates/Dashlets/FriendsDashlet.ss
@@ -0,0 +1,20 @@
+<% if CurrentMember %>
+
+ <% if $CurrentMember.ID != $OwnerID %>
+ <!-- add the user we're looking at as a friend -->
+
+ <% else %>
+ $FriendSearchForm
+
+ <div class="friendsSearchList">
+
+ </div>
+ <% end_if %>
+
+ <!-- list of this user's friends -->
+ <% with Owner.Friends %>
+
+ <% end_with %>
+<% else %>
+ Please login
+<% end_if %>
View
7 microblog/templates/FriendsResultList.ss
@@ -0,0 +1,7 @@
+
+<input type="hidden" id="AddFriendLink" value="$Link(addfriend)" />
+<% loop Items %>
+<div class="friendsSearchResult">
+ <a href="$Link">$FirstName $Surname</a> <input type="button" class="addFriendButton" data-id="$ID" value="Add" />
+</div>
+<% end_loop %>

No commit comments for this range

Something went wrong with that request. Please try again.