コード例 #1
0
ファイル: News.php プロジェクト: ChristopheBrun/hLib
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  */
 public function search()
 {
     $criteria = new CDbCriteria();
     $criteria->compare('event_date', h::inputDateToSQL($this->event_date), true);
     $criteria->compare('enabled', $this->enabled);
     $criteria->compare('category_id', $this->category_id);
     return new CActiveDataProvider($this, array('criteria' => $criteria));
 }
コード例 #2
0
ファイル: hTest.php プロジェクト: ChristopheBrun/hLib
 /**
  * Les dates sont transformées au format [opérateur] YYYY-MM-DD
  * @test
  */
 public function inputDateToSQL()
 {
     $validationPattern = "#^(<|<=|=|<>|>=|>)?(\\d\\d\\d\\d-\\d\\d-\\d\\d)\$#";
     $this->assertRegExp($validationPattern, h::inputDateToSQL('18/05/2012'));
     $this->assertRegExp($validationPattern, h::inputDateToSQL('> 18/05/2012'));
     $this->assertNotRegExp($validationPattern, h::inputDateToSQL('18/05/20a2'));
     $this->assertNotRegExp($validationPattern, h::inputDateToSQL('18/a5/2012'));
     $this->assertNotRegExp($validationPattern, h::inputDateToSQL('a8/05/2012'));
     $matches = array();
     $date = h::inputDateToSQL('> 18/05/2012');
     $this->assertEquals(1, preg_match($validationPattern, h::inputDateToSQL('> 18/05/2012'), $matches));
     $this->assertEquals('>', trim($matches[1]));
     $this->assertStringStartsWith($matches[1], $date);
 }
コード例 #3
0
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  */
 public function search()
 {
     $criteria = new CDbCriteria();
     $criteria->with = array('news');
     // filtres sur la table principale
     $criteria->compare('t.news_id', $this->news_id);
     $criteria->compare('t.language_id', $this->language_id);
     $criteria->compare('t.title', $this->title, true);
     $criteria->compare('t.description', $this->description, true);
     $criteria->compare('t.keywords', $this->keywords, true);
     $criteria->compare('t.content', $this->content, true);
     // filtres sur la table news
     $this->eventDate = trim($this->eventDate);
     if ($this->eventDate !== "") {
         $sqlDate = h::inputDateToSQL($this->eventDate);
         $criteria->addCondition("news.event_date = '{$sqlDate}'");
     }
     $this->enabled = trim($this->enabled);
     if ($this->enabled !== "") {
         $criteria->addCondition("news.enabled = {$this->enabled}");
     }
     // filtres sur les tags
     if ($tag = trim($this->tagsString)) {
         // ...depuis le frontend avec une chaine de caractères (formulaire de recherche, recherche élargie)
         $criteria->addSearchCondition('tags.name', $tag, true);
         $criteria->with[] = 'tags';
     } elseif ($tagId = intval($this->tagIdFilter)) {
         // ... depuis le backend ou le frontend avec un bouton 'tag'
         $criteria->addCondition("tags.id = {$tagId}");
         $criteria->with[] = 'tags';
     }
     $criteria->together = true;
     $criteria->scopes = 'defaultOrder';
     return new CActiveDataProvider($this, array('criteria' => $criteria));
 }