We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24530
    • 100 Posts
    Hi!
    I have a question concerning TV´s with @SELECT bindings used for tagged blogging (http://modxcms.com/forums/index.php/topic,11835.0.html).

    When I use @ bindings I get checkboxes for each page in the backend, but in combination with QuickEdit or NewsPublisherTagging I just get ONE checkbox with the query (Checkbox: @SELECT pagetitle FROM ...) instead of one checkbox for each option.

    Does anybody have an idea how to solve this problem?



    Some more details on the TV:
    Input Type: Check Box; Input Option Values: @SELECT pagetitle FROM modx_site_content WHERE `parent` =61; Widget: Delimited List; Delimiter: ,

    More details on the system:
    ModX 0.95, NewsPublisherTagging 1.0 (http://modxcms.com/forums/index.php/topic,4951.msg40296.html#msg40296)
      my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
      • 24530
      • 100 Posts
      OK ... I searched a little bit through the .php files of QuickEdit, NewsPublisherTagging and the handlers for Template Variables:

      assets/modules/quick_edit/output.class.inc.php line 168-206:
      			$cvs = $modx->getTemplateVars('*', 'id, name', '', 1, 'name');
      
      			foreach ($cvs as $content) {
      
      				if (isset ($content['id']) || in_array($content['name'], $editable)) {
      
      					if (isset ($content['id'])) {
      						$cv_obj->set($content['id']);
      					} else {
      						$cv_obj->set($content['name']);
      					}
      
      					if ($cv_obj && $cv_obj->checkPermissions()) {
      
      						// Get the menu
      						$menu = $cv_obj->group;
      
      						// Check for special CV types //
      
      						// One checkbox and not a binding
      						if ($cv_obj->type == 'checkbox' && !strpos($cv_obj->elements, '||') && substr($cv_obj->elements, 0, 1) != '@') {
      							$class = ($cv_obj->content ? 'unchecked' : 'checked');
      							$change_value = ($cv_obj->content ? '' : (strpos($cv_obj->elements, '==') ? substr(strstr($cv_obj->elements, '=='), 2) : $cv_obj->elements));
      							$menus[$menu][] .=<<<EOD
      <a class="{$class}" href="javascript: qe.ajaxSave('{$cv_obj->id}', '{$cv_obj->name}', '{$change_value}');" title="{$QE_lang['edit']} {$cv_obj->description}">{$cv_obj->caption}</a>
      EOD;
      
      							// Everything else
      						} else {
      
      							$menus[$menu][] .=<<<EOD
      <a href="javascript: qe.open('{$cv_obj->id}');" title="{$QE_lang['edit']} {$cv_obj->description}">{$cv_obj->caption}</a>
      EOD;
      
      						}
      
      					}
      
      				}

      It seems, that QuickEdit asks, if the checkbox is a @-binding, but it doesn´t really do the SQL-query ...


      snippet.NewsPublisherTagging.1.4-1.0.php line 176-184:
      			// tagging
      			$tags = array();
      			foreach($_POST as $n=>$v) {
      				if( substr($n, 0, 5)=='tags-' && $v=='on' ){
      					array_push($tags, substr($n, 5));
      					unset($_POST[$n]);
      				}
      			}
      			$tags_tvcontent = implode('||', $tags);

      NewsPublisherTagging doesn´t even ask, if the checkbox is a @-binding ...

      manager/includes/tmplvars.commands.inc.php line 7-47
      global $BINDINGS; // Array of supported bindings. must be upper case
      $BINDINGS = array('FILE','CHUNK','DOCUMENT','SELECT','EVAL','INHERIT','DIRECTORY');
      
      function ProcessTVCommand($value, $name=''){
      	global $modx;	
      	$etomite = &$modx;
      	
      	$nvalue = trim($value);
      	if (substr($nvalue,0,1)!='@') return $value;
      	else {
      
      		list($cmd,$param) = ParseCommand($nvalue);		
      		switch ($cmd) {
      			case "FILE":
      				...
      			case "SELECT":		// selects a record from the cms database
      				$rt = array();
      				$replacementVars= array(
      					'DBASE'=> $modx->db->config['dbase'],
      					'PREFIX'=> $modx->db->config['table_prefix']
      				);
      				foreach($replacementVars as $key=> $value) {
      					$modx->setPlaceholder($key, $value);
      				}
      				$param = $modx->mergePlaceholderContent($param); 
      				$rs = $modx->db->query("SELECT $param;");
      				$output = $rs;
      				break;

      ... this seems to be the appropriate way to solve @-bindings. But how can I refer to this code or include this code in QuickEdit or NewsPublisherTagging?

      I would be very happy to get some help ...
      thanks a lot ...
        my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
        • 24530
        • 100 Posts
        I still missed one, maybee important part:

        snippet.NewsPublisherTagging.1.4-1.0.php line 258-269:
                    //add tag data
                    if($tags_tvcontent){
                    	$rs = $modx->dbQuery("SELECT id FROM ".$modx->getFullTableName('site_tmplvars')." WHERE name='".substr($tvtags, 2)."' LIMIT 1;");
        	            if($row = $modx->fetchRow($rs, 'assoc')){
        		            $tmplflds = array(
        		            	'tmplvarid' => $row['id'],
        		            	'contentid' => $lastInsertId,
        		            	'value' => mysql_escape_string($tags_tvcontent)
        		            );
        		            $modx->db->insert($tmplflds,$modx->getFullTableName('site_tmplvar_contentvalues'));
        		        }
        	        }

        and line 355-368:
                   //tag area
                    if($tvtags){
                        $rs = $modx->dbQuery("SELECT elements FROM ".$modx->getFullTableName('site_tmplvars')." WHERE name='".substr($tvtags, 2)."' LIMIT 1;");
                        if($row = $modx->fetchRow($rs, 'assoc')){
                            $default_tags = explode('||', $row['elements']);
                            if($default_tags){
        	                    $tag_area = '';
        	                    foreach($default_tags as $tag){
        	                    	$tag_area.= '<input type="checkbox" name="tags-'.$tag.'" id="tags-'.$tag.'" />'.$tag."<br />\n";
        	                    }
        	                    $formTpl = str_replace('[+tags+]',$tag_area,$formTpl);
        	                }
                        }
                    }

        but I just can´t get it together ... my php-knowledge is just too little ...
          my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
          • 24530
          • 100 Posts
          I love to talk with myself! but I didn´t deserve something else: the QuickEdit module works as it should, it just doesn´t accept a space in front of " @SELECT". I deleted the space and it worked as it should ...
          In the meantime I tried to learn PHP and found some solutions:

          I made Quickedit a little more tolerant by changing line 188 in assets/modules/quick_edit/output.class.inc.php:
          if ($cv_obj->type == ’checkbox’ && !strpos($cv_obj->elements, ’||’) && substr(trim($cv_obj->elements), 0, 1) != ’@’) {

          ... and finally I achieved it to tell NewsPublisherTagging how to follow @SELECT-bindings.
          I added following code after line 360 in the file snippet.NewsPublisherTagging.1.4-1.0.php:
                              // follow @SELECT-bindings 
                              $temp_tag = trim($default_tags[0]);
                              
                              if (substr($temp_tag,0,7)=='@SELECT') {
          						unset($default_tags);
          						$query = substr($temp_tag,1);
          						$result = mysql_query($query) or die();
          						
          						while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
          						   foreach ($line as $col_value) {
          							   $default_tags[]=$col_value;
          						   	}
          						}
          					mysql_free_result($result);
          					}
                              // follow @SELECT-bindings end


          I am sorry blaming QuickEdit ...
            my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
            • 22303 MODX Staff
            • 10,725 Posts
            raum:

            Thanks for posting your explorations and soliloquys on QuickEdit and TV behavior. I’m sure your dialog has (or will have) some value to others exploring said features, so don’t feel like you’re just talking to the walls. BTW, if you do have bug reports or feature suggestions, feel free to post them at http://modxcms.com/bugs/ so they have a chance to make it into the product.

            Cheers
              • 23491 ☆ A M B ☆
              • 1,056 Posts
              (I have a similar issue, though not related to QuickEdit, rather @BINDING of Snippets via @CHUNK)

              According to http://modxcms.com/chunk-binding.html:

              @CHUNK Bindings:



              This binding is very similar to the @DOCUMENT binding with the exception that it will bind the TV to a chunk (or htmlsnippet).

              I have a Snippet that queries records in a table and formats and returns them all as one string like so: Display1==val1||Display2==val2||Display3==val3

              I am setting the TV’s Input Option Values as: @CHUNK snippetThatReturnsDropDownOptions

              (I am doing this to populate a TV dropdown with IDs as values with textual descriptors) ... otherwise, I would just use @SELECT

              However, it appears that the documentation may be incorrect/outdated, or possibly I’ve discovered a bug...

              I placed some DB Insert statements inside of the SnippetThatReturnsDropDownOptions snippet to help confirm that the snippet actually got ran, and it doesn’t appear to even run (which explains my empty TV dropdown when editting the document)

              However, when I enter a @CHUNK chunkNameHere, chunkNameHere sure enough returns data as expected.

              Can someone confirm whether the statement:
              "...exception that it will bind the TV to a chunk (or htmlsnippet)" is True?

              I’ve reported this as a Bug (as far as I can tell): http://modxcms.com/bugs/task/789

              Can anyone else confirm? Is this only related to 0.9.6 RC1?


              Too bad @BINDINGS don’t support Snippets sad
                Mike Reid - www.pixelchutes.com
                MODx Ambassador / Contributor
                [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                ________________________________
                Where every pixel matters.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Snippets are snippets of php code. Chunks used to be called "htmlsnippets", since they are snippets of html code.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 23491 ☆ A M B ☆
                  • 1,056 Posts
                  Quote from: sottwell at Feb 20, 2007, 03:57 AM

                  Snippets are snippets of php code. Chunks used to be called "htmlsnippets", since they are snippets of html code.

                  Thanks, Susasn. I was curious if I had mistaken the meaning, and it looks like I have.

                  So I am still curious, if there a way to use @SELECT to populate different Values than the option description/display in a DropDown or Checkbox TV?
                    Mike Reid - www.pixelchutes.com
                    MODx Ambassador / Contributor
                    [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                    ________________________________
                    Where every pixel matters.