2010-03-22 11:49:04 +01:00
|
|
|
<?php
|
2008-04-18 00:03:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decorate {@link DataObject}s which are required to be saved
|
|
|
|
* to the database directly by a {@link MultiFormStep}.
|
|
|
|
* Only needed for objects which aren't stored in the session,
|
|
|
|
* which is the default.
|
2015-11-02 01:38:50 +01:00
|
|
|
*
|
2008-04-18 00:03:51 +02:00
|
|
|
* This decorator also augments get() requests to the datalayer
|
|
|
|
* by automatically filtering out temporary objects.
|
|
|
|
* You can override this filter by putting the following statement
|
|
|
|
* in your WHERE clause:
|
|
|
|
* `<MyDataObjectClass>`.`MultiFormIsTemporary` = 1
|
|
|
|
*
|
|
|
|
* @package multiform
|
|
|
|
*/
|
2013-01-07 01:40:18 +01:00
|
|
|
class MultiFormObjectDecorator extends DataExtension {
|
2015-11-02 01:38:50 +01:00
|
|
|
|
2013-05-25 09:08:55 +02:00
|
|
|
private static $db = array(
|
|
|
|
'MultiFormIsTemporary' => 'Boolean',
|
|
|
|
);
|
2015-11-02 01:38:50 +01:00
|
|
|
|
2013-05-25 09:08:55 +02:00
|
|
|
private static $has_one = array(
|
|
|
|
'MultiFormSession' => 'MultiFormSession',
|
|
|
|
);
|
2015-11-02 01:38:50 +01:00
|
|
|
|
2015-11-23 10:53:45 +01:00
|
|
|
public function augmentSQL(SQLQuery &$query) {
|
2008-04-18 00:03:51 +02:00
|
|
|
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
|
|
|
|
if(
|
2015-11-02 01:38:50 +01:00
|
|
|
strpos($query->where[0], ".`ID` = ") === false
|
|
|
|
&& strpos($query->where[0], ".ID = ") === false
|
2008-04-18 00:03:51 +02:00
|
|
|
&& strpos($query->where[0], "ID = ") !== 0
|
|
|
|
&& !$this->wantsTemporary($query)
|
|
|
|
) {
|
2015-11-02 01:38:50 +01:00
|
|
|
$query->where[] = "\"{$query->from[0]}\".\"MultiFormIsTemporary\" = 0";
|
2008-04-18 00:03:51 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-02 01:38:50 +01:00
|
|
|
|
2008-04-18 00:03:51 +02:00
|
|
|
/**
|
|
|
|
* Determines if the current query is supposed
|
|
|
|
* to be exempt from the automatic filtering out
|
|
|
|
* of temporary records.
|
|
|
|
*
|
|
|
|
* @param SQLQuery $query
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
protected function wantsTemporary($query) {
|
2008-07-21 06:40:18 +02:00
|
|
|
foreach($query->where as $whereClause) {
|
2013-05-25 09:08:55 +02:00
|
|
|
if($whereClause == "\"{$query->from[0]}\".\"MultiFormIsTemporary\" = 1") {
|
|
|
|
return true;
|
|
|
|
}
|
2008-04-18 00:03:51 +02:00
|
|
|
}
|
2013-05-25 09:08:55 +02:00
|
|
|
|
2008-04-18 00:03:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
2010-03-22 11:49:04 +01:00
|
|
|
}
|