예제 #1
0
파일: Links.php 프로젝트: CGPX/EbayParser
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         $items = Item::find()->where(['id' => $this->itemId])->all();
         foreach ($items as $item) {
             $item->delete();
         }
         return true;
     } else {
         return false;
     }
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Item::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'attached_to' => $this->attached_to, 'provided_by' => $this->provided_by, 'condition' => $this->condition, 'fixed_by' => $this->fixed_by, 'date_added' => $this->date_added, 'date_updated' => $this->date_updated, 'status' => $this->status, 'photos' => $this->photos]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'serial', $this->serial])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'characteristics', $this->characteristics])->andFilterWhere(['like', 'doc_links', $this->doc_links])->andFilterWhere(['like', 'complect', $this->complect]);
     return $dataProvider;
 }
예제 #3
0
파일: ItemList.php 프로젝트: IVsevolod/zouk
 public function getAllItems($lastId = 0, $orderBy = self::ORDER_BY_ID, $dateCreateType = self::DATE_CREATE_LAST, $searchTag = "", $userId = false, $limit = false)
 {
     $query = Item::find()->from(["t" => Item::tableName()])->andWhere('t.deleted = 0')->addSelect('*');
     if ($lastId != 0) {
         $query = $query->andWhere('t.id < :id', [':id' => $lastId]);
     }
     // Определяем сортировку
     if ($orderBy == self::ORDER_BY_ID) {
         $query = $query->orderBy('id DESC');
     } elseif ($orderBy == self::ORDER_BY_LIKE) {
         $query = $query->orderBy('like_count DESC');
     } elseif ($orderBy == self::ORDER_BY_SHOW) {
         $query = $query->orderBy('show_count DESC');
     } elseif ($orderBy == self::ORDER_BY_LIKE_SHOW) {
         $query = $query->addSelect(['(like_count * 15 + show_count) as like_show_count'])->orderBy('like_show_count DESC');
     }
     // Определяем за какой период будем показывать
     if (!empty($limit)) {
         $query = $query->limit((int) $limit);
     } elseif ($dateCreateType == self::DATE_CREATE_LAST) {
         $query = $query->limit(10);
     } elseif ($dateCreateType == self::DATE_CREATE_ALL) {
         $query = $query->limit(50);
     } elseif ($dateCreateType == self::DATE_CREATE_WEEK) {
         $query = $query->andWhere('t.date_create >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 WEEK))');
     } elseif ($dateCreateType == self::DATE_CREATE_MONTH) {
         $query = $query->andWhere('t.date_create >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
     }
     if (!empty($userId)) {
         $query = $query->andWhere('user_id = :userId', [':userId' => $userId]);
     }
     if (!empty($searchTag)) {
         if (is_array($searchTag)) {
             $tagsId = $searchTag;
         } else {
             $tags = Tags::find()->where(['name' => $searchTag])->all();
             $tagsId = [];
             foreach ($tags as $tag) {
                 $tagsId[] = (int) $tag->id;
             }
         }
         if (count($tagsId) > 0) {
             $query = $query->andWhere('(SELECT COUNT(*) as tagCount FROM `' . TagEntity::tableName() . '` te WHERE te.entity = "' . TagEntity::ENTITY_ITEM . '" AND te.entity_id = t.id  AND te.tag_id IN (' . join(',', $tagsId) . ')) > 0');
         }
     }
     $query = $query->with(['videos', 'tagEntity', 'tagEntity.tags']);
     return $query->all();
 }
예제 #4
0
 public function getSingleItem($ebay_item_id)
 {
     return Item::find()->where(['ebay_item_id' => $ebay_item_id])->asArray()->all();
 }
예제 #5
0
 public function actionSitemap()
 {
     // проверяем есть ли закэшированная версия sitemap
     $urls = array();
     $items = Item::find()->where(['deleted' => 0])->all();
     $events = \common\models\Event::find()->where(['deleted' => 0])->all();
     $schools = School::find()->where(['deleted' => 0])->all();
     foreach ($items as $item) {
         /** @var Item $item */
         $urls[] = ['url' => $item->getUrl(true), 'priority' => 0.5];
     }
     foreach ($events as $event) {
         /** @var \common\models\Event $event */
         $urls[] = ['url' => $event->getUrl(true), 'priority' => 0.5];
     }
     foreach ($schools as $school) {
         /** @var School $school */
         $urls[] = ['url' => $school->getUrl(true), 'priority' => 0.8];
     }
     Yii::$app->response->format = \yii\web\Response::FORMAT_XML;
     echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
     echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     foreach ($urls as $url) {
         echo '<url>';
         echo '<loc>' . $url['url'] . '</loc>';
         echo '<changefreq>weekly</changefreq>';
         echo '<priority>' . $url['priority'] . '</priority>';
         echo '</url>';
     }
     echo '</urlset>';
 }
예제 #6
0
파일: Item.php 프로젝트: IVsevolod/zouk
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->alias == "") {
             $title = $this->encodestring($this->title);
             $alias = $this->toAscii($title);
             $baseAlias = substr($alias, 0, 250);
             $alias = $baseAlias;
             $i = 1;
             $wheres = ['alias = :alias'];
             $params[':alias'] = $alias;
             if (!is_null($this->id)) {
                 $wheres[] = 'id <> :id';
                 $params = [':id' => $this->id];
             }
             $where = join(' AND ', $wheres);
             while ($findItem = Item::find()->where($where, $params)->one()) {
                 $alias = $baseAlias . '-' . $i;
                 $params[':alias'] = $alias;
                 $i++;
                 if ($i > 30) {
                     $alias = '';
                     break;
                 }
             }
             $this->alias = $alias;
         }
         return true;
     }
     return false;
 }