public function isSubscribe($userId) { $return = false; $currentDate = date('Y-m-d H:i:s'); $criteria = new CDbCriteria(); $criteria->condition = "UserId=" . $userId; $criteria->order = "Objid DESC"; $criteria->limit = 1; if (MembershipUsers::model()->count($criteria)) { $model = MembershipUsers::model()->findAll($criteria); if ($currentDate <= $model[0]->MembershipEnd || $model[0]->membership->Duration == 0) { $return = true; } } return $return; }
<div class="upgrade_profile_details"> <div class="credit_section"> <span>AD SPACE</span> </div> </div> <?php $loginUserId = Yii::app()->user->getId(); $model = Memberships::model()->findByAttributes(array("Price" => 0)); $details = MembershipUsers::model()->findByAttributes(array("UserId" => $loginUserId, "MembershipId" => $model->Objid)); if (empty($details)) { ?> <div class="upgrade_profile_details"> <div class="duration"><?php echo $model->Duration; ?> <span>Months</span></div> <?php echo CHtml::link('<img src="' . Yii::app()->theme->baseUrl . '/images/free-membership1.jpg"/>', array('upgradepack/free')); ?> </div> <?php }
</h4> <span><?php echo $model->sender->UserName; ?> |<?php echo date('D, d M', strtotime($model->Date)); ?> </span> </div> <div class="clear"></div> <div class="messageBody"> <?php echo $model->Message; ?> </div> <div class="messageFooter"> <?php if (MembershipUsers::model()->isSubscribe(Yii::app()->user->getId())) { echo CHtml::link("Reply", array('message/reply', 'id' => $model->Objid)); } else { echo CHtml::link("Reply", array('/upgrade/')); } ?> | <a href="javascript:history.back();">Back</a> </div> </div> </div> </div> <div class="clear"></div> </div> </div>
public function actionFree() { $loginUserId = Yii::app()->user->getId(); $loginUserMail = Profile::model()->findByPk($loginUserId)->EmailAddress; $model = Memberships::model()->findByAttributes(array("Price" => 0)); $months = $model->Duration; $membserShipId = $model->Objid; $details = MembershipUsers::model()->findByAttributes(array("UserId" => $loginUserId, "MembershipId" => $membserShipId)); if (empty($details)) { $freeMember = new MembershipUsers(); $freeMember->UserId = $loginUserId; $freeMember->MembershipId = $membserShipId; $freeMember->TransactionId = "0"; $freeMember->MembershipStart = date('Y-m-d H:i:s'); $freeMember->MembershipEnd = date('Y-m-d H:i:s', strtotime("+ " . $months . " month")); if ($freeMember->save()) { $info = MembershipUsers::model()->findByPk($freeMember->Objid); $message = Messages::model()->mailHeader(); $message .= '<p>Free Membership successfully activated.</p>'; $message .= '<p><u>Membership type</u>: ' . $info->membership->MemberShipType . ' </p>'; $message .= '<p>' . $info->membership->Description . '</p>'; $message .= '<p><u>Membership Expired</u>: ' . $info->MembershipEnd . '</p>'; $message .= Messages::model()->mailFooter(); Messages::model()->sendMail('E Heart Match', 'Membership Details', Yii::app()->params['adminEmail'], $loginUserMail, $message); $this->render('success', array('details' => $info)); } } else { throw new CHttpException(404, 'Page not found'); } }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $folder = Yii::getPathOfAlias('webroot') . '/../images/users/'; UserText::model()->deleteAllByAttributes(array("UserId" => $id)); UserOptions::model()->deleteAllByAttributes(array("UserId" => $id)); MembershipUsers::model()->deleteAllByAttributes(array("UserId" => $id)); Messages::model()->deleteAllByAttributes(array("SenderId" => $id)); Messages::model()->deleteAllByAttributes(array("ReceiverId" => $id)); if (UserImages::model()->findAllByAttributes(array("UserId" => $id))) { $imgList = UserImages::model()->findAllByAttributes(array("UserId" => $id)); foreach ($imgList as $list) { unlink($folder . $list->ImagePath); } } UserImages::model()->deleteAllByAttributes(array("UserId" => $id)); $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } }
public function actionCheckMessage() { $data = array(); $date = date('Y-m-d H:i:s', strtotime('-5 seconds')); $receiverId = Yii::app()->user->getId(); $criteria = new CDbCriteria(); $criteria->condition = "ReceiverId = {$receiverId} AND Date > '" . $date . "'"; $models = ChatMessage::model()->findAll($criteria); if (!empty($models)) { foreach ($models as $model) { if (MembershipUsers::model()->isSubscribe($model->ReceiverId)) { $data[] = array('UserId' => $model->UserId, 'UserName' => Profile::model()->findByPk($model->UserId)->UserName, 'ReceiverId' => $model->ReceiverId); } } echo json_encode($data); } }
</div> </div> <div class="span6"> <div class="widget-box"> <div class="widget-title"><span class="icon"><i class="icon-user"></i></span> <h5>Recent Membership Users</h5> </div> <div class="widget-content nopadding"> <ul class="recent-posts"> <?php $criteria = new CDbCriteria(); $criteria->distinct = true; $criteria->select = "UserId"; $criteria->order = "MembershipStart DESC"; $criteria->limit = 4; $recentMember = MembershipUsers::model()->findAll($criteria); foreach ($recentMember as $mlist) { ?> <li> <div class="user-thumb"> <?php if (UserImages::model()->findByAttributes(array('UserId' => $mlist->user->Objid, 'MainImage' => 1))) { $userImage = UserImages::model()->findByAttributes(array('UserId' => $mlist->user->Objid, 'MainImage' => 1)); ?> <img src="<?php echo Yii::app()->params['siteUrl']; ?> /timthumb.php?src=<?php echo Yii::app()->params['siteUrl']; ?> /images/users/<?php
public function getPremiumUsers() { $criteria = new CDbCriteria(); $criteria->condition = "TransactionId != 0"; $criteria->distinct = true; $criteria->select = "UserId"; $model = MembershipUsers::model()->findAll($criteria); return count($model); }