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; } }
/** * 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; }
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(); }
public function sendEmail($email) { $text = ''; $cart = json_decode($this->itemslist); $mailArr = []; $mailArr[] = Yii::$app->params['adminEmail']; if (!empty($this->email)) { $mailArr[] = $this->email; } if (count($cart) > 0) { foreach ($cart as $item) { $ebayItem = Item::findOne(['ebay_item_id' => $item[0]]); $text .= '<tr>' . ' <td>' . $ebayItem['ebay_item_id'] . '</td> ' . '<td>' . $ebayItem['title'] . '</td>' . ' <td>' . $ebayItem['current_price_value'] . '</td>' . '<td>' . $item[3] . '</td>>' . '<td>' . $ebayItem['current_price_value'] * $item[3] . '</td><td>' . $ebayItem['viewItemURL'] . '</td>></tr>'; } return Yii::$app->mailer->compose('order-link', ['user' => Yii::$app->user->identity, 'name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'text' => $text])->setTo($mailArr)->setFrom(Yii::$app->params['supportEmail'])->setSubject($this->subject)->send(); } else { return false; } }
/** * @return \yii\db\ActiveQuery */ public function getItems() { return $this->hasMany(Item::className(), ['note_id' => 'id']); }
public function getSingleItem($ebay_item_id) { return Item::find()->where(['ebay_item_id' => $ebay_item_id])->asArray()->all(); }
public function getItems() { return $this->hasMany(Item::className(), ['id' => 'entity_1_id'])->viaTable(EntityLink::tableName(), ['entity_2_id' => 'id'], function ($query) { $query->onCondition(['entity_1' => Item::THIS_ENTITY, 'entity_2' => Video::THIS_ENTITY]); }); }
public static function addVote($entity, $id, $voteAdd) { $user = User::thisUser(); $vote = Vote::findOne(['entity' => $entity, 'entity_id' => $id, 'user_id' => $user->id]); if (empty($vote)) { $vote = new Vote(); $vote->entity = $entity; $vote->entity_id = $id; $vote->user_id = $user->id; } /** @var VoteModel $model */ $model = null; if ($entity == self::ENTITY_ITEM) { $model = Item::findOne($id); if ($user->reputation < Item::MIN_REPUTATION_ITEM_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } else { if ($entity == self::ENTITY_EVENT) { $model = Event::findOne($id); if ($user->reputation < Event::MIN_REPUTATION_EVENT_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } else { if ($entity == self::ENTITY_SCHOOL) { $model = School::findOne($id); if ($user->reputation < School::MIN_REPUTATION_SCHOOL_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } else { if ($entity == self::ENTITY_COMMENT) { $model = Comment::findOne($id); if ($user->reputation < Comment::MIN_REPUTATION_COMMENT_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } } } } if (!empty($model)) { if ($vote->vote == self::VOTE_UP) { if ($voteAdd == self::VOTE_UP) { // убираем up $vote->vote = self::VOTE_NONE; $model->addVote(-1); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP); } else { // ставим down $vote->vote = self::VOTE_DOWN; $model->addVote(-2); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP); $model->addReputation(VoteModel::ADD_REPUTATION_DOWN); } } elseif ($vote->vote == self::VOTE_DOWN) { if ($voteAdd == self::VOTE_UP) { // ставим up $vote->vote = self::VOTE_UP; $model->addVote(2); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN); $model->addReputation(VoteModel::ADD_REPUTATION_UP); } else { // убираем down $vote->vote = self::VOTE_NONE; $model->addVote(1); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN); } } else { if ($voteAdd == self::VOTE_UP) { // ставим up $vote->vote = self::VOTE_UP; $model->addVote(1); $model->addReputation(VoteModel::ADD_REPUTATION_UP); } else { // ставим down $vote->vote = self::VOTE_DOWN; $model->addVote(-1); $model->addReputation(VoteModel::ADD_REPUTATION_DOWN); } } } if ($vote->save()) { if (!empty($model)) { $model->save(); } } return ['vote' => $vote->vote, 'count' => $model->getVoteCount()]; }
public function getEntityModel() { if ($this->entity == self::ENTITY_ITEM) { return Item::findOne(['id' => $this->entity_id]); } }
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>'; }
public function actionAlarm() { $id = Yii::$app->request->post('id'); $msg = Yii::$app->request->post('msg'); $item = Item::findOne($id); if ($item && !empty($msg)) { if (Alarm::addAlarm(Alarm::ENTITY_ITEM, $item->id, $msg)) { $resultMsg = Lang::t('main/dialogs', 'modalAlarm_msgAlarmResultTrue'); Yii::$app->session->setFlash('success', $resultMsg); } else { $resultMsg = Lang::t('main/dialogs', 'modalAlarm_msgAlarmResultFalse'); Yii::$app->session->setFlash('success', $resultMsg); } return json_encode(['msg' => $resultMsg]); } }
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; }
/** * Finds the Item model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Item the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Item::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getItemsWithOrderBy($priceField = 'price_shipping_sum', $order = SORT_DESC) { return $this->hasMany(Item::className(), ['id' => 'itemId'])->viaTable('links', ['hashId' => 'id'])->orderBy([$priceField => $order]); }