Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1323 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1323 Rev 1662
Línea 109... Línea 109...
109
       $select->order('added_on DESC');
109
       $select->order('added_on DESC');
Línea 110... Línea 110...
110
       
110
       
111
       return $this->executeFetchAllObject($select, $prototype);
111
       return $this->executeFetchAllObject($select, $prototype);
Línea -... Línea 112...
-
 
112
   }
-
 
113
   
-
 
114
   /*
-
 
115
   * @param int $capsule_id
-
 
116
   * return CompanyMicrolearningCapsuleComment[]
-
 
117
   */
-
 
118
   public function fetchAllByCapsuleId($capsule_id)
-
 
119
   {
-
 
120
       $prototype = new CompanyMicrolearningCapsuleComment();
-
 
121
       
-
 
122
       $select = $this->sql->select();
-
 
123
       $select->from(self::_TABLE);
-
 
124
       $select->where->equalTo('capsule_id', $capsule_id);
-
 
125
       $select->order('added_on DESC');
-
 
126
       
-
 
127
       return $this->executeFetchAllObject($select, $prototype);
Línea 112... Línea 128...
112
   }
128
   }
113
   
129
   
114
   
130
   
115
   /**
131
   /**
Línea 180... Línea 196...
180
    * @return number[]
196
    * @return number[]
181
    */
197
    */
182
   public function fetchCountAndRatingAverage($company_id, $topic_id, $capsule_id)
198
   public function fetchCountAndRatingAverage($company_id, $topic_id, $capsule_id)
183
   {
199
   {
184
       $select = $this->sql->select();
200
       $select = $this->sql->select();
-
 
201
       $select->columns([
185
       $select->columns(['qty' => new Expression('COUNT(*)'), 'rating' ]);
202
           'total_comments' => new Expression('COUNT(*)'), 
-
 
203
           'total_rating'   => new Expression('COALESCE(AVG(rating), 0)')
-
 
204
       ]);
-
 
205
 
186
       $select->from(self::_TABLE);
206
       $select->from(self::_TABLE);
187
       $select->where->equalTo('company_id', $company_id);
207
       $select->where->equalTo('company_id', $company_id);
188
       $select->where->equalTo('topic_id', $topic_id);
208
       $select->where->equalTo('topic_id', $topic_id);
189
       $select->where->equalTo('capsule_id', $capsule_id);
209
       $select->where->equalTo('capsule_id', $capsule_id);
Línea 190... Línea -...
190
    
-
 
191
       $total_comments  = 0;
-
 
192
       $total_rating = 0;
-
 
193
       
210
    
194
       $records = $this->executeFetchAllArray($select);
-
 
195
       foreach($records as $record)
-
 
196
       {
-
 
197
           $total_comments += $record['qty'];
-
 
198
           $total_rating += ($record['qty'] * $record['rating']);
-
 
199
       }
211
       $record = $this->executeFetchOneArray($select);
200
       
212
 
201
       return  [
213
       return  [
202
           'total_comments' => $total_comments,
214
           'total_comments' => $record['total_comments'],
203
           'total_rating'  => $total_comments > 0 ? round($total_rating / $total_comments) : 0,
215
           'total_rating'   => $record['total_rating'],
Línea 204... Línea 216...
204
       ];
216
       ];