mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge branch (pull request #247) 'template-global-fixes' of https://github.com/sminnee/sapphire into sminnee-template-global-fixes
This commit is contained in:
commit
e5e8f489a2
@ -405,32 +405,6 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* returns a date object for use within a template
|
|
||||||
* Usage: $Now.Year - Returns 2006
|
|
||||||
* @return Date The current date
|
|
||||||
*/
|
|
||||||
function Now() {
|
|
||||||
$d = new Date(null);
|
|
||||||
$d->setValue(date("Y-m-d h:i:s"));
|
|
||||||
return $d;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the currently logged in user
|
|
||||||
*/
|
|
||||||
function CurrentMember() {
|
|
||||||
return Member::currentUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the visitor has signed up for a login account before
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
function PastMember() {
|
|
||||||
return Cookie::get("PastMember") ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pushes this controller onto the stack of current controllers.
|
* Pushes this controller onto the stack of current controllers.
|
||||||
* This means that any redirection, session setting, or other things that rely on Controller::curr() will now write to this
|
* This means that any redirection, session setting, or other things that rely on Controller::curr() will now write to this
|
||||||
|
@ -210,13 +210,13 @@ If the user is logged in this will print out
|
|||||||
Welcome Back, Admin
|
Welcome Back, Admin
|
||||||
|
|
||||||
|
|
||||||
#### <% if PastMember %>
|
#### <% if IsRepeatMember %>
|
||||||
|
|
||||||
Detect the visitor's previous experience with the site. `$PastMember` will return true if the visitor has signed up or
|
Detect the visitor's previous experience with the site. `$IsRepeatMember` will return true if the visitor has signed up or logged in on the site before.
|
||||||
logged in on the site before.
|
|
||||||
|
|
||||||
Note that as of version 2.4 `$PastVisitor` is deprecated. If you wish to check if a visitor has been to the site before,
|
Note that as of version 2.4 `$PastVisitor` is deprecated. If you wish to check if a visitor has been to the site before, set a cookie with `Cookie::set()` and test for it with `Cookie::get()`.
|
||||||
set a cookie with `Cookie::set()` and test for it with `Cookie::get()`.
|
|
||||||
|
Note that in 2.4 this variable was called `$PastMember`. This still works in 3.0 but is deprecated.
|
||||||
|
|
||||||
### Date and Time
|
### Date and Time
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
* @package framework
|
* @package framework
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
class SS_Datetime extends Date {
|
class SS_Datetime extends Date implements TemplateGlobalProvider {
|
||||||
|
|
||||||
function setValue($value, $record = null) {
|
function setValue($value, $record = null) {
|
||||||
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
||||||
@ -132,5 +132,11 @@ class SS_Datetime extends Date {
|
|||||||
static function clear_mock_now() {
|
static function clear_mock_now() {
|
||||||
self::$mock_now = null;
|
self::$mock_now = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_template_global_variables() {
|
||||||
|
return array(
|
||||||
|
'Now' => array('method' => 'now', 'casting' => 'SS_Datetime'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +551,13 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
return DataObject::get_one("Member", "\"Member\".\"ID\" = $id", true, 1);
|
return DataObject::get_one("Member", "\"Member\".\"ID\" = $id", true, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the current member is a repeat visitor who has logged in more than once.
|
||||||
|
*/
|
||||||
|
static function is_repeat_member() {
|
||||||
|
return Cookie::get("PastMember") ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID of the current logged in user
|
* Get the ID of the current logged in user
|
||||||
@ -1393,7 +1399,9 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
public static function get_template_global_variables() {
|
public static function get_template_global_variables() {
|
||||||
return array(
|
return array(
|
||||||
'CurrentMember' => 'currentUser',
|
'CurrentMember' => 'currentUser',
|
||||||
'currentUser'
|
'currentUser',
|
||||||
|
'PastMember' => 'is_repeat_member',
|
||||||
|
'IsRepeatMember' => 'is_repeat_member',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,12 @@ class SSViewer_Scope {
|
|||||||
array_splice($this->itemStack, $this->localIndex+1);
|
array_splice($this->itemStack, $this->localIndex+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function obj($name){
|
function getObj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
|
||||||
|
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
||||||
|
return $on->obj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function obj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null){
|
||||||
|
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'Up':
|
case 'Up':
|
||||||
@ -66,10 +71,7 @@ class SSViewer_Scope {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
$this->item = $this->getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
|
||||||
|
|
||||||
$arguments = func_get_args();
|
|
||||||
$this->item = call_user_func_array(array($on, 'obj'), $arguments);
|
|
||||||
|
|
||||||
$this->itemIterator = null;
|
$this->itemIterator = null;
|
||||||
$this->upIndex = $this->currentIndex ? $this->currentIndex : count($this->itemStack)-1;
|
$this->upIndex = $this->currentIndex ? $this->currentIndex : count($this->itemStack)-1;
|
||||||
@ -402,21 +404,33 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
|
|||||||
|
|
||||||
// If we want to provide a casted object, look up what type object to use
|
// If we want to provide a casted object, look up what type object to use
|
||||||
if ($cast) {
|
if ($cast) {
|
||||||
// Get the object to cast as
|
// If the handler returns an object, then we don't need to cast.
|
||||||
$casting = isset($source['casting']) ? $source['casting'] : null;
|
if(is_object($res['value'])) {
|
||||||
// If not provided, use default
|
$res['obj'] = $res['value'];
|
||||||
if (!$casting) $casting = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
|
} else {
|
||||||
|
// Get the object to cast as
|
||||||
|
$casting = isset($source['casting']) ? $source['casting'] : null;
|
||||||
|
|
||||||
$obj = new $casting($property);
|
// If not provided, use default
|
||||||
$obj->setValue($res['value']);
|
if (!$casting) $casting = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
|
||||||
|
|
||||||
$res['obj'] = $obj;
|
$obj = new $casting($property);
|
||||||
|
$obj->setValue($res['value']);
|
||||||
|
|
||||||
|
$res['obj'] = $obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getObj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
|
||||||
|
$result = $this->getInjectedValue($name, (array)$arguments);
|
||||||
|
if($result) return $result['obj'];
|
||||||
|
else return parent::getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
|
||||||
|
}
|
||||||
|
|
||||||
function __call($name, $arguments) {
|
function __call($name, $arguments) {
|
||||||
//extract the method name and parameters
|
//extract the method name and parameters
|
||||||
$property = $arguments[0]; //the name of the function being called
|
$property = $arguments[0]; //the name of the function being called
|
||||||
|
Loading…
x
Reference in New Issue
Block a user