]> gitweb.fluxo.info Git - drupal/reminder.git/commitdiff
Add default value to forms
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 26 Apr 2012 22:28:15 +0000 (19:28 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 26 Apr 2012 22:28:15 +0000 (19:28 -0300)
reminder.module

index a1c7b687e98e3596ec5ca9ed6185280e5f7d9edb..e24122205f1df7e73a443923b2aac31824d4f654 100644 (file)
@@ -134,6 +134,7 @@ function reminder_form(&$node) {
 
   $type         = node_type_get_type($node);
   $format_until = 'Y-m-d H:i';
+  $reminder     = isset($node->nid) ? reminder_get_reminder($node->nid) : array();
 
   if ($type->has_title) {
     $form['title'] = array(
@@ -166,6 +167,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,
     );
 
     $form['anonym']['user_email'] = array(
@@ -173,6 +175,7 @@ function reminder_form(&$node) {
       '#title' => t('Your e-mail'),
       '#description' => t(''),
       '#maxlength' => 100,
+      '#default_value' => isset($reminder['anonym_email']) ? $reminder['anonym_email'] : 0,
     );
   }
 
@@ -180,7 +183,7 @@ function reminder_form(&$node) {
      '#type'                => 'date_popup',
      '#title'               => 'Remind until',
      '#default_value'       => date($format_until),
-     '#date_format'         => isset($node->until) ? $node->until : $format_until,
+     '#date_format'         => isset($reminder['until']) ? $reminder['until'] : $format_until,
      '#date_label_position' => 'within',
      '#date_increment'      => 60,
      '#date_year_range'     => '0:+3',
@@ -197,7 +200,7 @@ function reminder_form(&$node) {
       'yearly'     => t('Yearly'),
       'decreasing' => t('Increasing (you get more reminders over time)'),
     ),
-    '#default_value' => isset($node->frequency) ? $node->frequency : 'hourly',
+    '#default_value' => isset($reminder['frequency']) ? $reminder['frequency'] : 'hourly',
     '#description' => t('Choose the frequency a reminder should be sent to you and all subscribers.'),
   );
 
@@ -212,7 +215,7 @@ function reminder_form(&$node) {
     '#title' => t('Show subscribed emails'),
     '#description' => t("Deny subscribers to see each other."),
     '#options' => array('0' => t('No'), '1' => t('Yes')),
-    '#default_value' => isset($node->secure) ? $node->secure : 0,
+    '#default_value' => isset($reminder['secure']) ? $reminder['secure'] : 0,
   );
 
   $form['reminder_options']['now'] = array(
@@ -223,6 +226,7 @@ function reminder_form(&$node) {
     '#default_value' => 0,
   );
 
+  // TODO
   $form['reminder_subscriptions'] = array(
     '#type' => 'textarea',
     '#title' => t('Subscribers'),
@@ -297,11 +301,6 @@ function reminder_node_submit($node, $form, &$form_state) {
     );
 
     $query = db_insert('reminder')->fields($values);
-
-    //if ($anonym_name != NULL) {
-    //  $query->fields(array('anonym_name' => $anonym_name, 'anonym_email' => $anonym_email));
-    //}
-
     $query->execute();
 
     // Save subscribers.
@@ -471,3 +470,36 @@ function _reminder_access_userreminders($account) {
   global $user;
   return user_access('access all reminders') || ($user->uid == $account->uid && user_access('access own reminders'));
 }
+
+/**
+ * Get reminder data.
+ *
+ * @param $nid
+ *   Reminder nid.
+ *
+ * @return
+ *   Reminder result set.
+ *
+ * @todo
+ *   Fetch subscriptions.
+ */
+function reminder_get_reminder($nid) {
+  // Schema
+  include_once 'reminder.install';
+  $schema = reminder_schema();
+  $fields = array_keys($schema['reminder']['fields']);
+
+  // Fetch existing options.
+  $query = db_select('reminder', 'r');
+  $query
+    ->condition('r.nid', $nid) 
+    ->fields('r', $fields);
+
+  $results = $query->execute()->fetchAll();
+
+  // 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);
+  }
+}