Skip to content

Commit

Permalink
Merge pull request #1 from nickdunn/master
Browse files Browse the repository at this point in the history
Tidying up
  • Loading branch information
kanduvisla committed Aug 9, 2011
2 parents f6fe951 + 1807b45 commit fb465e8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 65 deletions.
6 changes: 0 additions & 6 deletions assets/statusfield.css

This file was deleted.

5 changes: 5 additions & 0 deletions assets/statusfield.publish.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
div.field-status label { margin-bottom: 0; }
table.status th, table.status td { padding: 5px 8px; }
table.status { margin-left: -8px; }
table.status input { width: 98%; margin: 0; display: block; }
table.status tr.valid td { vertical-align: middle; }
File renamed without changes.
28 changes: 23 additions & 5 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function about()
'name' => 'Giel Berkers',
'website' => 'http://www.gielberkers.com',
'email' => 'info@gielberkers.com'),
'description' => 'Store the status and hold a history of previous statusses.'
'description' => 'Store the status and hold a history of previous statuses.'
);
}

Expand All @@ -30,14 +30,18 @@ public function getSubscribedDelegates()

public function initialiseHead($context)
{
Administration::instance()->Page->addScriptToHead(URL . '/extensions/statusfield/assets/statusfield.js', 101, false);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/statusfield/assets/statusfield.css', 'screen', 101, false);
$page = $context['parent']->Page;
if ($page instanceof ContentPublish && in_array($page->_context['page'], array('new', 'edit')))
{
Administration::instance()->Page->addScriptToHead(URL . '/extensions/statusfield/assets/statusfield.publish.js', 101, false);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/statusfield/assets/statusfield.publish.css', 'screen', 101, false);
}
}

public function uninstall()
{
Symphony::Database()->query("DROP TABLE `tbl_fields_status`");
Symphony::Database()->query("DROP TABLE `tbl_fields_status_statusses`");
Symphony::Database()->query("DROP TABLE `tbl_fields_status_statuses`");
}

public function install()
Expand All @@ -50,7 +54,7 @@ public function install()
PRIMARY KEY (`id`),
UNIQUE KEY `field_id` (`field_id`)
)");
Symphony::Database()->query("CREATE TABLE `tbl_fields_status_statusses` (
Symphony::Database()->query("CREATE TABLE `tbl_fields_status_statuses` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`entry_id` int(11) unsigned NOT NULL,
Expand All @@ -60,4 +64,18 @@ public function install()
PRIMARY KEY (`id`)
)");
}

public function update()
{
try{
if(version_compare($previousVersion, '0.2', '<')){
Symphony::Database()->query(
"RENAME `tbl_fields_status_statusses` TO `tbl_fields_status_statuses`"
);
}
}
catch(Exception $e){

}
}
}
67 changes: 22 additions & 45 deletions fields/field.status.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function __construct(&$parent){
}

function canToggle(){
return false;
return true;
}

function allowDatasourceOutputGrouping(){
Expand Down Expand Up @@ -46,7 +46,7 @@ public function displaySettingsPanel(&$wrapper, $errors = null) {
$options = array();
$fieldname = 'fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix;

$label = Widget::Label(__('Statusses'));
$label = Widget::Label(__('Statuses'));
$input = Widget::Input('fields['.$this->get('sortorder').'][options]', General::sanitize($this->get('options')));
$label->appendChild($input);
$wrapper->appendChild($label);
Expand Down Expand Up @@ -84,7 +84,7 @@ function commit(){


// Show the publish panel:
function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){
function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL, $entry_id=NULL){
// Get the toggle states:
$states = $this->getToggleStates();
natsort($states);
Expand All @@ -106,34 +106,29 @@ function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldn
$row->appendChild(new XMLElement('th', __('Status')));
if($this->get('valid_until') == 'yes')
{
$row->appendChild(new XMLElement('th', __('Valid until'), array('class'=>'date')));
$row->appendChild(new XMLElement('th', __('Valid Until'), array('class'=>'date')));
}

$table->appendChild($row);

// Show the different states:
$fieldId = $this->get('id');

// Get the Entry ID (code 'borrowed' from Nils Hörrmann's Subsection Manager):
$currentPageURL = Administration::instance()->getCurrentPageURL();
preg_match_all('/\d+/', $currentPageURL, $entry_id, PREG_PATTERN_ORDER);
$entry_id = $entry_id[0][count($entry_id[0])-1];

if($entry_id != false)
if($entry_id != NULL)
{
$results = Symphony::Database()->fetch('SELECT `date`, `status`, `valid_until` FROM `tbl_fields_status_statusses` WHERE `field_id` = '.$fieldId.' AND `entry_id` = '.$entry_id.' ORDER BY `date`, `id`;');
$results = Symphony::Database()->fetch('SELECT `date`, `status`, `valid_until` FROM `tbl_fields_status_statuses` WHERE `field_id` = '.$fieldId.' AND `entry_id` = '.$entry_id.' ORDER BY `date`, `id`;');
foreach($results as $result)
{
$row = new XMLElement('tr');
$row->appendChild(new XMLElement('td', $this->invertDate($result['date'])));
$row->appendChild(new XMLElement('td', DateTimeObj::get('d F Y', $result['date'])));
$row->appendChild(new XMLElement('td', $result['status']));
if($this->get('valid_until') == 'yes')
{
if($result['valid_until'] == null)
{
$valid_until = '-';
} else {
$valid_until = $this->invertDate($result['valid_until']);
$valid_until = DateTimeObj::get('d F Y', $result['valid_until']);
}
$row->appendChild(new XMLElement('td', $valid_until));
}
Expand All @@ -143,7 +138,7 @@ function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldn

// Show the footer (option to set new status):
$row = new XMLElement('tr', null, array('class'=>'footer'));
$row->appendChild(new XMLElement('td', __('Update:')));
$row->appendChild(new XMLElement('td', DateTimeObj::get('d F Y'), array('class' => 'inactive')));
$td = new XMLElement('td', null);
if($this->get('valid_until') == 'yes')
{
Expand All @@ -157,10 +152,10 @@ function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldn
if($this->get('valid_until') == 'yes')
{
$row = new XMLElement('tr', null, array('class'=>'valid'));
$row->appendChild(new XMLElement('td', __('Valid until:')));
$row->appendChild(new XMLElement('td', __('Valid Until')));
$td = new XMLElement('td', null, array('colspan'=>2));
$fieldname = 'fields['.$this->get('element_name').'-until]';
$td->appendChild(Widget::Input($fieldname, __('DD-MM-YYYY')));
$td->appendChild(Widget::Input($fieldname, DateTimeObj::get('d F Y', strtotime('next year'))));
$row->appendChild($td);
$table->appendChild($row);
}
Expand Down Expand Up @@ -197,16 +192,16 @@ public function processRawFieldData($data, &$status, $simulate=false, $entry_id=
// $statusStr = $_POST['fields'][$this->get('element_name')];
$statusStr = $data;

if($dateUntil != __('DD-MM-YYYY') && !empty($dateUntil))
if($dateUntil != __('YYYY-MM-DD') && !empty($dateUntil))
{
$dateUntil = '\''.$this->invertDate($dateUntil).'\'';
$dateUntil = '\''.DateTimeObj::get('Y-m-d', strtotime($dateUntil)).'\'';
} else {
$dateUntil = 'NULL';
}
// Don't insert if there is no entry_id:
if($entry_id != null)
{
Symphony::Database()->query('INSERT INTO `tbl_fields_status_statusses`
Symphony::Database()->query('INSERT INTO `tbl_fields_status_statuses`
(`field_id`, `entry_id`, `date`, `status`, `valid_until`) VALUES
('.$fieldId.', '.$entryId.', \''.$dateNow.'\', \''.$statusStr.'\', '.$dateUntil.');');
}
Expand All @@ -220,7 +215,7 @@ public function processRawFieldData($data, &$status, $simulate=false, $entry_id=
{
// There can only be a value returned if there is an entry_id:
return array(
'value' => Symphony::Database()->fetchVar('status', 0, 'SELECT `status` FROM `tbl_fields_status_statusses` WHERE `field_id` = '.$fieldId.' AND `entry_id` = '.$entryId.' ORDER BY `date` DESC, `id` DESC;')
'value' => Symphony::Database()->fetchVar('status', 0, 'SELECT `status` FROM `tbl_fields_status_statuses` WHERE `field_id` = '.$fieldId.' AND `entry_id` = '.$entryId.' ORDER BY `date` DESC, `id` DESC;')
);
} else {
// Is this the right way to do this?
Expand All @@ -238,7 +233,7 @@ public function appendFormattedElement(&$wrapper, $data, $encode = false) {
$attributes = $wrapper->getAttributes();
$entryId = $attributes['id'];
$fieldId = $this->get('id');
$results = Symphony::Database()->fetch('SELECT `date`, `status`, `valid_until` FROM `tbl_fields_status_statusses` WHERE `field_id` = '.$fieldId.' AND `entry_id` = '.$entryId.' ORDER BY `date`, `id`;');
$results = Symphony::Database()->fetch('SELECT `date`, `status`, `valid_until` FROM `tbl_fields_status_statuses` WHERE `field_id` = '.$fieldId.' AND `entry_id` = '.$entryId.' ORDER BY `date`, `id`;');
foreach($results as $result)
{
$status = new XMLElement('status', General::sanitize($result['status']), array('date'=>$result['date']));
Expand All @@ -251,11 +246,11 @@ public function appendFormattedElement(&$wrapper, $data, $encode = false) {
}


// Delete the entry and the associated statusses:
// Delete the entry and the associated statuses:
public function entryDataCleanup($entry_id, $data=NULL)
{
$this->Database->delete('tbl_entries_data_' . $this->get('id'), " `entry_id` = '$entry_id' ");
$this->Database->delete('tbl_fields_status_statusses', ' `entry_id` = '.$entry_id);
$this->Database->delete('tbl_fields_status_statuses', ' `entry_id` = '.$entry_id);
return true;
}

Expand Down Expand Up @@ -294,29 +289,11 @@ function displayDatasourceFilterPanel(&$wrapper, $data=NULL, $errors=NULL, $fiel


// Toggle the field
function toggleFieldData($data, $newState)
function toggleFieldData($data, $newState, $entry_id=NULL)
{
// $data['value'] = $newState;
// $data['handle'] = Lang::createHandle($newState);
// return $data;

// Get the entry-id:
// print_r(Symphony::Database()->fetch());


die();
$status = ''; // dummy variable
$data = $this->processRawFieldData($newState, $status, FALSE, $entry_id);
return $data;
}


/**
* Invert a date for database storage (convert 2010-10-21 to 21-10-2010 and vice versa)
* @param $str string The date
* @return string The inverted date
*/
private function invertDate($str)
{
$a = explode('-', $str);
return $a[2].'-'.$a[1].'-'.$a[0];
}

}
16 changes: 7 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Status Field #
# Status Field

Version: 0.1
Release date: 2010-10-21
Author: Giel Berkers
Website: http://www.gielberkers.com
E-mail: info@gielberkers.com
* Version: 0.1
* Release date: 2010-10-21
* Author: Giel Berkers
* Website: http://www.gielberkers.com
* E-mail: info@gielberkers.com

Store the status and hold a history of previous statusses.

The field also has an additional option to set a 'valid until'-date.
Store the status and hold a history of previous statuses. The field also has an additional option to set a 'Valid Until' date.

0 comments on commit fb465e8

Please sign in to comment.