We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31113
    • 45 Posts
    I had write first alpha version of Document class to create/edit/delete documents. It can change document fields and TV.

    http://modxcms.com/forums/index.php/topic,5823.new/boardseen.html

    But in Russian. Need to translating and testing
      • 21647
      • 9 Posts
      hi Ur001, thanks for posting!
      This looks very interesting. If only I could speak Russian! Da! babelfish translation on altavista.com !!!
      I hope the dev team see your work!
      I will try to follow your post and see if I can make use of it.
      Thanks again for helping.
      nmac smiley
        • 7923
        • 4,213 Posts
        There is also Wendys docApi library to create/edit/delete documents


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 16556
          • 27 Posts
          Hello, i was wondering if someone would mind explaining how i could display a checkbox TV, so it could be adjusted and the written to when the submit blog button is pressed.

          thanks very much in advance, lach.
            • 9549
            • 93 Posts
            There isn’t an easier solution by now?
            I’m creating a page where the client can submit their products. NewsPublisher works fine, except I want an additional field (Years’ Model).
              • 9549
              • 93 Posts
              I maybe should describe my problem some more. All leads to "a NewsPublisher that saves a TV value" is redirected to this post. First I was thinking of using MakeForm by OpenGeek, but realized that it want optimal for my purposes. Then I tried ur001’s Docmanager without success. I tested in both 0.9.2 and 0.9.5 to see if it was an version issue. Unfortunatley I didn’t manage to get it to work on either. No new document is created, do’h.

              My code looks like this:

              <?php
              require_once($modx->config[’base_path’] . ’assets/libs/docmanager/document.class.inc.php’);
              $submited=isset($_POST[’submit’]);

              if(!$submited) {
              return $modx->getChunk(’LaggTill’);
              }
              else{
              $doc = new Document();
              $doc->Set(’parent’,$folder);
              $doc->Set(’alias’,’post’.time());
              $doc->Set(’content’,’content’);
              $doc->Set(’template’,’VMD’);
              $doc->Set(’tvyrsModel’,’tvyrsModel’);
              $doc->Save();
              }
              ?>

              I tried to The Man Can!’s version too. But how am I suppose to save the TV value through the input form? Just name the fields with a "tv" as prefix? or do I use an extra parameter in the NewsPublisher call? I’m complete lost here. nmac (read http://modxcms.com/forums/index.php/topic,5983.15.html) was on the right track, but hacking the NewsPublisher snippet with ur001’s api is way too complicated for a guy like me embarrassed

              0.9.5 kicks ass by the way, nicley done!

              Thanks.
                • 20682
                • 31 Posts
                I just want to thank all those that posted their code for using TVs with Newspublisher.

                I got it working and added another little check to the function, as modx empty tv values do get entered into the db. This I don’t want!

                Here is the very very slightly modified function so that new tvs with empty values do not get sent to the db:

                // 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
                				);
                				if (!empty($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 **********************************************************


                And the code to add to the newspublisher snippet right after the small section that starts with
                "// Doc group thing":

                // Get the template variable names for this template
                			$sql = "SELECT stvs.name FROM". $modx->getFullTableName('site_templates')." st INNER JOIN ".$modx->getFullTableName('site_tmplvar_templates')." stvt ON st.id = stvt.templateid INNER JOIN ".$modx->getFullTableName('site_tmplvars')." stvs ON stvs.id = stvt.tmplvarid WHERE st.id = '".$template."' ORDER BY stvs.rank ASC";
                			$result = $modx->db->query($sql);
                			while ($row=$modx->db->getRow($result)) {
                				$thisTVData = mysql_escape_string($modx->stripTags($_POST[$row['name']]));
                				$modx->setTV($row['name'],$thisTVData,$redirectid);			
                			}


                I fixed up the query to make it compatible with any table prefix.

                I run modx.9.6 and newspublisher 1.4

                Sheri
                  • 20057
                  • 4 Posts
                  I have tried the above code, and am stuck on how to call it in the newsPublisher snippet..
                  Do I assign it with a name in the snippet call? if so, how do I do that?
                  Something like this?
                  &the_TV_I_Want_to_Call=`TVnickName`


                  I just wish to have a little more control on TVs with newspublisher..
                    • 27708 MODX Staff
                    • 2,502 Posts
                    I am working on a project and I want to use a date based TV for the date of the event in an events list. I have read this thread to see if there is a way to get TV’s working with NewsPublisher but none of the "solutions" mention how they called the TV in the form template. I am loathe to redo the whole thing with FDM 0.0.9.9 and I don’t even know if it would do what I want.

                    Please let me and others know how you managed to get TV’s working.

                    Ideally I could add a snippet to my site and call the function there instead of hacking the core but I can’t seem to figure out how to do that. Second I would like to know how to call the TV from within the form template for NewsPublisher. I know that it has been mentioned that this will be part of .0.9.7 but I need a solution pronto.

                    All the best,

                    Jay
                      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                      • 27708 MODX Staff
                      • 2,502 Posts
                      Bump smiley

                      Anyone who can comment or help on this? Suggestions? Move to FDM 0.0.9.9?

                      Cheers,

                      Jay
                        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub