Using Select custom field for managing publish_down date for content

More
7 years 9 months ago - 7 years 9 months ago #66722 by BigBadMamouth
I managed to make a dropdown (select) form element and populated it with data from other extension that consists of
- text name and
- value (date).
Code:
SELECT subnames.title AS text, subs.publish_down AS value FROM #__akeebasubs_subscriptions AS subs JOIN #__akeebasubs_levels AS subnames ON subs.akeebasubs_level_id=subnames.akeebasubs_level_id WHERE subs.state='C' AND subs.enabled=1 AND subs.user_id='{item->created_by}'

Extension is akeebasubscription and the goal is to have users subscribe and publish content while subscription is active (enabled=1) and payment complete (state=C).

How to make selected value in dropdown end up in publish_down field of content?

Enabling Publication Details and showing TAB with Publication details is working as it should, but the goal is not to show all that (or at least hide it) and use dropdown for setting publish_down date for content.

Thanks in advance.

PS. Awesome extension BTW. Waiting for PRO version.
Last edit: 7 years 9 months ago by BigBadMamouth.

Please Log in or Create an account to join the conversation.

More
7 years 9 months ago - 7 years 9 months ago #66749 by BigBadMamouth
If I insert in select.php in flexicontent_fields in

function onAfterSaveField( &$field, &$post, &$file, &$item ) {
Code:
$db = JFactory::getDbo(); $query = $db->getQuery(true); // Fields to update. $fields = array($db->quoteName('publish_down') . ' = 2017-04-18 00:00:00'); // Conditions for which records should be updated. $conditions = array($db->quoteName('id') . ' = 17'); $query->update($db->quoteName('#__content'))->set($fields)->where($conditions); $db->setQuery($query); $db->execute();

I get error:
Header may not contain more than a single header

If using
Code:
$publishdate = new stdClass(); $publishdate-> id = $field->item_id; $publishdate-> publish_down = $post[0]; JFactory::getDbo()->updateObject('#__content', $publishdate, 'id');

nothing is changed in db.
Last edit: 7 years 9 months ago by BigBadMamouth.

Please Log in or Create an account to join the conversation.

More
7 years 9 months ago - 7 years 9 months ago #66763 by BigBadMamouth
Fixed sql query but still no edit in table
Code:
$db = JFactory::getDbo(); $query = $db->getQuery(true); $query = 'UPDATE #__content SET publish_down = DATE('.$db->quote($post[0]).') WHERE id = '. (int)$item->id; $db ->setQuery($query); $db ->execute();
Last edit: 7 years 9 months ago by BigBadMamouth.

Please Log in or Create an account to join the conversation.

More
7 years 9 months ago - 7 years 9 months ago #66776 by BigBadMamouth
The way to implement what I needed is to modify select.php for flexicontent_fields select plugin and to add as last line in:

function onBeforeSaveField( &$field, &$post, &$file, &$item )

$item->publish_down = $post[0];

That way selected dropdown list value will be placed in item publish_down and saved.

WARNING: Data is pushed into datatime mysql field and you should take extra care with what data is that field filled. Since I'm taking datatime data from other table this can be achieved with this simple line. In all other cases data should be formatted according to targeted table field with something like this:
date('Y-m-d H:i:s', strtotime($post[0])) so you get
$item->publish_down = date('Y-m-d H:i:s', strtotime($post[0])) ;
Last edit: 7 years 9 months ago by BigBadMamouth.

Please Log in or Create an account to join the conversation.

More
7 years 9 months ago #66778 by micker
i recommand you to duplicate field to create your own (information is on faq)
more simple for update component

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]
The following user(s) said Thank You: BigBadMamouth

Please Log in or Create an account to join the conversation.

More
7 years 9 months ago #66780 by BigBadMamouth
I have done just that. Made custom select field with necessary changes and left original one intact.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.821 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline