/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Blockeditem(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Blockeditem'])) { $model->commodity_id = $_POST['Blockeditem']['commodity_id']; $model->item_id = $_POST['Blockeditem']['item_id']; $model->blocked_by = $_POST['Blockeditem']['blocked_by']; $model->blocked_on = $_POST['Blockeditem']['blocked_on']; $model->blocked_from = $_POST['Blockeditem']['blocked_from']; $model->blocked_to = $_POST['Blockeditem']['blocked_to']; $commo = Commodity::model()->findByPk($model->commodity_id); $item = $commo['name']::model()->findByPk($model->item_id); $model->item_name = $item['name']; //$model->attributes=$_POST['Blockeditem']; if ($model->validate()) { /** Single Line **/ if (isset($_POST['Blockeditem']['block_group'])) { $grps = $_POST['Blockeditem']['block_group']; $model->flag = 'G'; foreach ($grps as $grp) { $singlemodel = new Blockeditem(); $singlemodel->attributes = $model->attributes; $singlemodel->blocked_for = $grp; $commo = Commodity::model()->findByPk($model->commodity_id); $item = $commo['name']::model()->findByPk($model->item_id); $singlemodel->item_name = $item['name']; $singlemodel->save(); } } if (isset($_POST['Blockeditem']['block_user'])) { //echo "<script>djsahdja</script>";die; $users = $_POST['Blockeditem']['block_user']; $model->flag = 'U'; foreach ($users as $user) { $singlemodel = new Blockeditem(); $singlemodel->attributes = $model->attributes; $singlemodel->blocked_for = $user; $commo = Commodity::model()->findByPk($model->commodity_id); $item = $commo['name']::model()->findByPk($model->item_id); $singlemodel->item_name = $item['name']; $singlemodel->save(); } } if (!isset($_POST['Blockeditem']['block_group']) && !isset($_POST['Blockeditem']['block_user'])) { $model->flag = 'A'; $model->save(); } $commo = Commodity::model()->findByPk($model->commodity_id); $commodityName = $commo['name']; $cons = $commodityName::model()->findByPk($model->item_id); $cons->status_id = 4; $cons->update(); Yii::app()->request->redirect("http://localhost/asset_management/index.php/{$commodityName}/admin"); } } $this->render('create', array('model' => $model)); }