I see the "set a time frame" has monthly and daily, when will weekly and annually be added? I need all four of these for a project, each time limit is set to it's own content type for the authenticated user.

Thank you!

Comments

Kutakizukari’s picture

In the node_limitnumber.module line 135-154 it has:

$form['settings']['time'] = array(
    '#type' => 'select',
    '#title' => t('Set a time frame'),
    '#default_value' => $settings['time'],
    '#description' => t('Create the limit of nodes per time frame'),
    '#options' => array(
      'none' => t('No Time Limit'),
      'daily' => t('Daily'),
      'monthly' => t('Monthly'),
    ),

Can I just add weekly and annually to this and it will work or is it not just that easy?

Kutakizukari’s picture

Ok maybe not found this:

// Continue checking as a simple limit since the OG check is over
  switch ($settings['time']) {
    case 'none':
      $q = "SELECT * FROM {node} WHERE type = '%s' AND uid = %d";
      $result = db_query($q, $node->type, $user->uid);
      $num = db_affected_rows();
      if ($num >= $settings['limit']) {// We have the data, now we check the limit
        return TRUE;
      }
      return FALSE;
      break;
    case 'daily':
      $q = "SELECT * FROM {node} WHERE type = '%s' AND uid = %d AND created > %d";
      $day = strtotime(date('Y-m-d'));
      $result = db_query($q, $node->type, $user->uid, $day);
      $num = db_affected_rows();
      if ($num >= $settings['limit']) {
        return TRUE;
      }
      return FALSE;
      break;
    case 'monthly':
      $q = "SELECT * FROM {node} WHERE type = '%s' AND uid = %d AND created > %d";
      $month = strtotime(substr(date('Y-m-d'), 0, 8) .'01');
      $result = db_query($q, $node->type, $user->uid, $month);
      $num = db_affected_rows();
      if ($num >= $settings['limit']) {// We have the data, now we check the limit
        return TRUE;
      }
      return FALSE;
      break;
  }
  return FALSE;
}

Need to add two more for it to work but how and what?

Kutakizukari’s picture

I have looked up the functions at php.net. I'm not a php or mysql person, I have a php and mysql book but it is packed up in storage from a move.

for weekly:

case 'weekly':
      $q = "SELECT * FROM {node} WHERE type = '%s' AND uid = %d AND created > %d";
      $week = strtotime(substr(date('W'), 0, 8) .'01');
      $result = db_query($q, $node->type, $user->uid, $week);
      $num = db_affected_rows();
      if ($num >= $settings['limit']) {// We have the data, now we check the limit
        return TRUE;
      }
      return FALSE;
      break;

and for annually:

case 'annually':
      $q = "SELECT * FROM {node} WHERE type = '%s' AND uid = %d AND created > %d";
      $year = strtotime(substr(date('Y'), 0, 8) .'01');
      $result = db_query($q, $node->type, $user->uid, $year);
      $num = db_affected_rows();
      if ($num >= $settings['limit']) {// We have the data, now we check the limit
        return TRUE;
      }
      return FALSE;
      break;

Then add:

$form['settings']['time'] = array(
    '#type' => 'select',
    '#title' => t('Set a time frame'),
    '#default_value' => $settings['time'],
    '#description' => t('Create the limit of nodes per time frame'),
    '#options' => array(
      'none' => t('No Time Limit'),
      'daily' => t('Daily'),
      'weekly' => t('Weekly'),
      'monthly' => t('Monthly'),
      'annually' => t('Annually'),
    ),
  );

Is this close to right how bad did I mess things up?

Kutakizukari’s picture

Version: 6.x-2.0-alpha2 » 6.x-2.x-dev
Component: User interface » Code
Status: Active » Needs work
StatusFileSize
new2.22 KB

Made a patch but it needs some work.

jdwfly’s picture

Priority: Critical » Normal

thanks for the patch, i'm going to look at this tonight.

jdwfly’s picture

Status: Needs work » Fixed

I've committed some code to 2.x-dev branch. Try testing it to see if it works. You'll need to grab it through cvs. I'm going to mark as fixed for now. If there is any issues just reopen this.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.