model() public static méthode

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : Wishlist
$className string active record class name.
Résultat Wishlist the static model class
Exemple #1
0
 public function getWishListForWeb($user_id)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "user_id = {$user_id}";
     $wishlists = Wishlist::model()->findAll($criteria);
     $wishlist_arr = array();
     foreach ($wishlists as $wishlist) {
         $wishlist_arr[] = $wishlist->post_id;
     }
     //var_dump($wishlist_arr); die;
     $returnArr = array();
     $criteria_post = new CDbCriteria();
     $criteria_post->addInCondition('t.post_id', $wishlist_arr);
     $count = Posts::model()->count($criteria_post);
     $pages = new CPagination($count);
     $pages->validateCurrentPage = FALSE;
     $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
     $pages->applyLimit($criteria_post);
     $posts = Posts::model()->findAll($criteria_post);
     $is_followed = User::model()->isFollowedByUser(Yii::app()->session['user_id'], $user_id, 'USER');
     $profile = User::model()->findByPk($user_id);
     foreach ($posts as $post) {
         $itemArr = Posts::model()->getPostById($post->post_id, Yii::app()->session['user_id']);
         $returnArr[] = $itemArr;
     }
     return array('data' => $returnArr, 'pages' => $pages, 'profile' => $profile, 'is_followed' => $is_followed);
     // return FALSE;
 }
Exemple #2
0
 public static function LoadUserLists()
 {
     if (Yii::app()->user->isGuest) {
         return array();
     }
     return Wishlist::model()->findAllByAttributes(array('customer_id' => Yii::app()->user->id));
 }
 public function afterUninstall()
 {
     $db = Yii::app()->db;
     $tablesArray = array(Wishlist::model()->tableName(), WishlistProducts::model()->tableName());
     foreach ($tablesArray as $table) {
         $db->createCommand()->dropTable($table);
     }
     return parent::afterUninstall();
 }
Exemple #4
0
 /**
  * Create unique key to view orders
  * @param int $size
  * @return string
  */
 public function createSecretKey($size = 10)
 {
     $result = '';
     $chars = '1234567890qweasdzxcrtyfghvbnuioplkjnm';
     while (mb_strlen($result, 'utf8') < $size) {
         $result .= mb_substr($chars, rand(0, mb_strlen($chars, 'utf8')), 1);
     }
     if (Wishlist::model()->cache(Yii::app()->controller->cacheTime)->countByAttributes(array('key' => $result)) > 0) {
         $this->createSecretKey($size);
     }
     return $result;
 }
 public function validAccount($attribute, $param)
 {
     $objCustomer = Customer::LoadByEmail($this->email);
     if (!$objCustomer instanceof Customer) {
         $this->addError($attribute, Yii::t('global', 'Email address not found'));
         return;
     }
     $intQty = Yii::app()->db->createCommand("SELECT COUNT(*) from " . Wishlist::model()->tableName() . "\n\t\t\t\t\tWHERE\n\t\t\t\t\tcustomer_id=" . $objCustomer->id . " AND\n\t\t\t\t\tvisibility=" . Wishlist::PUBLICLIST . ";")->queryScalar();
     if ($intQty == 0) {
         $this->addError($attribute, Yii::t('wishlist', 'No publicly searchable wish lists for this email address.'));
         return;
     }
 }
Exemple #6
0
 public function getWishListForWeb($user_id)
 {
     $returnArr = array();
     $criteria = new CDbCriteria();
     $criteria->condition = "user_id = {$user_id}";
     $count = Posts::model()->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = Yii::app()->params['RESULT_PER_PAGE'];
     $pages->applyLimit($criteria);
     $posts = Wishlist::model()->findAll($criteria);
     if ($posts) {
         foreach ($posts as $post) {
             $itemArr = Posts::model()->getPostById($post->post_id);
             $returnArr[] = $itemArr;
         }
         return array('data' => $returnArr, 'pages' => $pages);
     }
     return FALSE;
 }
 /**
  * Display the logged in user's list of addresses
  * and handle them choosing one
  *
  * @return void
  */
 public function actionShippingAddress()
 {
     $this->publishJS('shipping');
     $this->publishJS('zippo');
     $this->layout = '/layouts/checkout';
     $error = null;
     $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     $arrObjAddresses = CustomerAddress::getActiveAddresses();
     // if the logged in customer has no addresses saved on file
     // take them to the page where they can enter an address
     if (count($arrObjAddresses) < 1) {
         $this->redirect($this->createAbsoluteUrl('/checkout/shipping'));
     }
     $arrFirst = array();
     $objCart = Yii::app()->shoppingcart;
     // if the logged in user has a default shipping address
     // make it appear first
     foreach ($arrObjAddresses as $key => $address) {
         if ($address->id == $objCart->customer->default_shipping_id) {
             $arrFirst['first'] = $address;
             // assign an index to avoid accidental overwrite
             unset($arrObjAddresses[$key]);
         }
     }
     $this->checkoutForm->objAddresses = array_values($arrFirst + $arrObjAddresses);
     $this->checkoutForm->saveFormToSession();
     // populate our form with some default values in case the user
     // was logged in already and bypassed checkout login
     if (isset($this->checkoutForm->contactEmail) === false) {
         $this->checkoutForm->contactEmail = $objCart->customer->email;
     }
     if (isset($this->checkoutForm->contactEmail_repeat) === false) {
         $this->checkoutForm->contactEmail_repeat = $objCart->customer->email;
     }
     if (isset($_POST['MultiCheckoutForm'])) {
         $this->checkoutForm->attributes = $_POST['MultiCheckoutForm'];
     }
     $hasErrors = false;
     $inStorePickupSelected = isset($_POST['storePickupCheckBox']) && $_POST['storePickupCheckBox'] == 1;
     // If in-store pickup was previously selected but has been deselected, make sure it's no longer used.
     if ($inStorePickupSelected === false && $this->checkoutForm->isStorePickupSelected()) {
         // TODO: Factor out this and the similar check in actionShipping.
         $this->checkoutForm->shippingProvider = null;
         $this->checkoutForm->shippingPriority = null;
         $this->checkoutForm->pickupFirstName = null;
         $this->checkoutForm->pickupLastName = null;
     }
     $addressId = Yii::app()->getRequest()->getPost('Address_id');
     $wishlistId = Yii::app()->getRequest()->getPost('wishlistId');
     // Store pickup.
     if ($inStorePickupSelected === true) {
         // store pickup is chosen
         $this->checkoutForm->fillFieldsForStorePickup();
         $this->checkoutForm->setScenario('StorePickup');
         $redirectUrl = $this->createUrl('/checkout/final');
         if ($this->checkoutForm->validate() === false) {
             $hasErrors = true;
         }
     } elseif ($addressId || $wishlistId) {
         $customerId = null;
         if ($wishlistId) {
             $wishlist = Wishlist::model()->findByPk($wishlistId);
             $addressId = $wishlist->ship_option;
             $customerId = $wishlist->customer_id;
         }
         // An existing shipping address is chosen.
         $result = $this->checkoutForm->fetchCustomerShippingAddress($addressId, $customerId);
         if ($result === false) {
             $this->redirect($this->createAbsoluteUrl("/checkout/shippingaddress"));
         }
         $this->checkoutForm->setScenario('Shipping');
         $redirectUrl = $this->createUrl('/checkout/shippingoptions');
         if ($this->checkoutForm->validate() == false) {
             $hasErrors = true;
         }
     } else {
         $wishlist = null;
         $wishlistAddress = null;
         // If any of the cart items are on a wishlist, then we show the
         // wishlist address to the user.
         foreach ($objCart->cartItems as $item) {
             if ($item->wishlist_item !== null) {
                 $wishlist = $item->wishlistItem()->registry();
                 $wishlistAddressId = $wishlist->ship_option;
                 $wishlistAddress = CustomerAddress::model()->findByPk($wishlistAddressId);
                 break;
                 // Multiple wishlist addresses are not yet supported.
             }
         }
         // Nothing was posted, just render the shipping address page.
         $this->render('shippingaddress', array('model' => $this->checkoutForm, 'error' => $this->formatErrors(), 'wishlist' => $wishlist, 'wishlistAddress' => $wishlistAddress));
         return;
     }
     // Update address ID if there are no errors.
     if ($hasErrors === false) {
         $this->checkoutForm->updateAddressId();
         // An error occurred in updateAddressId.
         if (count($this->checkoutForm->getErrors())) {
             $hasErrors = true;
         }
     }
     // A validation error occurred.
     if ($hasErrors === true) {
         $this->render('shippingaddress', array('model' => $this->checkoutForm, 'error' => $this->formatErrors()));
         return;
     }
     // Update the shipping scenarios based on the new address.
     $this->checkoutForm->saveFormToSession();
     Shipping::updateCartScenariosInSession();
     // If in-store pickup was selected we need to update the cart now
     // before moving to checkout/final. Otherwise, the address will be
     // validated at the next step and the taxes updated.
     if ($inStorePickupSelected === true) {
         // Update the shopping cart taxes.
         Yii::app()->shoppingcart->setTaxCodeByCheckoutForm($this->checkoutForm);
         // Update shipping. If in-store pickup was chosen then we need to
         // ensure the cart shipping values are updated.
         // Update shipping. If in-store pickup was chosen then we need to
         // ensure the cart shipping values are updated.
         $objShipping = CartShipping::getOrCreateCartShipping();
         if ($objShipping->hasErrors() === false) {
             $objShipping->updateShipping();
             $this->checkoutForm->addErrors($objShipping->getErrors());
         } else {
             $this->checkoutForm->addErrors($objShipping->getErrors());
         }
     }
     // Save the passed scenario and redirect to the next stage.
     $this->checkoutForm->passedScenario = $this->checkoutForm->getScenario();
     $this->redirect($redirectUrl);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Wishlist the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Wishlist::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionEmail()
 {
     if (Yii::app()->user->isGuest) {
         _xls_404();
     }
     $model = new ShareForm();
     if (isset($_POST['ShareForm'])) {
         $model->attributes = $_POST['ShareForm'];
         if ($model->validate()) {
             $strCode = $model->code;
             //Make sure code we've been passed is valid
             $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode));
             if (!$objWishlist->Visible) {
                 _xls_404();
             }
             if (!Yii::app()->user->isGuest) {
                 $objCustomer = Customer::model()->findByPk(Yii::app()->user->Id);
                 $model->fromEmail = $objCustomer->email;
                 $model->fromName = $objCustomer->fullname;
             }
             $strHtmlBody = $this->renderPartial('/mail/_cart', array('model' => $model), true);
             $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_WISHLIST', $objWishlist->customer->fullname, null);
             $objEmail = new EmailQueue();
             $objEmail->customer_id = $objWishlist->customer_id;
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $objEmail->to = $model->toEmail;
             $objHtml = new HtmlToText();
             //If we get back false, it means conversion failed which 99.9% of the time means improper HTML.
             $strPlain = $objHtml->convert_html_to_text($strHtmlBody);
             if ($strPlain !== false) {
                 $objEmail->plainbody = $strPlain;
             }
             $objEmail->save();
             $response_array = array('status' => "success", 'message' => Yii::t('wishlist', 'Your wish list has been sent'), 'url' => CController::createUrl('site/sendemail', array("id" => $objEmail->id)), 'reload' => true);
         } else {
             $response_array['status'] = 'error';
             $response_array['errormsg'] = _xls_convert_errors($model->getErrors());
         }
         echo json_encode($response_array);
     }
 }
Exemple #10
0
 public function checkIfPostIsBookmarked($post_id, $user_id)
 {
     $check = Wishlist::model()->findByAttributes(array('post_id' => $post_id, 'user_id' => $user_id));
     if ($check) {
         return TRUE;
     }
     return FALSE;
 }
 /**
  * @param $key
  * @return CActiveRecord
  * @throws CException
  */
 public function loadByKey($key)
 {
     $model = Wishlist::model()->findByAttributes(array('key' => $key));
     if ($model === null) {
         throw new CException();
     }
     $this->_model = $model;
     $this->_user_id = $model->user_id;
     return $model;
 }
Exemple #12
0
 public function actionPostToAlbum()
 {
     $posts = Posts::model()->findAll();
     foreach ($posts as $item) {
         $check = PostAlbum::model()->findByAttributes(array('album_id' => $item->album_id, 'post_id' => $item->post_id));
         if (!$check) {
             $model = new PostAlbum();
             $model->post_id = $item->post_id;
             $model->album_id = $item->album_id;
             $model->created_at = time();
             $model->updated_at = time();
             $model->save(FALSE);
         }
     }
     $wishilist = Wishlist::model()->findAll();
     foreach ($wishilist as $item) {
         $check = PostAlbum::model()->findByAttributes(array('album_id' => $item->album_id, 'post_id' => $item->post_id));
         if (!$check) {
             $model = new PostAlbum();
             $model->post_id = $item->post_id;
             $model->album_id = $item->album_id;
             $model->created_at = time();
             $model->updated_at = time();
             $model->save(FALSE);
         }
     }
 }
 public function loadWishlistModel($bid)
 {
     $uid = Yii::app()->user->getId();
     $model = Wishlist::model()->findByAttributes(array('user_id' => $uid, 'product_id' => $bid));
     //		if($model===null)
     //                    $model=new Wishlist;
     return $model;
 }