コード例 #1
0
 public function createOccupation($name)
 {
     $occ = new Occupation();
     $occ->setName($name);
     $occ->save();
     return $occ;
 }
コード例 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Occupation();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Occupation'])) {
         $model->attributes = $_POST['Occupation'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
コード例 #3
0
ファイル: admin.php プロジェクト: Robinwist/UXDTalentenTest
 $app->map('/new', function () use($app, $data) {
     if ($app->request->isGet()) {
         $data['education_levels'] = EducationLevel::NoSchoolAdvice()->get();
         $data['talents'] = Talent::all();
     } else {
         if ($app->request->isPost()) {
             $edu_level = EducationLevel::find($app->request->post('educationlevel'));
             $talent = Talent::find($app->request->post('talent'));
             parse_str(parse_url($app->request->post('yt-video'), PHP_URL_QUERY), $urlvars);
             $job = new Occupation();
             $job->name = $app->request->post('title');
             $job->description = $app->request->post('description');
             $job->youtube = $urlvars['v'];
             $job->educationLevel()->associate($edu_level);
             $job->talent()->associate($talent);
             $job->save();
             $data['new_occupation'] = $job;
         }
     }
     $app->render('occupations/new.html', $data);
 })->via('GET', 'POST')->name('occupations_new');
 $app->map('/edit/:id', function ($id) use($app, $data) {
     $data['request_method'] = $app->request->getMethod();
     if ($app->request->isGet()) {
         $data['occupation'] = Occupation::with('talent', 'educationLevel')->find($id);
         $data['education_levels'] = EducationLevel::NoSchoolAdvice()->get();
         $data['talents'] = Talent::all();
     } else {
         if ($app->request->isPost()) {
             $edu_level = EducationLevel::find($app->request->post('educationlevel'));
             $talent = Talent::find($app->request->post('talent'));
コード例 #4
0
 public function actionUpload()
 {
     parent::actionUpload();
     $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
     // folder for uploaded files
     $allowedExtensions = array("csv");
     $sizeLimit = (int) Yii::app()->params['sizeLimit'];
     // maximum file size in bytes
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder, true);
     $row = 0;
     if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             if ($row > 0) {
                 $model = Occupation::model()->findByPk((int) $data[0]);
                 if ($model === null) {
                     $model = new Occupation();
                 }
                 $model->occupationid = (int) $data[0];
                 $model->occupationname = $data[1];
                 $model->recordstatus = (int) $data[2];
                 try {
                     if (!$model->save()) {
                         $errormessage = $model->getErrors();
                         if (Yii::app()->request->isAjaxRequest) {
                             echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
                         }
                     }
                 } catch (Exception $e) {
                     $errormessage = $e->getMessage();
                     if (Yii::app()->request->isAjaxRequest) {
                         echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
                     }
                 }
             }
             $row++;
         }
         fclose($handle);
     }
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
コード例 #5
0
 public function actionCreate_occ()
 {
     $model = new Occupation();
     if (isset($_POST['Occupation'])) {
         $cat = Occupation::model()->countByAttributes(array('cat_id' => $_POST['Occupation']['cat_id'], 'name' => $_POST['Occupation']['name']));
         if ($cat <= 0) {
             $templ = Occupation::model()->findByAttributes(array('cat_id' => $_POST['Occupation']['cat_id']));
             $model->name = $_POST['Occupation']['name'];
             $model->cat_id = $_POST['Occupation']['cat_id'];
             $model->templ = $templ->templ;
             if ($model->save()) {
                 Yii::app()->user->setFlash('create_occ', '1');
                 //$this->redirect(array('/register/step3/uid/'.$_POST['uid'],'add'=>1));
                 $this->actionAdd_occ($model->id, $_POST['uid']);
             } else {
                 print_r($model->getErrors());
             }
         } else {
             Yii::app()->user->setFlash('add_occ', '1');
             //$this->redirect(array('/register/step3/uid/'.$_POST['uid']));
             $this->actionAdd_occ($cat->id, $_POST['uid']);
         }
     }
 }