aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2012-08-09 21:16:09 -0300
committerSilvio Rhatto <rhatto@riseup.net>2012-08-09 21:16:09 -0300
commite54660859d23c2e54c7094d1cb0d05b109f00d06 (patch)
tree3856a7ae5e7b9f58995f65d9bde817e50a842170
parent12cebe41230ef69caf245b6add23f939ca4be94c (diff)
downloadreminder-e54660859d23c2e54c7094d1cb0d05b109f00d06.tar.gz
reminder-e54660859d23c2e54c7094d1cb0d05b109f00d06.tar.bz2
Misc changes
-rw-r--r--reminder.module63
1 files changed, 52 insertions, 11 deletions
diff --git a/reminder.module b/reminder.module
index 7d5b82f..fa7f80b 100644
--- a/reminder.module
+++ b/reminder.module
@@ -128,13 +128,16 @@ function reminder_node_access($node, $op, $account) {
/**
* Implementation of hook_node_form()
+ *
+ * @todo
+ * Default value for subscription field.
*/
function reminder_form(&$node) {
global $user;
$type = node_type_get_type($node);
$format_until = 'Y-m-d H:i';
- $reminder = isset($node->nid) ? reminder_get_reminder($node->nid) : array();
+ $reminder = isset($node->nid) ? reminder_get_reminder($node->nid, TRUE) : array();
if ($type->has_title) {
$form['title'] = array(
@@ -167,7 +170,7 @@ function reminder_form(&$node) {
'#title' => t('Your name'),
'#maxlength' => 100,
'#description' => t('This is optional.'),
- '#default_value' => isset($reminder['anonym_name']) ? $reminder['anonym_name'] : 0,
+ '#default_value' => isset($reminder['anonym_name']) ? $reminder['anonym_name'] : '',
);
$form['anonym']['user_email'] = array(
@@ -175,7 +178,7 @@ function reminder_form(&$node) {
'#title' => t('Your e-mail'),
'#description' => t(''),
'#maxlength' => 100,
- '#default_value' => isset($reminder['anonym_email']) ? $reminder['anonym_email'] : 0,
+ '#default_value' => isset($reminder['anonym_email']) ? $reminder['anonym_email'] : '',
);
}
@@ -226,13 +229,12 @@ function reminder_form(&$node) {
'#default_value' => 0,
);
- // TODO
$form['reminder_subscriptions'] = array(
'#type' => 'textarea',
'#title' => t('Subscribers'),
'#description' => t('One valid email address per line.'),
'#maxlength' => 100,
- '#default_value' => isset($node->reminder_subscriptions) ? $node->reminder_subscriptions: NULL,
+ '#default_value' => isset($reminder['subscriptions']) ? implode($reminder['subscriptions'], '\n'): NULL,
);
return $form;
@@ -470,13 +472,13 @@ function _reminder_access_userreminders($account) {
* @param $nid
* Reminder nid.
*
+ * @param $subscriptions
+ * Whether to fetch subscription information.
+ *
* @return
* Reminder result set.
- *
- * @todo
- * Fetch subscriptions.
*/
-function reminder_get_reminder($nid) {
+function reminder_get_reminder($nid, $subscriptions = FALSE) {
// Schema
include_once 'reminder.install';
$schema = reminder_schema();
@@ -485,7 +487,7 @@ function reminder_get_reminder($nid) {
// Fetch existing options.
$query = db_select('reminder', 'r');
$query
- ->condition('r.nid', $nid)
+ ->condition('r.nid', $nid)
->fields('r', $fields);
$results = $query->execute()->fetchAll();
@@ -493,6 +495,45 @@ function reminder_get_reminder($nid) {
// Sanitize the data before handing it off to the theme layer.
foreach ($results as $entry) {
// Return the first result as we just have one entry.
- return array_map('check_plain', (array) $entry);
+ $result = array_map('check_plain', (array) $entry);
+ break;
+ }
+
+ if (!$subscriptions) {
+ return $result;
}
+
+ $result['subscriptions'] = reminder_get_subscriptions($nid);
+ return $result;
+}
+
+/**
+ * Get subscription data.
+ *
+ * @param $nid
+ * Reminder nid.
+ *
+ * @return
+ * Subscriptions result set.
+ */
+function reminder_get_subscriptions($nid) {
+ // Schema
+ include_once 'reminder.install';
+ $schema = reminder_schema();
+ $fields = array_keys($schema['reminder_subscriptions']['fields']);
+
+ // Fetch existing options.
+ $query = db_select('reminder_subscriptions', 'r');
+ $query
+ ->condition('r.reminder_id', $nid)
+ ->fields('r', $fields);
+
+ $results = $query->execute()->fetchAll();
+
+ // Sanitize the data before handing it off to the theme layer.
+ foreach ($results as $entry) {
+ $results[] = array_map('check_plain', (array) $entry);
+ }
+
+ return $results;
}