Changeset 5774
- Timestamp:
- 10/31/07 09:58:29 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelActAsCommentableBehaviorPlugin/trunk/lib/sfPropelActAsCommentableBehavior.class.php
r5664 r5774 111 111 public function getComments(BaseObject $object, $options = array(), Criteria $criteria = null) 112 112 { 113 $c = $this->getCommentsCriteria($object, $options, $criteria); 114 $comment_objects = sfCommentPeer::doSelect($c); 115 $comments = array(); 116 117 foreach ($comment_objects as $comment_object) 118 { 119 $comment = $comment_object->toArray(); 120 $comments[] = $comment; 121 } 122 123 return $comments; 124 } 125 126 /** 127 * Returns a criteria for comments selection. The options array 128 * can contain several options : 129 * - order : order of the comments 130 * 131 * @param BaseObject $object 132 * @param Array $options 133 * @param Criteria $criteria 134 * 135 * @return Array 136 */ 137 protected function getCommentsCriteria(BaseObject $object, $options = array(), Criteria $criteria = null) 138 { 113 139 if ($criteria != null) 114 140 { … … 143 169 } 144 170 145 $comment_objects = sfCommentPeer::doSelect($c); 146 $comments = array(); 147 148 foreach ($comment_objects as $comment_object) 149 { 150 $comment = $comment_object->toArray(); 151 $comments[] = $comment; 152 } 153 154 return $comments; 171 return $c; 155 172 } 156 173 … … 166 183 public function getNbComments(BaseObject $object, $options = array(), Criteria $criteria = null) 167 184 { 168 return count($this->getComments($object, $options, $criteria)); 185 $c = $this->getCommentsCriteria($object, $options, $criteria); 186 return sfCommentPeer::doCount($c); 169 187 } 170 188 plugins/sfPropelActAsCommentableBehaviorPlugin/trunk/test/unit/sfPropelActAsCommentableBehaviorTest.php
r5680 r5774 21 21 22 22 // start tests 23 $t = new lime_test( 8, new lime_output_color());23 $t = new lime_test(11, new lime_output_color()); 24 24 25 25 … … 45 45 $object2_comments = $object2->getComments(); 46 46 $t->ok((count($object1_comments) == 2) && (count($object2_comments) == 1), 'one comment is only attached to one Propel object.'); 47 $t->ok(count($object1_comments) == $object1->getNbComments(), 'getNbComment() permùits to retrieve one object\'s comments number.'); 47 48 48 49 $object3 = _create_object();