×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Different text if no comments

Different text if no comments 14 years 11 months ago #3751

  • Isak
  • Isak's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
Thanks for a great component. My wish is a small one. When there are no comments after an article the same text "Write comment (# comments)" show as when there are comments. It would be great if it could say something in the line of "There are no comments yet, why don't you write one!" or the likes. It's actually the only feature I miss from yvcomment. :)

Different text if no comments 14 years 11 months ago #3778

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Well, I can tell you a way to make it. The only problem will be that after a comment is there you will need to refresh the page for the message to disappear.

Different text if no comments 14 years 11 months ago #3795

  • Isak
  • Isak's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
Well that's fine, would be great if you could tell me how to do it :)

Different text if no comments 14 years 11 months ago #3798

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Ok, you will need to change 2 function (I suppose you use joomlacomment alpha3)

open components/com_comment/joscomment/comment.class.php

find the function getComments and change it with the one I've added.
    function getComments($onlydata=false)
    {
		$database =& JFactory::getDBO();			
 
        if ($this->_sort_downward) {
         	$sort = 'DESC'; /* new first */
        } else {
			$sort = 'ASC'; /* last first */
        }		
        $html = '';
		$com = $this->_component;
		/*
		 * ORDER must be done only on high level
		 * because children must be ordered ascending for tree construction
		 */        
        $queryselect 	= "SELECT * ";
        $querycount 	= "SELECT COUNT(*) ";
        $queryfrom 		= "\nFROM jos_comment"
        				. "\n WHERE contentid='$this->_content_id' AND component='$com' "
        				. "\n   AND published='1' ";
		$queryparent	= $this->_tree ? "\n   AND parentid<=0 " : "";        				
		$querychildren	= $this->_tree ? "\n   AND parentid>0 "  : "";        				
        $queryorder		= "\n ORDER BY id $sort";    
 
        if ($this->_display_num>0) {
 
			/*
			 * pages -> use limitstart on root id (childs are not counted - always attached to root id)
			 */
 
	    	if ($this->_comment_id) {
				/* 
				 * - get the limitstart(page) of the comment_id 
				 * - comment id can be a root id but also a child ! 
				 * in this case, we must search for its root id.
				 */
				$parentid = $id = $this->_comment_id;
	    		for ($i=1; $i<=20 && $parentid>0; $i++)
	    		{   /* LEFT JOIN is for loop optimization : 1 loop = 2 levels */
    	   			/* 20 times is for infinity loop limit = maximum 40 levels.  it should be enough....? :) */
	    			$query 	= "SELECT c.id, c.parentid, p.id AS p_id, p.parentid AS p_parentid "
    	   					. "\n FROM jos_comment AS c LEFT JOIN jos_comment AS p ON c.parentid=p.id "
    	   					. "\n    WHERE c.id=$parentid LIMIT 1";
    	   			$database->SetQuery($query);
    	   			$row = $database->loadAssocList();
    	   			if ($row=$row[0]) { 
	    	   			$id = $row['id'];
    		   			$parentid = $row['parentid'];
    		   			if ($row['parentid']>0) {
    	   					$id = $row['p_id'];
    	   					$parentid=$row['p_parentid'];
    	   				}
    	   			} else {
    	   				$id = $parentid = -1;
    	   			}
	    		}
	    		if ($id) {
					/* get the limitstart from the root id */
        			$database->SetQuery("SELECT id ".$queryfrom.$queryparent.$queryorder);
    	    		$data = $database->loadResultArray();
    	    		$i = array_search($id, $data);
    	    		if ($i) $this->_limitstart = $i;           
	    		}    		
	    	}
 
        	$database->SetQuery($querycount.$queryfrom.$queryparent.$queryorder);
        	$this->_total = $database->loadResult();
 
        	$checklimit = new JOSC_PageNav($this->_ajax, $this->_total, $this->_limitstart, $this->_display_num);
        	$this->_limitstart = $checklimit->limitstart;
			$database->SetQuery($queryselect.$queryfrom.$queryparent.$queryorder, $this->_limitstart, $this->_display_num);
	        $dataparent = $database->loadAssocList();		
 
        } else {
        	$database->SetQuery($queryselect.$queryfrom.$queryparent.$queryorder);
    	    $dataparent = $database->loadAssocList();
        }
        if ($this->_tree) {
			$database->SetQuery($queryselect.$queryfrom.$querychildren."\n ORDER BY id ASC");
			$datachildren = $database->loadAssocList();
 
			$data = ($dataparent && count($datachildren)>0) ?  array_merge($dataparent,$datachildren) : $dataparent;
        } else {
        	$data = $dataparent;
        }
//return "displ=".$this->_display_num; 
//return JOSC_utils::debug_array($data);
 
		/* 
		 * $data is composed of ALL  or   ROOT array + CHILDREN array
		 * 	this means that position of a ROOT gives the page position.
		 */
        $postCSS = 1;
 
		if (!$data && $onlydata) return $data;
 
        if ($data != null) {
 
            if ($this->_tree) $data = JOSC_utils::buildTree($data);
 
//return $data;
            if ($onlydata) return $data; /* after the foreach */
 
            if ($data != null) {
                foreach($data as $item) {
	            	$html .= $this->insertPost($item, $postCSS);
    	            $postCSS++;
        	        if ($postCSS == 3) $postCSS = 1;
                }
            }
        }
 
		$document = JFactory::getDocument();
 
        $addjs = " var JOSC_postCSS=$postCSS;";
 
		$document->addScriptDeclaration($addjs);
 
		/* Daniel add-on for Allvideo Reloaded */
			if (JPluginHelper::importPlugin('content', 'avreloaded')) { 
    			$app = &JFactory::getApplication(); 
    			$res = $app->triggerEvent('onAvReloadedGetVideo', array($html)); 
    			if (is_array($res) && (count($res) == 1)) { 
    				$html = $res[0]; 
    			} 
			}
			return $html;
    }

then after this function find the insertComments() and change it to this one
    function insertComments()
    {
		$html = $this->getComments();
		if(strcmp($html,'')) {
			$output = $html;
		} else {
//			TODO: show some text when there is no comment - needs changes in the javascript file.
			$output = '';
		}
 
		return "<div id='Comments'>".$output."</div>";
    }

change $output = ''; to
$output = 'the text you wish to display when there are no comments';
and it should work.

As I said - when you publish new comment - the text will stay there, but after a refresh it will go away.

Different text if no comments 14 years 10 months ago #3897

  • Isak
  • Isak's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
Thanks a bunch! :)

Different text if no comments 14 years 10 months ago #3898

  • Isak
  • Isak's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
Hmm, it aint working. The text saying there are no comments shows up above the input comment field on the comment page instead of replacing the "Read on" text on the article page.

Different text if no comments 14 years 10 months ago #3900

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Oh, well I didn't understand that you want different text for the read more.

I will have to look for this.
  • Page:
  • 1
Time to create page: 0.133 seconds