public function actionCreate($type)
 {
     $incoming = new Incoming();
     $contact = new Contact();
     if ($incoming->load(Yii::$app->request->post()) && $contact->load(Yii::$app->request->post())) {
         $contact->type = Contact::PERSON;
         $isValid = $incoming->validate();
         $isValid = $contact->validate() && $isValid;
         if ($isValid) {
             $incoming->save(false);
             $contact->save(false);
             $from = new Endpoint();
             $from->type = Endpoint::FROM;
             $from->doc_id = $incoming->id;
             $from->contact_id = $contact->id;
             $from->save(false);
             return $this->redirect(['index']);
         } else {
             Yii::trace($contact->errors);
         }
     }
     $incoming->type = Incoming::PERSON;
     $incoming->docdate = date('Y-m-d');
     return $this->render('create', ['incoming' => $incoming, 'contact' => $contact]);
 }
 /**
  * Creates a new Contact model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Contact();
     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 Contact model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Contact();
     if (!\Yii::$app->user->can('createPost', ['post' => $model])) {
         throw new NotFoundHttpException('You havent access to create item.');
     }
     $model->setScenario(Contact::SCENARIO_ADD_CONTACT);
     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 Contact model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Contact();
     $infoCompany = Infocompany::findOne(['id' => 1]);
     if ($model->load(Yii::$app->request->post())) {
         $model->fullname = $_POST['genderName'] . " " . $model->fullname;
         if ($model->save()) {
             //return $this->redirect(['create', 'id' => $model->id]);
             Yii::$app->session->setFlash('contactFormSubmitted');
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['model' => $model, 'infoCompany' => $infoCompany]);
     }
 }
Example #5
0
 /**
  * Creates a new Contact model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     // Define that response will be on json format
     $model = new Contact();
     $model->scenario = Contact::SCENARIO_CREATE;
     // Scenarios allow us to configure which attributes are safe to massive assignment
     $data = Json::decode(Yii::$app->request->post('model'));
     // First of all we decode json data to data in Yii conventions
     if ($model->load($data) && $model->save()) {
         return ['statusCode' => 200, 'model' => $model];
     } else {
         // Return error 400 if no data or not created
         return new HttpException(400);
     }
 }
Example #6
0
 public function actionWorkers($id)
 {
     $dept = $this->loadModel($id);
     $worker = new Contact(['scenario' => Contact::SCENARIO_NEW_WORKER]);
     if ($worker->load(Yii::$app->request->post())) {
         $worker->type = Contact::COWORKER;
         $worker->dept = $dept->id;
         if ($worker->save()) {
             if ($worker->isChief) {
                 $dept->chief_id = $worker->id;
                 $dept->save();
             }
             $worker = new Contact(['scenario' => Contact::SCENARIO_NEW_WORKER]);
         }
     }
     return $this->render('workers', ['dept' => $dept, 'worker' => $worker, 'workersDataProvider' => $this->workersDataProvider($dept->id)]);
 }
Example #7
0
 public function actionIndex()
 {
     $model = new Contact();
     $msgs = Contact::find()->orderBy('id DESC')->limit('50')->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->admin_id = Yii::$app->user->id;
         $model->time = time();
         $model->save();
         $this->redirect('contact');
     }
     // проверка на время публикации (1 час)
     $openContactForm = true;
     $restTime = 0;
     foreach ($msgs as $one) {
         if ($one['admin_id'] == Yii::$app->user->id && $one['time'] >= time() - 60 * 60) {
             $openContactForm = false;
             $restTime = ceil(($one['time'] - (time() - 60 * 60)) / 60);
             break;
         }
     }
     return $this->render('index', ['model' => $model, 'msgs' => $msgs, 'openContactForm' => $openContactForm, 'restTime' => $restTime]);
 }
 /**
  * Add a contact to an existing Supplier.
  * @param integer $id
  * @return mixed
  */
 public function actionAddContact($id)
 {
     $supplier = $this->findModel($id);
     $model = new Contact();
     $model->supplier_id = $supplier->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $supplier->id]);
     } else {
         return $this->render('add-contact', ['model' => $model, 'supplier' => $supplier]);
     }
 }