Gravity Forms Date Push Reservations - forms

I currently use GF for reservations 'Arrive' and 'Departure'. I would like the date displayed on the 'Departure' to always be one date ahead of the 'Arrival' date, regards of what date the guest picks. Then can pick a custom 'Departure' date, but as a default I'd like to show one date forward of the 'Arrival' date no matter what 'Arrival' date they choose.

This is possible with the gform_datepicker_options_pre_init JS filter. Example #3 is what you're after:
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 8 ) {
optionsObj.minDate = 0;
optionsObj.onClose = function (dateText, inst) {
jQuery('#input_12_9').datepicker('option', 'minDate', dateText).datepicker('setDate', dateText);
};
}
return optionsObj;
});
If you're looking for a code-less solution, I've written a plugin that let's you do this in just a few clicks called GP Limit Dates.
Also, here is an article that addresses your specific need: How to restrict dates in second date field based on date selected in first date field with Gravity Forms

Related

Selecting all records created current year with Eloquent

I need to select records created at current year, with Eloquent
So far, this is the code I'm using. How can I filter the results to retrieve only the ones created in the current year?
public function vacationsbalance($typeId) {
// Get vacataions balance for existing employee.
$vacationsBalance = $this->vacations()->where('vacation_type_id', '=', $typeId)->sum('days_num');
return $vacationsBalance;
}
Assuming you have timestamps in your table (that is, you have a created_at column with the record's creation date), you can use:
public function vacationsbalance($typeId) {
// Get vacations balance for existing employee and for the current year.
return $this->vacations()
->where('vacation_type_id', '=', $typeId)
->whereRaw('year(`created_at`) = ?', array(date('Y')))
->sum('days_num');
}
Check Eloquent's documentation and look for whereRaw.

How to use nest in d3 to group using the 'month' as key, but my csv file contains the whole date?

var data = d3.nest()
.key(function(d) { return d.date;})
.rollup(function(d) {
return d3.sum(d, function(g) {return g.something; });
}).entries(csv_data);
using this code above I can group by date which is in the format yyyy-mm-dd , but I want to group using the month as key. How do I do this ?
You can use the builtin method d3.timeMonth() to get the first day of the month for a date like:
d3.nest()
.key(function(d){ return d3.timeMonth(d.date); });
If d.date is not already a javascript Date object you have to first parse it to be one.
var date_format = d3.timeFormat("%Y-%m-%d");
csv_data.forEach(function(d, i) {
d.date = date_format.parse(d.date);
};
You need to change the key function to return the value you want to nest by. In most cases, the key function just returns a property of the data object (like d.date), but in your case the function will require a little more calculation.
If your date is stored as a string of the format "yyyy-mm-dd" you have two options for extracting the month: either
use regular expressions to extract the portion of the string in between the "-" characters, or
convert it to a date object and use date methods to extract a component of the date.
Browsers differ in which date formats they can convert using the native Javascript new Date(string) constructor, so if you're using date objects you may want to use a d3 date format function's format.parse(string) method to be sure of consistent results.

Webform form alter date hide day

I'm relatively new to Drupal 7 and I'm trying to create a custom webform. My goal is to add a date (provided by the date module) field with out the day option. So it displays on month and year hiding the day option.
I have managed to achieve this but only by recreating the wholedate field as a custom field but I wanted to know if it was possible to customize the date field provided by the date module.
Below is a screen shot of my form:
How I create my custom date field:
function my_webform_form_alter(&$form, &$form_state) {
if (isset($form['#node']->webform) && $form['#node']->uuid == '00b20537-d5ce-45c2-af37-150c9e73b96d') {
//$form['submitted']['date']['#type'] = 'hidden';
$form['ggg'] = array(
'#type' => 'date_select',
'#title' => 'Date',
'#date_format' => 'm/Y',
'#default_value' => date('Y-m-d')
);
}
}
I have tried other methods on hiding the field components but nothing seem to work so far. I was wondering if I needed to implement a hook different from the alter hook (the one being used).
Any suggestions on how to achieve this?
A possible solution would be to transform the day field of the date component to a hidden field instead of the select field type. That can be achieved by adding a #process callback for that field and altering the data.
function YOURMODULE_form_alter(&$form, &$form_state, $form_id)
{
// Your logic here depending which form to alter
// ...
// Add #process for the component with key name 'date'
$form['submitted']['date']['#process'][] = 'YOURMODULE_process_date';
}
function YOURMODULE_process_date(&$element)
{
// change type to hidden
$element['day']['#type'] = 'hidden';
// set value to first day of the month
$element['day']['#value'] = '1';
return $element;
}
Webform now allows hiding the day, month or year of a date. See this issue for details.

In yii how to find date is greater than current date

I am working in Yii framework. I am having Poll table with fields as-
-pollId
-pollQuestion
-Isactive
-publishDate
-isPublish
when new poll is created,that date get inserted into publishDate field.
e.g.2012-04-04 02:23:45 In this format entry get inserted.
Now i want to check weather this publishDate is smaller than today's date or current date. i.e.publishDate should not be greater than current date.
So how to check this in yii? Please help me
As per normal PHP. Assuming $model is the submitted form and you have assigned (after the form has been submitted) $model->attributes = $_POST['MyModel']
You can then use:
if ($model->publishDate < date('Y-m-d H:i:s')){
// it is smaller
}
Another thing you could look at is using Yii's model validation. You could store the created date (which would be todays date) and then compare that to the publishDate in the form submit:
$model->created = date("Y-m-d H:i:s");
if ($model->validate){
...
}
And in your Poll model:
array('publishDate ','compare','created','operator'=>'<', 'message'=>'Publish Date must be smaller than the current date'),

Rally: how to pull latest testresult from a specific testset

I am trying to use the following code to get a pie chart for the latest testresult from a particular testset.
pieconfig = {
type: 'TestCaseResult',
attribute: 'Verdict',
query: rally.sdk.util.Query.and(['TestSet = "' + testsetDropdown.getValue() + '"','Date < "2012-11-01"'])
};
var pieChart = new rally.sdk.ui.PieChart(pieconfig,rallyDataSource);
pieChart.display("pieChartDiv");
In this code I've put today's date manually, but I want to make this query as of a generic type which should pull the latest testresult from a specific testset. Any hints...? Thank you.
Rally has a nice DateTime format that formats dates to whatever you want. Here's the reference you can use: http://developer.rallydev.com/help/datetime.
If you always want the current day in the year-month-day format, you can do this:
var dateQuery = 'Date < ' + rally.sdk.util.DateTime.format(new Date(), "yyyy-MM-dd");
Then your query will look something like this:
query: rally.sdk.util.Query.and(['TestSet = "' + testsetDropdown.getValue() + '"', dateQuery])
EDIT: Now I see what you mean by grabbing the latest TestCaseResult. You don't actually need the Date conditional in your query. What you need to add is a couple of options to your pie config.
var pieconfig = {
type: 'TestCaseResult',
attribute: 'Verdict',
query: '(Test Set = "' + testsetDropdown.getValue() + '")',
order: 'CreationDate desc',
pagesize: 1
};
This will sort by the Creation Date in descending order, which means the most recently made TestCaseResult will be on top. Setting a pagesize to 1 means you'll always get the most recent result.
This also solves the issue of not getting test case results of the current day. The previous query will get all TestCaseResults from today at 12:00AM backward. So any test case results made in the current day will not be included.
Let me know if that doesn't work out for you. I'm pretty new to the Rally SDK1 query system.