public function getUserOptionValue($userId, $attributeId) { if (UserOptions::model()->findByAttributes(array("UserId" => $userId, "AttributeId" => $attributeId))) { $data = UserOptions::model()->findByAttributes(array("UserId" => $userId, "AttributeId" => $attributeId)); return $data->AttributeValueId; } else { return ''; } }
public function actionIndex() { $id = Yii::app()->user->getId(); $model = $this->loadModel($id); if (UserOptions::model()->findByAttributes(array('UserId' => $id))) { $options_list = UserOptions::model()->findByAttributes(array('UserId' => $id)); } else { $options_list = new UserOptions(); } $profileImage = UserImages::model()->findByAttributes(array("UserId" => $id, "MainImage" => 1)); $UserOption = UserOptions::model()->findByAttributes(array('UserId' => $id)); $birthday = explode('-', $model->DateOfBirth); $model->year = $birthday[0]; $model->month = $birthday[1]; $model->day = $birthday[2]; if (isset($_POST['Profile'])) { $model->attributes = $_POST['Profile']; $model->year = $_POST['Profile']['year']; $model->month = $_POST['Profile']['month']; $model->day = $_POST['Profile']['day']; $dob = (string) $model->year . "-" . $model->month . "-" . $model->day; $timestamp = strtotime($dob); $model->DateOfBirth = date('Y-m-d', $timestamp); $model->save(false); } if (isset($_POST['UserOptions'])) { $data = array(); $data['basic'] = $_POST['UserOptions']['AttributeValueId']; $jsonData = CJSON::encode($data); $options_list = UserOptions::model()->findByAttributes(array('UserId' => $id)); if ($options_list) { $options_list->UserId = $id; $options_list->AttributeValueId = $jsonData; } else { $options_list = new UserOptions(); $options_list->UserId = $id; $options_list->AttributeValueId = $jsonData; } $options_list->save(false); } $this->render('index', array('model' => $model, 'options_list' => $options_list, 'profileImage' => $profileImage)); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { if (Yii::app()->user->isGuest) { $this->layout = 'login'; $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $date = date('Y-m-d H:i:s'); $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $loginUserID = Yii::app()->user->getId(); Users::model()->updateByPk($loginUserID, array('LoginStatus' => 1, 'LastLoginDate' => $date)); /* $this->redirect(array('site/index')); */ $this->redirect(Yii::app()->user->returnUrl); } } // display the login form $this->render('login', array('model' => $model)); } else { $pageCount = 20; $loginUserId = Yii::app()->user->getId(); $favourites = Favourites::model()->findByAttributes(array('UserId' => $loginUserId)); if (!empty($favourites)) { $favourites = explode(',', $favourites->FavouriteIds); } $criteria = new CDbCriteria(); $condition = "Status=1 AND SearchStatus=1 AND Objid <> {$loginUserId}"; if (isset($_GET['searchAttList'])) { $criteria->condition = "UserId !='" . $loginUserId . "'"; $options_list = UserOptions::model()->findAll($criteria); $key = array(); $i = 0; $hasAttrUser = array(); if ($_GET['searchAttList'] !== '') { $values = explode(',', $_GET['searchAttList']); foreach ($options_list as $option) { $AttrOption = CJSON::decode($option->AttributeValueId); foreach ($AttrOption['basic'] as $attr) { if (is_array($attr)) { foreach ($values as $value) { array_push($key, in_array($value, $attr)); } } } foreach ($values as $value) { array_push($key, in_array($value, $AttrOption['basic'])); } $key = array_filter($key); if (count($key) == count($values)) { $hasAttrUser[$i++] = $option->UserId; } } $condition .= !empty($hasAttrUser) ? " AND Objid IN(" . implode(',', $hasAttrUser) . ")" : ' AND Objid = 0'; } } if (isset($_GET['MinAge']) && isset($_GET['MaxAge'])) { $minAge = $_GET['MinAge']; $maxAge = $_GET['MaxAge']; $minAge1 = $_GET['MinAge'] - 1; $maxAge1 = $_GET['MaxAge'] + 1; $toDate = date('Y-m-d', strtotime('-' . $minAge1 . ' years')); $fromDate = date('Y-m-d', strtotime('-' . $maxAge1 . ' years')); $condition .= " AND DateOfBirth BETWEEN '" . $fromDate . "' AND '" . $toDate . "'"; } if (isset($_GET['Gender'])) { $condition .= $_GET['Gender'] !== '' ? " AND Gender=" . $_GET['Gender'] : " AND Gender=0 OR Gender=1"; } $criteria->addCondition($condition); if (isset($_GET['type'])) { $criteria->compare("LoginStatus", 1, true); } $model = Profile::model()->findAll($criteria); $count = Profile::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = $pageCount; $pages->applyLimit($criteria); $this->render('list', array('models' => $model, 'pages' => $pages, 'pageCount' => $pageCount, 'favourites' => $favourites)); } }
/** * 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) { UserOptions::model()->deleteAllByAttributes(array('AttributeId' => $id)); UserText::model()->deleteAllByAttributes(array('AttributeId' => $id)); AttributeValues::model()->deleteAllByAttributes(array('AttributeId' => $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')); } }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { if (Yii::app()->user->isGuest) { $this->layout = 'login'; $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { // echo "tetste"; exit(); $date = date('Y-m-d H:i:s'); // print_r($_POST['LoginForm']);exit(); $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $loginUserID = Yii::app()->user->getId(); Users::model()->updateByPk($loginUserID, array('LoginStatus' => 1, 'LastLoginDate' => $date)); /* $this->redirect(array('site/index')); */ $this->redirect(Yii::app()->user->returnUrl); } } // display the login form $this->render('login', array('model' => $model)); } else { $loginUserId = Yii::app()->user->getId(); $message = new Messages(); $userList = array(); $idLilst = array(); $location = ''; $genVal = ''; $minAge = 18; $maxAge = 30; $pageCount = 20; $criteria = new CDbCriteria(); $condition = "Status=1 AND SearchStatus=1 AND Objid <> {$loginUserId}"; if (isset($_POST['Messages'])) { $message->attributes = $_POST['Messages']; $message->SenderId = $loginUserId; $message->Date = date('Y-m-d H:i:s'); if ($message->save()) { $this->redirect(array('site/index')); } } if (isset($_GET['Find'])) { $minAge = $_GET['MinAge']; $maxAge = $_GET['MaxAge']; $minAge1 = $_GET['MinAge'] - 1; $maxAge1 = $_GET['MaxAge'] + 1; $toDate = date('Y-m-d', strtotime('-' . $minAge1 . ' years')); $fromDate = date('Y-m-d', strtotime('-' . $maxAge1 . ' years')); $condition .= " AND DateOfBirth BETWEEN '" . $fromDate . "' AND '" . $toDate . "'"; if (isset($_GET['searchAttList'])) { $idLilst = $_GET['searchAttList']; $attributes = implode(',', $idLilst); $criteria2 = new CDbCriteria(); $criteria2->condition = "AttributeValueId IN(" . $attributes . ") GROUP BY AttributeId"; $total = UserOptions::model()->findAll($criteria2); $count = count($total); $count = $count - 1; $criteria1 = new CDbCriteria(array('having' => 'COUNT(ObjId) > ' . $count)); $criteria1->condition = "AttributeValueId IN(" . $attributes . ")"; $criteria1->group = "UserId"; $userData = UserOptions::model()->findAll($criteria1); if ($userData) { foreach ($userData as $data) { $userList[] = $data->UserId; } $condition .= " AND Objid IN (" . implode(',', $userList) . ")"; } else { $condition .= " AND Objid IN (0)"; } } if (isset($_GET['Gender']) && $_GET['Gender']) { $genVal = $_GET['Gender']; if ($_GET['Gender'] == 1) { $condition .= " AND Gender=0"; } else { if ($_GET['Gender'] == 2) { $condition .= " AND Gender=1"; } } } if (isset($_GET['Location']) && $_GET['Location']) { $location = $_GET['Location']; $condition .= " AND CityOrPostal LIKE '%" . $location . "%'"; } if (isset($_GET['postsPerPage']) && $_GET['postsPerPage']) { $pageCount = $_GET['postsPerPage']; } } if (isset($_GET['type']) && $_GET['type'] == 'online') { $expDate = date('Y-m-d H:i:s', strtotime('-2 minutes')); $condition .= " AND LoginStatus=1 AND LastActivity >'" . $expDate . "'"; } if (isset($_GET['type']) && $_GET['type'] == 'new') { $now = date('Y-m-d H:i:s', strtotime('last month')); $condition .= ' AND CreatedDate > "' . $now . '"'; } $criteria->condition = $condition; $count = Profile::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = $pageCount; $pages->applyLimit($criteria); $model = Profile::model()->findAll($criteria); $this->render('list', array('models' => $model, 'location' => $location, 'idLilst' => $idLilst, 'gender' => $genVal, 'minAge' => $minAge, 'maxAge' => $maxAge, 'pages' => $pages, 'pageCount' => $pageCount, 'message' => $message)); } }
/** * 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 actionIndex() { if (Yii::app()->user->isGuest) { $this->redirect(Yii::app()->getBaseUrl(true)); } $userList = array(); $idLilst = array(); $genVal = ''; $minAge = 18; $maxAge = 30; $pageCount = 10; $criteria = new CDbCriteria(); $condition = "Status=1 AND SearchStatus=1"; if (isset($_GET['Browse'])) { $minAge = $_GET['MinAge'] - 1; $maxAge = $_GET['MaxAge'] + 1; $toDate = date('Y-m-d', strtotime('-' . $minAge . ' years')); $fromDate = date('Y-m-d', strtotime('-' . $maxAge . ' years')); $condition .= " AND DateOfBirth BETWEEN '" . $fromDate . "' AND '" . $toDate . "'"; if (isset($_GET['searchAttList'])) { $idLilst = $_GET['searchAttList']; $attributes = implode(',', $idLilst); $criteria2 = new CDbCriteria(); $criteria2->condition = "AttributeValueId IN(" . $attributes . ") GROUP BY AttributeId"; $total = UserOptions::model()->findAll($criteria2); $count = count($total); $count = $count - 1; $criteria1 = new CDbCriteria(array('having' => 'COUNT(ObjId) > ' . $count)); $criteria1->condition = "AttributeValueId IN(" . $attributes . ")"; $criteria1->group = "UserId"; $userData = UserOptions::model()->findAll($criteria1); if ($userData) { foreach ($userData as $data) { $userList[] = $data->UserId; } $condition .= " AND Objid IN (" . implode(',', $userList) . ")"; } else { $condition .= " AND Objid IN (0)"; } } if (isset($_GET['Gender']) && $_GET['Gender']) { $genVal = $_GET['Gender']; if ($_GET['Gender'] == 1) { $condition .= " AND Gender=0"; } else { if ($_GET['Gender'] == 2) { $condition .= " AND Gender=1"; } } } if (isset($_GET['postsPerPage']) && $_GET['postsPerPage']) { $pageCount = $_GET['postsPerPage']; } } $criteria->condition = $condition; $count = Profile::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = $pageCount; $pages->applyLimit($criteria); $model = Profile::model()->findAll($criteria); $this->render('index', array('models' => $model, 'idLilst' => $idLilst, 'gender' => $genVal, 'minAge' => $minAge, 'maxAge' => $maxAge, 'pages' => $pages, 'pageCount' => $pageCount)); }
foreach ($attributes as $att_list) { ?> <div class="row" id="userOptions"> <label><?php echo $att_list->Name; ?> </label> <?php if ($att_list->Type == 'dropdown') { $selectValue = UserOptions::model()->getUserOptionValue($model->Objid, $att_list->Objid); $list = CHtml::listData(AttributeValues::model()->findAllByAttributes(array('AttributeId' => $att_list->Objid)), 'Objid', 'AttributeValue'); echo $form->dropDownList($options_list, 'AttributeValueId[' . $att_list->Objid . ']', $list, array('empty' => '--Select a value--', 'options' => array($selectValue => array('selected' => true)))); } else { if ($att_list->Type == 'checkbox') { $list = CHtml::listData(AttributeValues::model()->findAllByAttributes(array('AttributeId' => $att_list->Objid)), 'Objid', 'AttributeValue'); $check_options = CHtml::listData(UserOptions::model()->findAllByAttributes(array('UserId' => $model->Objid, 'AttributeId' => $att_list->Objid)), 'AttributeValueId', 'AttributeValueId'); $options_list->AttributeValueId = array($att_list->Objid => $check_options); echo $form->checkBoxList($options_list, 'AttributeValueId[' . $att_list->Objid . ']', $list); } } ?> </div> <?php if ($temp % $i == 0) { echo '</div><div class="twoColumns">'; } $temp++; } ?> </div> <div class="clear"></div>
?> "><th><?php echo $attlist->Name; ?> </th><td> <?php if ($attlist->Type == 'dropdown') { $attValId = UserOptions::model()->findByAttributes(array('UserId' => $model->Objid, 'AttributeId' => $attlist->Objid)); if ($attValId) { echo $attValId->attributeName->AttributeValue; } else { echo '----'; } } else { if ($attlist->Type == 'checkbox') { $checkValId = UserOptions::model()->findAllByAttributes(array('UserId' => $model->Objid, 'AttributeId' => $attlist->Objid)); if ($checkValId) { foreach ($checkValId as $cid) { echo $cid->attributeName->AttributeValue . ', '; } } else { echo '----'; } } else { $text = UserText::model()->findByAttributes(array("UserId" => $model->Objid, "AttributeId" => $attlist->Objid)); if ($text) { echo substr($text->Value, 0, 70) . '..'; } else { echo '---'; } }