mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02: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.
|
||||
* 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
|
||||
|
||||
|
||||
#### <% if PastMember %>
|
||||
#### <% if IsRepeatMember %>
|
||||
|
||||
Detect the visitor's previous experience with the site. `$PastMember` will return true if the visitor has signed up or
|
||||
logged in on the site before.
|
||||
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.
|
||||
|
||||
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()`.
|
||||
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()`.
|
||||
|
||||
Note that in 2.4 this variable was called `$PastMember`. This still works in 3.0 but is deprecated.
|
||||
|
||||
### Date and Time
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
* @package framework
|
||||
* @subpackage model
|
||||
*/
|
||||
class SS_Datetime extends Date {
|
||||
class SS_Datetime extends Date implements TemplateGlobalProvider {
|
||||
|
||||
function setValue($value, $record = null) {
|
||||
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
||||
@ -132,5 +132,11 @@ class SS_Datetime extends Date {
|
||||
static function clear_mock_now() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -1393,7 +1399,9 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
||||
public static function get_template_global_variables() {
|
||||
return array(
|
||||
'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);
|
||||
}
|
||||
|
||||
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) {
|
||||
case 'Up':
|
||||
@ -66,10 +71,7 @@ class SSViewer_Scope {
|
||||
break;
|
||||
|
||||
default:
|
||||
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
||||
|
||||
$arguments = func_get_args();
|
||||
$this->item = call_user_func_array(array($on, 'obj'), $arguments);
|
||||
$this->item = $this->getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
|
||||
|
||||
$this->itemIterator = null;
|
||||
$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 ($cast) {
|
||||
// Get the object to cast as
|
||||
$casting = isset($source['casting']) ? $source['casting'] : null;
|
||||
// If not provided, use default
|
||||
if (!$casting) $casting = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
|
||||
// If the handler returns an object, then we don't need to cast.
|
||||
if(is_object($res['value'])) {
|
||||
$res['obj'] = $res['value'];
|
||||
} else {
|
||||
// Get the object to cast as
|
||||
$casting = isset($source['casting']) ? $source['casting'] : null;
|
||||
|
||||
$obj = new $casting($property);
|
||||
$obj->setValue($res['value']);
|
||||
// If not provided, use default
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
//extract the method name and parameters
|
||||
$property = $arguments[0]; //the name of the function being called
|
||||
|
Loading…
Reference in New Issue
Block a user