public function getPosition($from = 1, $count = 1)
 {
     $console = Console::getInstance();
     $console->operationStart('Collecting search results');
     $this->pageNumber = ceil($from / $this->positionsPerPage);
     if ($count < 1 || $count > 10) {
         $console->operationEnd();
         $console - error('Count must be in 1-10. ' . $count . ' is setted');
         return false;
     }
     $sites = array();
     $position = 1;
     do {
         $console->operationStep();
         $pageResults = $this->getPageResults();
         foreach ($pageResults as $pr) {
             $sitesCount = count($sites);
             $domain = ($domain = String::rebuildUrl($pr->url, false, false, true, false)) ? $domain : $pr->url;
             if (IgnoreList::isInList($domain) || $sitesCount && $sites[$sitesCount - 1]->domain == $domain) {
                 continue;
             }
             $site = new Site();
             $site->name = strip_tags($pr->title);
             $site->position = $position++;
             $site->link = $pr->url;
             $site->domain = $domain;
             $sites[] = $site;
         }
         $this->pageNumber++;
     } while ($sitesCount < $count);
     //$this->pageNumber++ * $this->positionsPerPage < $count // old
     $console->operationEnd();
     return array_slice($sites, 0, $count);
 }
Esempio n. 2
0
 public function actionIgnoreListDelete($ignoreListId)
 {
     IgnoreList::model()->deleteByPk($ignoreListId);
     $this->redirect(Yii::app()->createUrl('site/ignoreList'));
 }
Esempio n. 3
0
 public static function isInList($domain)
 {
     return IgnoreList::model()->find('domain = :domain', array(':domain' => $domain)) ? true : false;
 }
Esempio n. 4
0
 public function searchLeads()
 {
     $criteria = new CDbCriteria();
     $criteria->alias = 'site';
     $criteria->addCondition('site.deleted_at IS NULL');
     $criteria->group = 'site.domain';
     $criteria->distinct = true;
     $sites = Site::model()->findAll($criteria);
     $sitesCount = count($sites);
     for ($i = 0; $i < $sitesCount; $i++) {
         if (IgnoreList::isInList($sites[$i]->domain)) {
             unset($sites[$i]);
         }
     }
     return new CArrayDataProvider($sites, array('sort' => array('attributes' => array('*')), 'pagination' => array('pageSize' => 50)));
 }
Esempio n. 5
0
 public function generate()
 {
     $reportHtml = '';
     $criteria = new CDbCriteria();
     $criteria->alias = 'site';
     $criteria->addCondition('site.deleted_at IS NULL');
     $criteria->group = 'site.domain';
     $criteria->distinct = true;
     $site = Site::model()->findAll($criteria);
     $reportHtml .= '<table>';
     $row = '<tr>';
     $row .= '<th>Domain</th>';
     $row .= '<th>Keyword</th>';
     $row .= '<th>Added On</th>';
     $row .= '</tr>';
     $reportHtml .= $row;
     foreach ($site as $s) {
         if (IgnoreList::isInList($s->domain)) {
             continue;
         }
         $row = '<tr>';
         $row .= '<td>' . $s->domain . '</td>';
         $row .= '<td>' . $s->keyword->name . '</td>';
         $row .= '<td>' . Time::toPretty($s->created_at) . '</td>';
         $row .= '</tr>';
         $reportHtml .= $row;
     }
     $reportHtml .= '</table><p><i>Report generated on ' . date(Time::FORMAT_PRETTY) . '</i></p>';
     return $reportHtml;
 }