/** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria(); $criteria->compare('id', $this->id, true); $criteria->compare('user_id', $this->user_id, true); $criteria->compare('name', $this->name, true); $criteria->compare('date_create', $this->date_create, true); $criteria->compare('ignored', $this->ignored, true); if (!WebUser::isAdmin()) { $criteria->compare('user_id', WebUser::Id()); } $criteria->order = 'user_id, ignored DESC, name'; return new CActiveDataProvider($this, array('criteria' => $criteria)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); if (!WebUser::isAdmin()) { if (WebUser::Id() != $id) { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Users'])) { $model->attributes = $_POST['Users']; $model->password = CPasswordHelper::hashPassword(trim($model->password)); if ($model->save()) { $this->setFlashSuccess('User password for <strong>' . $model->username . '</strong> successfully changed'); $this->redirect(array('admin')); } } $this->render('update', array('model' => $model)); }
<?php /* @var $this SearchController */ /* @var $items EbayItem[] */ /* @var $request SearchRequests */ $this->actions_menu = array(array('label' => 'Create request', 'url' => array('/search/index')), array('label' => 'Update request', 'url' => array('/search/index', 'id' => $request->id))); $listings = ListingNames::model()->getUserLists(WebUser::Id()); ?> <div class="row-fluid"> <div class="span3 pull-right"> <?php $data = array('', 'id' => 'Sort by id', 'id_desc' => 'Sort by id DESC', 'price' => 'Sort by price', 'price_desc' => 'Sort by price DESC', 'bin' => 'Sort by BuyItNow', 'bin_desc' => 'Sort by BuyItNow DESC', 'date_start' => 'Sort by start date', 'date_start_desc' => 'Sort by start date DESC', 'date_end' => 'Sort by end date', 'date_end_desc' => 'Sort by end date DESC'); echo CHtml::label('Sort', 'sort-order'); echo CHtml::dropDownList('sortOrder', 0, $data, array('id' => 'sort-order-list')); ?> </div> </div> <?php $this->widget('bootstrap.widgets.TbGridView', array('id' => 'search-results-grid', 'dataProvider' => new CArrayDataProvider($items, array('pagination' => false)), 'template' => '{summary} {pager} {items} {pager}', 'afterAjaxUpdate' => 'setHandlers', 'pager' => array('class' => 'booster.widgets.TbPager', 'displayFirstAndLast' => true), 'htmlOptions' => array('class' => 'table-hover'), 'rowHtmlOptionsExpression' => 'array("data-item-id" => $data->itemId, "data-date-end" => $data->dateOfEnded, "data-date-start" => $data->dateOfAdded, "data-price" => $data->price, "data-bin" => $data->buyItNow)', 'columns' => array(array('header' => '<input type="checkbox" class="checkbox-all">', 'type' => 'raw', 'value' => function ($data) { /* @var $data EbayItem */ $details = array('ebay_id' => $data->itemId, 'title' => $data->title, 'url_picture' => $data->pictureUrl, 'url_item' => $data->itemUrl, 'buy_it_now' => intval($data->buyItNow != -1), 'date_start' => $data->dateOfAdded, 'date_end' => $data->dateOfEnded, 'currency' => $data->currency); return CHtml::checkBox("EbayItems[id][]", false, array("data-id" => $data->itemId, 'class' => 'checkbox', 'value' => $data->itemId, 'data-details' => json_encode($details))); }, 'footer' => '<input type="checkbox" class="checkbox-all">'), array('type' => 'raw', 'value' => function ($data) { /* @var $data EbayItem */ $img = CHtml::image($data->pictureUrl, $data->title, array('class' => 'item-image')); return CHtml::link($img, $data->itemUrl, array('target' => '_blank')); }, 'htmlOptions' => array('class' => 'item-image')), array('type' => 'raw', 'value' => function ($data) { /* @var $data EbayItem */ $out = 'Item title: <span class="text-error">' . $data->title . '</span><br/>';
$model->only_new = WebUser::isGuest() ? 0 : $model->only_new; $chb_only_new = CHtml::activeCheckBox($model, 'only_new', array('id' => 'checkbox-only-new')); $text = Yii::t('sniper_ebay', 'Only new results'); echo CHtml::label($text . ' ' . $chb_only_new, 'checkbox-only-new'); ?> </td> </tr> <tr class="<?php echo WebUser::isGuest() ? 'hidden' : ''; ?> "> <td> <?php $chb_ignored_list = CHtml::activeCheckBox($model, 'ignore_list', array('id' => 'checkbox-ignored-list')); $text = Yii::t('sniper_ebay', 'Use ignore list'); $ignore_list = ListingNames::model()->getUserIgnoreList(WebUser::Id()); echo CHtml::label($text . ' ' . $chb_ignored_list, 'checkbox-ignored-list'); echo CHtml::link('Browse', array('/listing/index', 'id' => $ignore_list->id), array('target' => '_blank')); ?> </td> </tr> <tr> <td> <?php echo CHtml::submitButton(Yii::t('sniper_ebay', 'Start Search'), array('class' => 'btn btn-primary')); ?> </td> </tr> </table> </form> </div>
public function actionListing($id) { //array $request = array() $request = $this->loadModel($id); if ($request->user_id != WebUser::Id(true)) { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } $atributes = $request->attributes; $atributes['auction_type'] = SearchRequests::model()->getAuctionType($request->auction_type_id); $searchApi = new FindItemsAdvancedClass($atributes); $items_ignored = array(); if ($request->only_new) { $items_ignored = $request->items; } elseif ($request->ignore_list) { $list = ListingNames::model()->getUserIgnoreList(WebUser::Id()); $items_ignored = $list->items; } if (!empty($items_ignored)) { $ignore_ids = CHtml::listData($items_ignored, 'id', 'ebay_id'); $searchApi->setIgnoreIds($ignore_ids); } try { $items = $searchApi->makeAPICall(); $ebay_ids = array(); $items_attrs = array(); $date = time(); foreach ($items as $_item) { $items_attrs[] = array('ebay_id' => $_item->itemId, 'title' => $_item->title, 'url_picture' => $_item->pictureUrl, 'url_item' => $_item->itemUrl, 'buy_it_now' => intval($_item->buyItNow > 0), 'date_of_added' => $date); $ebay_ids[] = $_item->itemId; } SearchItems::model()->saveMultipleIgnore($items_attrs); SearchRequests::model()->addItemsToRequest($id, $ebay_ids); } catch (Exception $ex) { $this->setFlashWarning($ex->getMessage()); $items = $searchApi->getItems(); } if (empty($items)) { $this->setFlashError($searchApi->getError()); } $data = array('items' => $items, 'request' => $request); $this->enableAddToListBtn(); $this->render('listing', $data); }
private function initMenu() { $this->main_menu = array(array('label' => 'Home', 'url' => array('/site/index')), array('label' => 'Search', 'url' => array('/search/index')), array('label' => 'Lists', 'url' => array('/listing/index'), 'visible' => !WebUser::isGuest()), array('label' => '|', 'url' => '#', 'visible' => !WebUser::isGuest()), array('label' => 'Users', 'url' => array('/users/admin'), 'visible' => WebUser::isAdmin()), array('label' => 'Profile', 'url' => array('/users/update', 'id' => WebUser::Id()), 'visible' => !WebUser::isGuest()), array('label' => '|', 'url' => '#', 'visible' => !WebUser::isGuest()), array('label' => 'Login', 'url' => array('/site/login'), 'visible' => WebUser::isGuest()), array('label' => 'Register', 'url' => array('/site/register'), 'visible' => WebUser::isGuest()), array('label' => 'Logout (' . Yii::app()->user->name . ')', 'url' => array('/site/logout'), 'visible' => !WebUser::isGuest())); }