Code Duplication    Length = 22-23 lines in 3 locations

src/TextContent/Content.php 3 locations

@@ 297-319 (lines=23) @@
294
   * @param  boolean    $publish    Check if it needs to be publish
295
   * @return int   						      With count
296
   */
297
  public function countAllContentOfTag($tag, $type, $publish = true){
298
    $now    = date('Y-m-d H:i:s');
299
    $params = [$tag, $type];
300
    
301
    $this->db->select("COUNT(c.id) AS countAll")
302
             ->from("content AS c")
303
             ->join("content_tags AS t", "t.idContent = c.id")
304
             ->where("t.slug = ?")
305
             ->andWhere("c.`type` = ?")
306
             ->andWhere("c.`deleted` IS NULL");
307
    
308
    if($publish){
309
      $this->db->andWhere("c.published <= ?");
310
      $params[] = $now;
311
    }
312
    
313
    $this->db->execute($params);
314
    
315
    $this->db->setFetchModeClass(__CLASS__);
316
    $count = $this->db->fetchOne();
317
    
318
    return $count->countAll;		
319
  }
320
	
321
  /*****
322
   ***
@@ 146-168 (lines=23) @@
143
   * @param  	string  	$type			Wich type of content ex. blog, page etc.
144
   * @return 	object   						With content data from database
145
   */
146
  public function getContentByUrl($url, $type, $publish = true){
147
    $now    = date('Y-m-d H:i:s');
148
    $params = [$url, $type];
149
150
    $this->db->select("c.*")
151
             ->from("content AS c")
152
    //       ->join("user AS u", "c.author = u.id")
153
             ->where("c.url = ?")
154
             ->andWhere("c.`type` = ?")
155
             ->andWhere("c.`deleted` IS NULL");
156
157
    if($publish){
158
      $this->db->andWhere("c.published <= ?");
159
      $params[] = $now;
160
    }
161
162
    $this->db->orderBy('c.published DESC, c.created DESC')
163
             ->limit(1)
164
             ->execute($params);
165
166
    $this->db->setFetchModeClass(__CLASS__);
167
    return $this->db->fetchOne();
168
  }
169
	
170
  /**
171
   * Get content from database by slug
@@ 178-199 (lines=22) @@
175
   * @param  	string  $type			Wich type of content ex. blog, page etc.
176
   * @return 	object   					With content data from database
177
   */
178
  public function getContentBySlug($slug, $type, $publish = true){
179
    $now = date('Y-m-d H:i:s');
180
    $params = array($slug, $type);
181
    $this->db->select("c.*")
182
             ->from("content AS c")
183
    //       ->join("user AS u", "c.author = u.id")
184
             ->where("c.slug = ?")
185
             ->andWhere("c.`type` = ?")
186
             ->andWhere("c.`deleted` IS NULL");
187
           
188
    if($publish){
189
      $this->db->andWhere("c.published <= ?");
190
      $params[] = $now;
191
    }
192
193
    $this->db->orderBy('c.published DESC, c.created DESC')
194
             ->limit(1)
195
             ->execute($params);
196
197
    $this->db->setFetchModeClass(__CLASS__);
198
    return $this->db->fetchOne();
199
  }
200
	
201
  /**
202
   * Get content from database by index