Наследование: extends Illuminate\Database\Eloquent\Model
 public function store(CreateCompanyRequest $request)
 {
     $company = Company::create($request->all());
     if (!Input::get('person_id')) {
         $person = new Person();
         $person->first_name = Input::get('person_fn');
         $person->last_name = Input::get('person_ln');
         $person->save();
     }
     $contact = new CompanyPerson();
     $contact->company_id = $company->id;
     $contact->person_id = Input::get('person_id') ? Input::get('person_id') : $person->id;
     $contact->title_id = Input::get('title_id');
     $contact->department_id = Input::get('department_id');
     $contact->phone = Input::get('phone');
     $contact->extension = Input::get('extension');
     $contact->cellphone = Input::get('cellphone');
     $contact->email = Input::get('email');
     $contact->group_type_id = Input::get('company_id') == ELETTRIC80_COMPANY_ID ? EMPLOYEE_GROUP_TYPE_ID : CUSTOMER_GROUP_TYPE_ID;
     $contact->group_id = Input::get('company_id') == ELETTRIC80_COMPANY_ID ? DEFAULT_EMPLOYEE_GROUP_ID : DEFAULT_CUSTOMER_GROUP_ID;
     $contact->save();
     $company_main_contact = new CompanyMainContact();
     $company_main_contact->company_id = $company->id;
     $company_main_contact->main_contact_id = $contact->id;
     $company_main_contact->save();
     $company_account_manager = new CompanyAccountManager();
     $company_account_manager->company_id = $company->id;
     $company_account_manager->account_manager_id = Input::get('account_manager_id');
     $company_account_manager->save();
     return redirect()->route('companies.index')->with('successes', ['company created successfully']);
 }
Пример #2
0
 public function login(Request $request)
 {
     if (!empty($request->input('email'))) {
         $email = $request->input('email');
         $password = $request->input('password');
         $user_node = $this->users->getUser($email);
         // Create the Person model
         $user = new Person();
         $user->setNode($user_node);
         if (!empty($user_node)) {
             // Check password and verification
             if (!$user->verified) {
                 $message_bag = new MessageBag();
                 return redirect()->back()->with('errors', $message_bag->add('email', 'Dit emailadres is nog niet geverifieerd.'));
             } elseif (Hash::check($password, $user->password)) {
                 Auth::login($user);
                 // Register the event to Piwik
                 $this->registerPiwikEvent($user->email, 'Login');
                 return redirect($this->redirectTo);
             } else {
                 $message_bag = new MessageBag();
                 return redirect()->back()->with('errors', $message_bag->add('password', 'Het wachtwoord is incorrect.'));
             }
         } else {
             $message_bag = new MessageBag();
             return redirect()->back()->with('errors', $message_bag->add('email', 'Het emailadres werd niet gevonden.'));
         }
     } else {
         $message_bag = new MessageBag();
         return redirect()->back()->with('errors', $message_bag->add('email', 'Het emailadres werd niet gevonden.'));
     }
 }
 /**
  * Creates a new SocialServiceManager model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new SocialServiceManager();
     if ($model->load(Yii::$app->request->post())) {
         $person = new Person();
         $person->name = $model->name;
         $person->lastname = $model->last_name;
         $person->phone = $model->phone;
         $person->save(false);
         $user = new User();
         $user->username = $model->username;
         $user->password = $model->password;
         $user->email = $model->email;
         $user->person_id = $person->id;
         $user->scenario = 'register';
         if ($user->validate(['username', 'password'])) {
             $user->register();
             $model->user_id = $user->id;
             $model->save(false);
             //assign the role to the user
             $authManager = Yii::$app->getAuthManager();
             $socialServiceMRole = $authManager->getRole('socialServiceManager');
             $authManager->assign($socialServiceMRole, $user->id);
             //set the success message
             Yii::$app->getSession()->setFlash('success', 'Usuario creado con éxito');
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             $model->addErrors($user->errors);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #4
0
 /**
  * @return string|\yii\web\Response
  * @throws \yii\base\Exception
  */
 public function actionProjectManagerRequest()
 {
     $projectManager = new ProjectManager();
     $user = new User();
     $person = new Person();
     if (Yii::$app->request->post()) {
         $params = Yii::$app->request->post();
         $person->load($params);
         $user->load($params);
         $projectManager->load($params);
         if ($person->validate() && $user->validate() && $projectManager->validate()) {
             $user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
             $person->save(false);
             $user->person_id = $person->id;
             $user->register();
             $projectManager->user_id = $user->id;
             $projectManager->save();
             Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', 'Ocurrió un error al guardar. Vuelve a intentar');
         }
     }
     return $this->render('project-manager-request', ['projectManager' => $projectManager, 'user' => $user, 'person' => $person]);
 }
Пример #5
0
 public function create($inputs)
 {
     $person = new Person();
     $person->name = $inputs['name'];
     $person->surname = $inputs['surname'];
     $person->birthdate = $inputs['birthdate'];
     $person->save();
 }
Пример #6
0
 public function actionPerson()
 {
     $model = new Person();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     return $this->render('person', ['model' => $model]);
 }
Пример #7
0
 /**
  * Deny a user's registration
  *
  * @param  string $token
  * @return mixed
  */
 public function denyRegistration($token, AppMailer $mailer)
 {
     $user = $this->users->denyUser($token);
     if (!empty($user)) {
         $person = new Person();
         $person->setNode($user);
         // Send an email to the user that his email has been confirmed
         $mailer->sendRegistrationDenial($person);
     }
     return redirect('/persons');
 }
Пример #8
0
 public function fillForUser(Person $user)
 {
     $this->durations = [];
     $this->workTypes = [];
     $this->courses = [];
     foreach ($user->getWorkPreferences() as $workPref) {
         $this->workTypes[] = $workPref["id"];
     }
     foreach ($user->getPeriodPreferences() as $periodPref) {
         $this->durations[] = $periodPref["id"];
     }
     foreach ($user->getCoursePreferences() as $coursePref) {
         $this->courses[] = $coursePref["id"];
     }
 }
Пример #9
0
 private function removeAllUsers()
 {
     $count = 0;
     $userNodes = $this->users->getAll();
     $bar = $this->output->createProgressBar(count($userNodes));
     foreach ($userNodes as $userNode) {
         $person = new Person();
         $person->setNode($userNode);
         $person->delete();
         $bar->advance();
         $count++;
     }
     $this->info("");
     $this->info("Removed {$count} Person nodes.");
 }
Пример #10
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make(Request::all(), ['name' => 'required']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->errors());
     } else {
         try {
             $person = new Person();
             $person->name = Input::get('name');
             $person->last_name = Input::get('last_name');
             $person->document = Input::get('document') == '' ? null : Input::get('document');
             $person->identity = Input::get('identity') == '' ? null : Input::get('identity');
             $person->email = Input::get('email') == '' ? null : Input::get('email');
             $person->birthdate = Input::get('birthdate');
             $person->nationality = Input::get('nationality');
             $person->gender = Input::get('gender');
             $person->phone = Input::get('phone');
             $person->phone_cel = Input::get('phone_cel');
             $person->name = Input::get('name');
             $person->name = Input::get('name');
             $person->save();
             $member = new Member();
             $member->father = Input::get('father');
             $member->mother = Input::get('mother');
             $member->marital_status_id = Input::get('marital_status_id');
             $member->date_baptism = Input::get('date_baptism');
             $member->occupacion = Input::get('occupacion');
             $member->function_id = Input::get('function_id');
             $member->literacy_id = Input::get('literacy_id');
             $member->person_id = $person->id;
             $member->save();
             $address = new Address();
             $address->address = Input::get('address');
             $address->number = Input::get('number');
             $address->complement = Input::get('complement');
             $address->zip_code = Input::get('zip_code');
             $address->reference = Input::get('reference');
             $address->country = Input::get('country');
             $address->state = Input::get('state');
             $address->city = Input::get('city');
             $address->person_id = $person->id;
             $address->save();
             return redirect('members');
         } catch (\Illuminate\Database\QueryException $e) {
             print_r($e->errorInfo);
         }
     }
 }
Пример #11
0
 public function actionIncoming($id)
 {
     $user_id = NULL;
     $from = Yii::$app->request->post('From');
     $body = Yii::$app->request->post('Body');
     // Lookup user based on a few different methods
     // First, check with basic number with +1 removed
     $number = str_replace('+1', '', $from);
     $person = Person::find()->where(['phone' => $number])->one();
     // If no results, add hyphens
     if (!$person) {
         $formatted_number = preg_replace("/^(\\d{3})(\\d{3})(\\d{4})\$/", "\$1-\$2-\$3", $number);
         $person = Person::find()->where(['phone' => $formatted_number])->one();
     }
     if ($person) {
         $user_id = $person->id;
     }
     if ($from) {
         $message = new Message();
         $message->message = $body;
         $message->project_id = $id;
         $message->time = time();
         $message->user_id = $user_id;
         $message->status = 2;
         $message->type = 'text';
         $message->number = $from;
         $message->save();
     }
 }
 public function show($personId)
 {
     $person = Person::find($personId);
     $tree = $person->buildRelationsTree();
     JavaScript::put(['gentree' => $tree, 'currentElementId' => $personId]);
     return view('person.gentree.show');
 }
Пример #13
0
 public function all($params)
 {
     $params['order'] = isset($params['order']) ? $params['order'] : ['last_name|ASC', 'first_name|ASC'];
     $users = Person::select("people.*");
     $users = parent::execute($users, $params);
     return $users;
 }
Пример #14
0
 public function actionView()
 {
     $id = \Yii::$app->getRequest()->get()['match'];
     $vacancy = \Yii::$app->getRequest()->get()['vacancy'];
     $person = Person::findOne($id);
     return $this->render("view", ["person" => $person]);
 }
Пример #15
0
 public function listFiles($target, $target_action, $target_id)
 {
     $resource_type = 'App\\Models\\' . ucfirst(str_singular($target));
     $uploader_id = Auth::user()->active_contact->id;
     if ($target == "posts") {
         if ($target_action == "create") {
             $post = Post::where('author_id', $uploader_id)->where("status_id", "=", POST_DRAFT_STATUS_ID)->where("ticket_id", $target_id)->first();
         } elseif ($target_action == "edit") {
             $post = Post::where("id", $target_id)->first();
         }
         $id = isset($post->id) ? $post->id : null;
     } elseif ($target == "tickets") {
         if ($target_action == "create") {
             $ticket = Ticket::where('status_id', TICKET_DRAFT_STATUS_ID)->where('creator_id', $uploader_id)->first();
         } else {
             $ticket = Ticket::where("id", $target_id)->first();
         }
         $id = isset($ticket->id) ? $ticket->id : null;
     } elseif ($target == "people") {
         $target_id = is_null($target_id) ? Auth::user()->owner->id : $target_id;
         $person = Person::find($target_id);
         $id = $person->id;
     }
     $files = is_null($id) ? [] : File::where('resource_type', $resource_type)->where("resource_id", $id)->get();
     foreach ($files as $file) {
         $file->size = filesize(RESOURCES . DS . $file->file_path . DS . $file->file_name);
     }
     return $files;
 }
Пример #16
0
 /**
  * Creates a new File model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new File();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $dir = Yii::getAlias('@app/uf');
         foreach (UploadedFile::getInstances($model, 'files') as $file) {
             $file->saveAs($dir . '/' . $file->baseName . '.' . $file->extension);
             $new_file = new File();
             $new_file->setAttributes($model->attributes);
             $new_file->file_name = $file->baseName . '.' . $file->extension;
             $new_file->file_path = $dir . '/' . $file->baseName . '.' . $file->extension;
             $new_file->table_name = 'person';
             $new_file->class_name = Person::className();
             $new_file->save();
         }
         Yii::$app->getSession()->addFlash('success', "Запись \"{$model->id}\" успешно добавлена.");
         return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
             Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
         }
         if (!Yii::$app->request->isPost) {
             $model->setAttributes(Yii::$app->request->get());
         }
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #17
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = \app\models\Person::findByUsername($this->username);
     }
     return $this->_user;
 }
Пример #18
0
 /**
  * Finds the model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Person::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Страница не найдена');
     }
 }
Пример #19
0
 public function checkIfChildAndParentsAreInTheSameFamily(Person $father, Person $mother, Person $child)
 {
     $fathersFamily = Person::find($father->id)->family_id;
     $mothersFamily = Person::find($mother->id)->family_id;
     $childFamily = Person::find($child->id)->family_id;
     $families = array_unique([$fathersFamily, $mothersFamily, $childFamily]);
     $this->assertEquals(1, count($families));
 }
Пример #20
0
 /**
  * Used to save people to the db.
  * @param array $arrayOfPeople
  * @return Array of ids
  */
 public static function savePeople(array $arrayOfPeople)
 {
     $arrayOfPeopleIds = [];
     foreach ($arrayOfPeople as $people) {
         $person = Person::create($people);
         array_push($arrayOfPeopleIds, $person->id);
     }
     return $arrayOfPeopleIds;
 }
 public function actionPerson($query)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $fullName = new Expression('CONCAT(`person_last_name`, " ", `person_first_name`, " ", `person_second_name`)');
     $model = Person::find()->select(['full_name' => $fullName, 'person_id'])->where(['like', $fullName, $query])->orderBy('full_name')->asArray()->all();
     return array_map(function ($value) {
         return ['id' => $value['person_id'], 'value' => $value['full_name']];
     }, $model);
 }
Пример #22
0
 public function searchPerson($full_name)
 {
     $query = Person::find();
     $query->where('user.id <> ' . Yii::$app->user->getId());
     $query->joinWith('user');
     $query->limit(10);
     $query->andFilterWhere(['like', 'CONCAT(person.first_name, person.last_name)', $full_name]);
     $query->select(['user.id', 'CONCAT(person.first_name, " ", person.last_name) as full_name']);
     return $query->asArray()->all();
 }
Пример #23
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $name = Input::get('data');
     if ($name == 'lesson') {
         $data = Person::find($id)->lesson;
     } elseif ($name == 'seminar') {
         $data = Lessons::find($id)->seminar;
     }
     return response()->json($data);
 }
Пример #24
0
 public function actionDelete($id)
 {
     $person = Person::findOne($id);
     if ($person == null) {
         throw new \yii\web\NotFoundHttpException('This record does not exists.');
     }
     $person->delete();
     \Yii::$app->session->addFlash('success', 'Record deleted successfully.');
     header("Location: /persons/web");
     exit;
 }
Пример #25
0
 /**
  * Deliver a registration email to the admin
  *
  * @param Person $user
  * @return void
  */
 public function sendRegistrationToAdmin(Person $user)
 {
     $this->to = env('ADMIN_EMAIL');
     $this->view = 'auth.emails.adminconfirm';
     $roles_string = '';
     foreach ($user->getRoles() as $role) {
         $roles_string .= $role . ',';
     }
     $roles_string = rtrim($roles_string, ',');
     $this->data = ['user' => $user, 'roles' => $roles_string];
     $this->subject = 'Nieuwe registratie';
     $this->deliver();
 }
Пример #26
0
 /**
  * Show guest register form
  * @return mixed
  */
 public function actionGuest()
 {
     $model = new Person();
     $model->prs_type = Person::PERSON_TYPE_GUEST;
     $model->prs_active = 0;
     $oConference = $this->findConferenceModel();
     $model->aSectionList = ArrayHelper::map($oConference->sections, 'sec_id', 'sec_title');
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($oConference->cnf_guestlimit > 0 && $oConference->cnf_guestlimit <= $oConference->getGuestcount()) {
             return [Html::getInputId($model, 'prs_fam') => ['Превышено максимальное количество гостей']];
         }
         return ActiveForm::validate($model);
     }
     if ($oConference->cnf_guestlimit > 0 && $oConference->cnf_guestlimit <= $oConference->getGuestcount()) {
         return $this->render('//person/_guest_limit_exeeded', ['oConference' => $oConference, 'model' => $model]);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->render('//person/ok_guest', ['oConference' => $oConference, 'model' => $model]);
     }
     return $this->render('//person/_form_guest', ['oConference' => $oConference, 'model' => $model]);
 }
Пример #27
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Person::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['person_id' => $this->person_id, 'is_student' => $this->is_student, 'is_coach' => $this->is_coach, 'person_rate' => $this->person_rate, 'recommend_by' => $this->recommend_by]);
     $query->andFilterWhere(['like', 'person_wechat_id', $this->person_wechat_id])->andFilterWhere(['like', 'person_name', $this->person_name])->andFilterWhere(['like', 'phone_number', $this->phone_number]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Person::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'name_eng', $this->name_eng]);
     return $dataProvider;
 }
Пример #29
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Person::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'sex' => $this->sex, 'address_id' => $this->address_id, 'rec_status_id' => $this->rec_status_id, 'user_id' => $this->user_id, 'dc' => $this->dc]);
     $query->andFilterWhere(['like', 'lname', $this->lname])->andFilterWhere(['like', 'fname', $this->fname])->andFilterWhere(['like', 'mname', $this->mname])->andFilterWhere(['like', 'birthday', $this->birthday])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Пример #30
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Person::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'register_date' => $this->register_date, 'person_type_id' => $this->person_type_id, 'tud_id' => $this->tud_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'emailaddress', $this->emailaddress])->andFilterWhere(['like', 'picture', $this->picture]);
     return $dataProvider;
 }