Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Updating the module to support 3.2.X.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Glasl committed Mar 15, 2016
1 parent 7c15ddb commit 5ffa00c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
5 changes: 4 additions & 1 deletion code/dataobjects/MediaTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public function validate() {
if($result->valid() && !$this->Title) {
$result->error('"Title" required!');
}
else if($result->valid() && MediaTag::get_one('MediaTag', "ID != " . (int)$this->ID . " AND Title = '" . Convert::raw2sql($this->Title) . "'")) {
else if($result->valid() && MediaTag::get_one('MediaTag', array(
'ID != ?' => $this->ID,
'Title = ?' => $this->Title
))) {
$result->error('Tag already exists!');
}

Expand Down
18 changes: 14 additions & 4 deletions code/dataobjects/MediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function requireDefaultRecords() {

// Confirm that this media type doesn't already exist before creating it.

if(!MediaType::get_one('MediaType', "Title = '" . Convert::raw2sql($default) . "'")) {
if(!MediaType::get_one('MediaType', array(
'Title = ?' => $default
))) {
$type = MediaType::create();
$type->Title = $default;
$type->write();
Expand Down Expand Up @@ -139,12 +141,17 @@ public function getCMSFields() {

// Allow customisation of media type attributes if a respective media page exists, depending on the current CMS user permissions.

if(MediaPage::get()->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where("MediaType.Title = '" . Convert::raw2sql($this->Title) . "'")->exists()) {
if(MediaPage::get()->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where(array(
'MediaType.Title = ?' => $this->Title
))->exists()) {
$configuration = ($this->checkPermissions() === false) ? GridFieldConfig_RecordViewer::create() : GridFieldConfig_RecordEditor::create()->removeComponentsByType('GridFieldDeleteAction');
$fields->addFieldToTab('Root.Main', GridField::create(
'MediaAttributes',
'Custom Attributes',
MediaAttribute::get()->innerJoin('MediaPage', 'MediaAttribute.MediaPageID = MediaPage.ID')->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where("MediaType.Title = '" . Convert::raw2sql($this->Title) . "' AND MediaAttribute.LinkID = -1"),
MediaAttribute::get()->innerJoin('MediaPage', 'MediaAttribute.MediaPageID = MediaPage.ID')->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where(array(
'MediaType.Title = ?' => $this->Title,
'MediaAttribute.LinkID = ?' => -1
)),
$configuration
)->setModelClass('MediaAttribute'));
}
Expand Down Expand Up @@ -179,7 +186,10 @@ public function validate() {
if($result->valid() && !$this->Title) {
$result->error('"Title" required!');
}
else if($result->valid() && MediaType::get_one('MediaType', "ID != " . (int)$this->ID . " AND Title = '" . Convert::raw2sql($this->Title) . "'")) {
else if($result->valid() && MediaType::get_one('MediaType', array(
'ID != ?' => $this->ID,
'Title = ?' => $this->Title
))) {
$result->error('Type already exists!');
}

Expand Down
4 changes: 3 additions & 1 deletion code/pages/MediaHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ public function getPaginatedChildren($limit = 5, $sort = 'Date', $order = 'DESC'
}
if($valid) {
$from = implode('-', $date);
$children = $children->where("Date >= '" . Convert::raw2sql("{$from} 00:00:00") . "'");
$children = $children->where(array(
'Date >= ?' => "{$from} 00:00:00"
));
}
}

Expand Down
5 changes: 4 additions & 1 deletion code/pages/MediaPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ public function onBeforeWrite() {

// Retrieve existing attributes for the respective media type.

$attributes = MediaAttribute::get()->innerJoin('MediaPage', 'MediaAttribute.MediaPageID = MediaPage.ID')->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where("MediaType.Title = '" . Convert::raw2sql($type) . "' AND MediaAttribute.LinkID = -1");
$attributes = MediaAttribute::get()->innerJoin('MediaPage', 'MediaAttribute.MediaPageID = MediaPage.ID')->innerJoin('MediaType', 'MediaPage.MediaTypeID = MediaType.ID')->where(array(
'MediaType.Title = ?' => $type,
'MediaAttribute.LinkID = ?' => -1
));
if($attributes->exists()) {
foreach($attributes as $attribute) {

Expand Down
4 changes: 2 additions & 2 deletions templates/Layout/MediaPage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h1>{$Title}</h1>
<% if $Images.first %>
<p class='media-page-main-image'>
<span><a href='$Images.first.Link'>{$Images.first.CroppedImage(200, 200)}</a></span>
<span><a href='$Images.first.Link'>{$Images.first.Fill(200, 200)}</a></span>
</p>
<% end_if %>
<% if $Categories %>
Expand All @@ -26,7 +26,7 @@
<p class='media-page-images'>
<% loop $Images %>
<% if not $first %>
<span><a href='{$Link}'>{$CroppedImage(100, 100)}</a></span>
<span><a href='{$Link}'>{$Fill(100, 100)}</a></span>
<% end_if %>
<% end_loop %>
</p>
Expand Down

0 comments on commit 5ffa00c

Please sign in to comment.