public function actionView($username) { $this->layout = "column1"; /*find the user with username provided*/ $assignedListIdCollection = []; $unAssignedListId = []; $userModel = User::model()->findByAttributes(array('username' => $username, 'superuser' => 0)); $unAssignedListIdObjCollection = ListId::getUnassignedListId($userModel->id); foreach ($unAssignedListIdObjCollection as $key => $value) { $unAssignedListId[] = $value->list_id_value; } if (!$userModel) { throw new CHttpException(404, "Sorry Username {$username} doesn't exists in the database"); } $assignedAllowedListId = AssignedAllowedListId::getAllAssignedList($userModel->id); foreach ($assignedAllowedListId as $key => $currentAssignedLIstId) { $assignedListIdCollection[] = $currentAssignedLIstId->list; } //using user id find the assigned $this->render('view', array("model" => $userModel, "assignedListIdCollection" => $assignedListIdCollection, "user_id" => $userModel->id, "username" => $_GET['username'], "unassigned_list_ids" => $unAssignedListId)); }
/** * Returns list of unassigned listid * @param integer $user_id The ID of user * @return array The unassigned listid */ public static function getUnassignedListId($user_id) { /*get all list id of current user */ $assignedListId = AssignedAllowedListId::getAllAssignedList($user_id); $excludedCollection = []; foreach ($assignedListId as $key => $value) { /*compose list id to be exluded*/ $excludedCollection[] = $value->list->list_id_value; } $criteria = new CDbCriteria(); /*get all records not in excluded collection */ $criteria->addNotInCondition("list_id_value", $excludedCollection); $unassignedListId = ListId::model()->findAll($criteria); return $unassignedListId; /*return collection*/ }
$baseUrl = Yii::app()->theme->baseUrl; $gridDataProvider->pagination = false; ?> <div class="row-fluid"> <div class="offset1 span10"> <?php $this->beginWidget('zii.widgets.CPortlet', array('title' => '<span class="icon-search"></span>Search', 'titleCssClass' => '')); ?> <div class="span9"> <?php echo CHtml::beginForm(array(''), 'get', array('class' => 'form')); ?> <?php //autocomplete for listid available to current user $listIdModels = AssignedAllowedListId::getAllAssignedList(Yii::app()->user->id); /*collection list id*/ $finalCollection = []; foreach ($listIdModels as $key => $value) { $finalCollection[] = $value->list->list_id_value; } $finalCollection = array_combine($finalCollection, $finalCollection); echo CHtml::dropDownList('searchListId', 'something', $finalCollection, array('style' => "margin: 20px", 'prompt' => "Search list")); ?> <?php echo CHtml::button('Submit', array('type' => 'submit', 'class' => 'btn btn-primary')); ?> <?php echo CHtml::endForm(); ?> </div>