Mark
Coding Team

Posts: 3,247
Ditto Developer
|
 |
« on: Aug 23, 2005, 06:14 PM » |
|
Is there any way to set a tv using the new NewsPublisher?
|
|
|
|
|
Logged
|
|
|
|
xwisdom
Foundation

Posts: 1,732
|
 |
« Reply #1 on: Aug 23, 2005, 06:17 PM » |
|
Is there any way to set a tv using the new NewsPublisher?
You mean the set the value of a TV?
|
|
|
|
|
Logged
|
|
|
|
Mark
Coding Team

Posts: 3,247
Ditto Developer
|
 |
« Reply #2 on: Aug 23, 2005, 06:24 PM » |
|
Yeah.
|
|
|
|
|
Logged
|
|
|
|
xwisdom
Foundation

Posts: 1,732
|
 |
« Reply #3 on: Aug 23, 2005, 08:04 PM » |
|
Yeah.
It currently does not but you can modify it to do so. It's best to make a copy of the snippet and give it a new name to prevent upgrade problems
|
|
|
|
|
Logged
|
|
|
|
The Man Can!
Testers

Posts: 274
|
 |
« Reply #4 on: Nov 22, 2005, 03:17 AM » |
|
In attempting to figure this out, I've hit a bit of a stumbling block. There doesn't seem to be an API function to write to a TV? I see that there is a $modx->putChunk, and I thought there'd be something similar for TVs, but I don't see anything in the documentation or in the document.parser file. I'm guessing I'm wrong, as I almost always am.
Thinking that perhaps TVs can just be added with the regular document info (like longtitle, alias, etc.), I tried adding the TV values along with the other values in the $flds array (around line 190), but can't get anything going there either.
Any advice on which direction to go to get this working? Thanks for any help! Brett
|
|
|
|
|
Logged
|
|
|
|
rthrash
Foundation

Posts: 9,105
|
 |
« Reply #5 on: Nov 22, 2005, 08:48 AM » |
|
Hi Brett, Unfortunately at this time there is no API for writing to TVs as you've discovered. You'll need to create a query via the DB API in order to do it. However, this would be a great time to log a request to the bugtracker for just such a function as we're in that "mode" right now.  Thanks!
|
|
|
|
|
Logged
|
MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
|
|
|
The Man Can!
Testers

Posts: 274
|
 |
« Reply #6 on: Nov 22, 2005, 10:32 AM » |
|
Thanks Ryan. I logged that feature request in Flyspray (after spending 5 minutes trying to find the "Create new user" link up at the top  ). I'll attempt a query via the DB API like you suggested and will update if I have success.
|
|
|
|
|
Logged
|
|
|
|
jaredc
Coding Team

Posts: 286
|
 |
« Reply #7 on: Nov 23, 2005, 08:24 AM » |
|
Man I'm glad I'm not the only one. After the instructions said look at the BOTTOM for the new user account link, I looked and looked. Thought my lasik surgery was letting me down. Then I finally did a search and found it smack at the TOP. 
|
|
|
|
|
Logged
|
Standard Disclaimer I could be totally wrong.
|
|
|
OpenGeek
MODx Co-Founder
Foundation

Posts: 4,669
looking a little more like my avatar again...
|
 |
« Reply #8 on: Nov 23, 2005, 11:52 AM » |
|
My apologies for your time wasted searching the bottom of the page!  Flyspray moved the login and registration to the top of the page since the last version, and I neglected to change the wording on the page to reflect this.
|
|
|
|
|
Logged
|
Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
— Frank Herbert
|
|
|
Djamoer
Testers

Posts: 1,492
No one can limit a man other than the man himself.
|
 |
« Reply #9 on: Nov 23, 2005, 12:36 PM » |
|
Happened to me too...  Hehehee... But that's the fun of open source community, we learn something from error/mistake of other people too... I'm just trying to point out that it's something that makes open source project fun, compare to corporate business project like what I'm working on right now. A small mistake in typo is being taken VERY serious. So anyway, looking forward to get to know y'all... C ya...
|
|
|
|
|
Logged
|
|
|
|
jlarson
Member
 
Posts: 96
|
 |
« Reply #10 on: Nov 24, 2005, 03:24 AM » |
|
In the meantime I've hacked the following function into document.parser.class.inc.php: # Set template variable value function setTV($tvname, $value, $docid="") { if($tvname== "") return false; if($docid == "") $docid = $this->documentIdentifier; //get id of tv $result=$this->db->select("id", $this->getFullTableName("site_tmplvars"), "name = '$tvname'"); if (!$result) return false; $row=$this->fetchRow($result); $rows_affected = $this->db->update("value='$value'", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid); return $rows_affected; } Of course if you just replace each "$this" with '$modx' you could put it in a snippet.
|
|
|
|
|
Logged
|
|
|
|
The Man Can!
Testers

Posts: 274
|
 |
« Reply #11 on: Nov 30, 2005, 02:09 AM » |
|
Oh my gosh I could kiss you for that!  Seriously, thank you so much.
|
|
|
|
|
Logged
|
|
|
|
davidm
Marketing & Design Team

Posts: 6,590
The best way to predict the future is to invent it
|
 |
« Reply #12 on: Nov 30, 2005, 02:16 AM » |
|
+1 Thanks !!! Oh my gosh I could kiss you for that!  Seriously, thank you so much.
|
|
|
|
|
Logged
|
|
|
|
The Man Can!
Testers

Posts: 274
|
 |
« Reply #13 on: Feb 09, 2006, 12:59 AM » |
|
Hi all. Sorry for the super long delay in this post, but that post above doesn't quite work (at least, not from what we could figure). Luke used that as a starting point and made this, which seems to work absolutely beautifully: There's a feature/bug tracking request here: http://modxcms.com/bugs/task/129// HACK ********************************************************** // Insert this about line 1700 in document.parser.class.inc.php // right after function getTemplateVarOutput # Set template variable value function setTV($tvname, $value, $docid="") { if($tvname== "") return false; if($docid == "") $docid = $this->documentIdentifier; //get id of tv $result=$this->db->select("id", $this->getFullTableName("site_tmplvars"), "name = '". $tvname . "'"); if (!$result) return false; $row=$this->fetchRow($result); // query the db to see if there are any records to update $result=$this->db->select("Count(*) AS RecordsExist", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid); $row2=$this->fetchRow($result); if (!$row2['RecordsExist']) { $fields = array( "tmplvarid" => $row['id'], "contentid" => $docid, "value" => $value ); $rows_affected = $this->db->insert($fields, $this->getFullTableName("site_tmplvar_contentvalues")); } else { $rows_affected = $this->db->update("value='" . $value . "'", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid); } return $rows_affected; } // END HACK **********************************************************
We made a modified NewsPublisher snippet as well that uses this. If anybody wants to see that, just let me know. It has some stuff hardcoded, so it's not really great for a general release, but if anybody wants to take it and run with it it shouldn't be too hard. Best, Brett PS: jlarson, if your's works, sorry! We (Luke and I) didn't have any luck with it, but maybe it's just because we goofed something.  If they both work, I guess that's great too!
|
|
|
|
« Last Edit: Feb 09, 2006, 01:02 AM by The Man Can! »
|
Logged
|
|
|
|
luke.stokes
Support Subscriber

Posts: 54
|
 |
« Reply #14 on: Feb 09, 2006, 12:12 PM » |
|
Yeah, just to clarify, I had to add a check to see if the TV had any current value yet. If not, the UPDATE query doesn't do anything so you have to do an INSERT query instead. I think MODx doesn't create blank TV entries, but only creates them when you enter a value.
Hope this helps someone out there.
|
|
|
|
|
Logged
|
|
|
|
|