public function actionAdmin() { $this->layout = Yum::module()->adminLayout; $model = new YumMembership('search'); $model->unsetAttributes(); if (isset($_GET['YumMembership'])) { $model->attributes = $_GET['YumMembership']; } $this->render('admin', array('model' => $model)); }
public function activeMembership() { return YumMembership::model()->lastFirst()->find('user_id = :user_id and membership_id = :role_id', array(':user_id' => Yii::app()->user->id, ':role_id' => $this->id)); }
public static function syncMemberships () { if(!Yii::app()->user->isGuest) { foreach(YumMembership::model()->findAll( 'user_id = :uid and end_date != 0 and end_date < :date', array( ':uid' => Yii::app()->user->id, ':date' => time())) as $membership) { if($membership->subscribed != -1) { // renew membership $new_membership = new Membership; $new_membership->user_id = Yii::app()->user->id; $new_membership->payment_id = $membership->payment_id; $new_membership->payment_date = time(); // the user has choosen to up/downgrade to another membership if($membership->subscribed > 0) $new_membership->membership_id = $membership->subscribed; else $new_membership->membership_id = $membership->membership_id; $role = YumRole::model()->findByPk($new_membership->membership_id); $new_membership->end_date = time() + ($role->duration * 86400); $new_membership->save(); } $membership->end_date = 0; $membership->save(); } } }