/** * Lists all Organization models. * @return mixed */ public function actionIndex() { $model = new Organization(); // This is used to search/filter organizations $dataProvider = null; if (isset($_GET['user_id'])) { $user_id = $_GET['user_id']; if ($user_id !== null) { $query = new Query(); $query->from(Organization::tableName()); $query->where(['user_id' => $user_id]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); } } else { if (isset($_GET['search_keyword']) && $_GET['search_keyword'] !== null && strlen($_GET['search_keyword']) > 0 || isset($_GET['search_location']) && $_GET['search_location'] !== null && strlen($_GET['search_location']) > 0) { $search_keyword = $_GET['search_keyword']; if ($search_keyword !== null) { $query = new Query(); $query->from(Organization::tableName()); $query->where(['name' => $search_keyword]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); } } else { $dataProvider = new ActiveDataProvider(['query' => Organization::find(), 'pagination' => ['pageSize' => 5]]); } } if ($model->load(Yii::$app->request->post())) { $query = new Query(); $query->from(Organization::tableName()); if (!is_null($model->org_type) && is_array($model->org_type)) { $query->where(['org_type' => array_map('intval', $model->org_type)]); } if (!is_null($model->work_domain) && is_array($model->work_domain)) { $query->andWhere(['work_domain' => array_map('intval', $model->work_domain)]); } if (isset($_GET['user_id'])) { $query->andWhere(['user_id' => $_GET['user_id']]); } if (isset($_GET['search_keyword']) && $_GET['search_keyword'] !== null && strlen($_GET['search_keyword']) > 0 || isset($_GET['search_location']) && $_GET['search_location'] !== null && strlen($_GET['search_location']) > 0) { $query->andWhere(['name' => $_GET['search_keyword']]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); } return $this->render('index', ['model' => $model, 'dataProvider' => $dataProvider]); }
/** * Creates a new Organization model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Organization(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Organization model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $chkOrg = Organization::find()->all(); if (!empty($chkOrg)) { throw new NotFoundHttpException('The requested page does not exist.'); } $model = new Organization(); if (isset($_POST['Organization']) && $model->load(Yii::$app->request->post())) { $model->attributes = $_POST['Organization']; $model->org_email = strtolower($_POST['Organization']['org_email']); $model->created_by = 1; $model->created_at = new \yii\db\Expression('NOW()'); ob_start(); if (!empty($_FILES['Organization']['tmp_name']['org_logo'])) { $file = UploadedFile::getInstance($model, 'org_logo'); $model->org_logo_type = $file->type; $fp = fopen($file->tempName, 'r'); $content = fread($fp, filesize($file->tempName)); fclose($fp); if ($model->org_logo_type == "image/png") { $src_img = imagecreatefrompng($file->tempName); $dst_img = imagecreatetruecolor(90, 70); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, 90, 70, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 90, 70, imagesx($src_img), imagesy($src_img)); imagepng($dst_img); ob_start(); imagepng($dst_img); $image_string = ob_get_contents(); ob_end_flush(); } if ($model->org_logo_type == "image/jpg" || $model->org_logo_type == "image/jpeg") { $src_img = imagecreatefromjpeg($file->tempName); $dst_img = imagecreatetruecolor(90, 70); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, 90, 70, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 90, 70, imagesx($src_img), imagesy($src_img)); imagejpeg($dst_img); ob_start(); imagepng($dst_img); $image_string = ob_get_contents(); ob_end_flush(); } if ($model->org_logo_type == "image/gif") { $src_img = imagecreatefromgif($file->tempName); $dst_img = imagecreatetruecolor(90, 70); imagealphablending($dst_img, false); imagesavealpha($dst_img, true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, 90, 70, $transparent); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 90, 70, imagesx($src_img), imagesy($src_img)); imagepng($dst_img); ob_start(); imagecreatefromgif($dst_img); $image_string = ob_get_contents(); ob_end_flush(); } $model->org_logo = $image_string; } if ($model->save()) { return $this->redirect(['view', 'id' => $model->org_id]); } } return $this->render('create', ['model' => $model]); }