Hiding end date in Drupal - date

I'm creating a calendar module in Drupal. Due to the clients' needs, I need to be able to hide the end date using a boolean variable on the node, saved in a CCK field.
My problem is that I am able to hide it, by hooking into the theme_date_display_range() theming function, but not from within my module. As far as I can see, this is only possible from within the theme. This will mean, that I won't be able to hide the end date without using a certain theme enabling this.
If I then say, I'll use a certain theme and live with that, I'm still not able to see the context in which the mytheme_date_display_range() is called, and I thereby have no way of knowing if the current node wants to show or hide the end date. I could pass it along as a variable, but would there be a better way to do this?
Could I maybe overwrite the date's theming function to use my module instead, and how would I do this, if that was the best/correct way?

Okay, so I think I've found a good solution without using the theming functions at all. I took a closer look at theme_date_display_combination(), which themes the dates. If the end date is not set, it will only display the start date. I hook into hook_entity_prepare_view() and check if both the date and hide endtime fields are present. If so I unset the endtime based on the boolean value.
/**
* Implements hook_entity_prepare_view().
*/
function kw_calendar_full_entity_prepare_view($entities, $type, $langcode) {
foreach ($entities as &$entity) {
if (isset($entity->field_event_date) && isset($entity->field_hide_endtime) && $entity->field_hide_endtime[LANGUAGE_NONE][0]['value'] == 0) {
unset($entity->field_event_date[LANGUAGE_NONE][0]['value2']);
}
}
}
Hope this will help somebody one day...

Related

how to correctly use Firebase.Firestore.FieldValue.ServerTimestamp in unity?

Currently, I was working on a Unity project and using Firestone as my database.
now i facing a problem is when i create a document in firestone i want to add the time of creation also.
i was using the code
db.Collection("Challenges").Document(addedDocRef.Id).UpdateAsync("TimeCreated", Firebase.Firestore.FieldValue.ServerTimestamp);
but it always update the same time in firestone.
every document get same timestemp, can anyone teach me how to solve this issue?
The FieldValue properties are sentinel values in this case to be understood as dummy values that are supposed to be filled in by "someone".
I don't know how Firebase works exactly and who is supposed to fill this in but what you get basically equals DateTime.UnixEpoch the default uninitialized system time (+ 7:30 timeszone shift). It might have to be configured accordingly somewhere before it works correctly.
You could instead simply pass in your own timestamp using e.g. DateTime.Now

Access 2013: I am trying to return today's date when a yes/no fields is marked as "Yes"

I am trying to return today's date in a date field when another field is marked as "Yes". I tried the following expression but to no avail. I have limited experience with expressions and greatly appreciate any guidance. If the field does not have a "Yes" the date field can be blank. I cannot set the default to "No" for the Approved field.
Approved Date: IIf([Approved]=True,Today(),Null)
If I set the date, it will work but the date is dynamic so this is not really helpful.
Approved Date: IIf([Approved]=True,5/1/2016,Null)
Thank you in advance for your help.
OK, so I spent a little time looking at how to do this with an expression. The answer is you can't, at least not without a helper function. So, my hybrid solution is:
1) Create a function in a standard module:
Public Function SetControlValue( _
ByVal ctlControl As Access.Control, _
ByVal varValue As Variant, _
Optional ByVal varTest As Variant = True)
If (varTest) Then
ctlControl.Value = varValue
End If
End Function
2) In the AfterUpdate event for the Approved checkbox, enter:
=SetControlValue([ApprovedDate],Date(),([Approved]=True) AND (IsNull([ApprovedDate])))
This approach saves you from making a class module under the form. And you can keep all such code in a common module, so you can build a library of such functions for other forms.
(old answer 2)
Based on your answers, what you can do is add an AfterUpdate event to the Approved control, which does something like:
Private Sub Approved_AfterUpdate()
If (Approved.Value = True) And IsNull(ApprovedDate.Value) Then
ApprovedDate.Value = Date()
End If
End Sub
This will set the approved date once, when the approved checkbox is first checked. If you need different behavior, this can easily be modified.
(old answer 1)
I think you have it backwards.
When [Approved] is set to True, set [ApprovedDate] = Today(). That way, it is saved to the table, and you have a permanent record of when it was approved.

Handling more complex forms

In my current project I have to deal with more complex forms. Fields (i'll name them 'A' and 'B') are automatically filled if a specific field (i'll name that one 'C') received user input. But also if the user inputs data into field A, the fields B and C are automatically filled out.
(This is only a simple example, the current logic is a bit more complicated)
What I have to take care of is that no cycles happen (C -> A -> C -> A -> ...). So I need to now if the current value change was due to user input or another field that had received input and then triggered the value change of the current field. And I also need to now in the second case which field exactly triggered the value change because then I must trigger other specific actions corresponding from who/what triggered that value change.
Is there a general approach in Vaadin to deal with this kind of form
structure? The problem at the moment is that I simply don't now who
or what triggered what ValueChangeEvent.
Are there frameworks to deal with this or am I overlooking an existing Vaadin pattern?
Handling of valueChange events in Vaadin is a bit of pain, since it always fires, no matter if the user has changed something, or the application has used setValue(....) on the component.
The only solution for this is to remember when you do a setValue(....) in your application and then disable the trigger code in the other components.
For example in this case (endless loop):
field1.addValueChangeListener( field2.setValue('Updated by field1');
field2.addValueChangeListener( field1.setValue('Updated by field2');
Change it that way:
boolean inTrigger= false;
field1.addValueChangeListener(
{
if (!inTrigger)
{
inTrigger= true;
field2.setValue('Updated by field1');
inTrigger= false;
}
});
field2.addValueChangeListener(
{
if (!inTrigger)
{
inTrigger= true;
field1.setValue('Updated by field2');
inTrigger= false;
}
});
That way you can prevent update loops and let execute your code exactly once.

Requesting member of node_element results in "undefined"

I'm using Opa for a school project in which there has to be some synchronization of a textfield between several users. The easy way to solve this, is to transmit the complete field whenever there is a change performed by one of the users. The better way is of course to only transmit the changes.
My idea was to use the caret position in the textfield. As a user types, one can get the last typed character based on the caret position (simply the character before the caret). A DOM element has an easy-to-use field for this called selectionStart. I have this small Javascript for this:
document.getElementById('content').selectionStart
which correctly returns 5 if the caret stands at the fifth character in the field. In Opa, I cannot use selectionStart on either a DOM or a dom_element so I thought I'd write a small plugin. The result is this:
##extern-type dom_element
##register jsGetCaretPosition: dom_element -> int
##args(node)
{
return node.selectionStart;
}
This compiles with the opp-builder without any problem and when I put this small line of code in my Opa script:
#pos = %%caret.jsGetCaretPosition%%(Dom.of_selection(Dom.select_id("content")));
that also compiles without problems. However, when I run the script, it always returns "undefined" and I have no idea what I'm doing wrong. I've looked in the API and Dom.of_selection(Dom.select_id("content")) looked like the correct way to get the corresponding dom_element typed data to give to the plugin. The fact that the plugin returns "undefined" seems to suggest that the selected element does not know the member "selectionStart" eventhough my testcode in Javascript suggest otherwise. Anyone can help?
In Opa dom_element are the results of jQuery selection (i.e. an array of dom nodes). So if I well understood your program you should write something like node[0].selectionStart instead of node.selectionStart.
Moreover you should take care of empty selection and selection which doesn't contains textarea node (without selectionStart property). Perhaps the right code is tmp == undefined ? -1 : tmp = node[0].selectionStart == undefined ? -1 : tmp

zfdatagrid date format

I am using ZF 1.11, PHP 5.3, Windows and the most recent version of zfdatagrid.
I use
$grid->updateColumn('birthday', array('format'=> array('date',array('date_format' => 'dd-MM-yyyy'))));
to display an attribute "birthday" as dd-MM-yyyy. When I click on the Edit button (CRUD enabled), the value of this attribute is being displayed as 'yyyy-MM-dd'. When the user clicks the save button, he gets an error message (Please, enter date as dd-MM-yyyy).
How can I tell the $form to display the value as dd-MM-yyyy instead of yyyy-MM-dd?
looking at the docks I think your code maybe slighty incorrect:
$grid->updateColumn('birthday', array('format'=> array('date',array('date_format' => 'dd-MM-yyyy'))));
Maybe:
$grid->updateColumn('birthday', array('format'=> 'date',array('date_format' => 'dd-MM-yyyy')));
looks like you had an extra array() at date.
reference:
Date ZFDatagrid will for a key in Zend_Registry with the name
Zend_Locale and use it. You can also pass as argument a instance of
Zend_Locale or an array with the following options
locale
date_format
type
$grid->updateColumn('field',array('format'=>'date'));
thanks, but that doesn't solve the problem. Actually, what I did now is to add an event listener for the crud.form_built event. The method called in this event simply creates a new Zend_Validate_Date object and assigns this validator to the corresponding zfdatagrid element.
This is a hack indeed, but it works. Actually, zfdatagrid doesn't really work with PostgreSQL and the manual is incorrent in many places.
!Warning maybe bad English!
for i.e. "localized" values in forms i do something like this..
after passing form to the grid $grid->setForm($myform);
but before the call of $grid->deploy();
i get the form element and set the value manually like the following
$Form=$grid->getForm(1);
$dateVal = $Form->getElement('birthday')->getValue();
if(Zend_Date::isDate($dateVal,'yyyy-MM-dd', 'en'))
$dateObject = new Zend_Date($dateVal);
$Form->getElement('birthday')
->setValue($dateObject->toString('dd.MM.yyyy'))
->setValidators(array(new Zend_Validate_Date('dd.MM.yyyy')))
;
then register a zfdatagrid event trigger "crud.before_update"
$grid->listenEvent('crud.before_update', array($this, '_updateCallback')
that calls a function from this controller _updateCallback() with something custom like this
public function _updateCallback(Bvb_Grid_Event $e)
{
$n = $e->getParam('newValues');
list($d,$m,$y) = explode('.', $n['birthday']);
$sqldate = $y.'-'.$m.'-'.$d;
$n['birthday'] = $sqldate;
$e->setParam('newValues', $n);
}
or just use Zend Date like before to refactor date to ensure that
the datevalue we want to save, is in a sql valid US date format..
hope this will help..
z.