Exemplo n.º 1
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->login = $this->username ?: $this->email;
         $user->email = $this->email;
         $user->password = $this->password;
         $seller = User::findByUsername($this->seller ?: 'ahnames');
         if (!$seller->id) {
             throw new InvalidParamException('wrong seller given');
         }
         $user->seller_id = $seller->id;
         //$user->setPassword($this->password);
         //$user->generateAuthKey();
         $user->save();
         $user = User::findByUsername($user->login);
         if (!$user) {
             throw new IntegrityException('failed create user');
         }
         $contact = Contact::findOne($user->id);
         $contact->load([$contact->formName() => $this->getAttributes()]);
         $contact->save();
         return $user;
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * Creates a new Company model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Company();
     if ($model->load(Yii::$app->request->post())) {
         $model->save();
         $company_id = $model->id;
         $user_id = Yii::$app->user->id;
         $contact = new Contact();
         $contact->company_id = $company_id;
         $contact->user_id = $user_id;
         $contact->roles_code = Roles::ROLE_EMP;
         if (!$contact->save()) {
             throw new NotFoundHttpException('Save contact error');
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 3
0
 /**
  * Displays a single Ticket model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $notes = new ActiveDataProvider(['query' => $model->getNotes()->complete()->with(['author', 'attachment']), 'pagination' => false, 'sort' => ['attributes' => ['public', 'created_at'], 'defaultOrder' => ['created_at' => SORT_ASC]]]);
     $labors = new ActiveDataProvider(['query' => $model->getLabors()->joinWith('schedule.tech')->with(['note', 'schedule.travel'])->orderBy(Schedule::tableName() . '.start_time'), 'key' => 'schedule_id', 'pagination' => false, 'sort' => ['attributes' => ['schedule.start_time' => ['asc' => [Schedule::tableName() . '.start_time' => SORT_ASC], 'desc' => [Schedule::tableName() . '.start_time' => SORT_DESC]], 'schedule.tech_id' => ['asc' => [Contact::tableName() . '.name' => SORT_ASC], 'desc' => [Contact::tableName() . '.name' => SORT_DESC]]], 'defaultOrder' => ['schedule.start_time' => SORT_DESC]]]);
     $purchases = new ActiveDataProvider(['query' => $model->getPurchasedItems(), 'pagination' => false, 'sort' => ['defaultOrder' => ['id' => SORT_ASC]]]);
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('view', ['model' => $model, 'notes' => $notes, 'labors' => $labors, 'purchases' => $purchases]);
     }
     Url::remember();
     return $this->render('view', ['model' => $model, 'notes' => $notes, 'labors' => $labors, 'purchases' => $purchases]);
 }
Exemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::readFilter(Contact::find()->joinWith('contact_groups'));
     //$query = Yii::$app->user->identity->readFilter(Contact::find()->joinWith('contact_groups'));
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'company', $this->company])->andFilterWhere(['like', 'phone_prefix', $this->phone_prefix])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'mobile_prefix', $this->mobile_prefix])->andFilterWhere(['like', 'general_prefix', $this->general_prefix])->andFilterWhere(['like', 'general', $this->general])->andFilterWhere(['=', 'contact_category_id', $this->contact_category_id]);
     return $dataProvider;
 }
Exemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Contact::find()->joinWith('client')->andWhere([Client::tableName() . '.active' => true]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 25], 'sort' => ['defaultOrder' => ['name' => SORT_ASC]]]);
     $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([Contact::tableName() . '.client_id' => $this->client_id, Contact::tableName() . '.active' => $this->active]);
     $query->andFilterWhere(['like', Contact::tableName() . '.name', $this->name])->andFilterWhere(['like', Contact::tableName() . '.email', $this->email])->andFilterWhere(['like', Contact::tableName() . '.phone', $this->phone]);
     return $dataProvider;
 }
Exemplo n.º 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Contact::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['company_id' => $this->company_id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'udpated_at' => $this->udpated_at]);
     $query->andFilterWhere(['like', 'roles_code', $this->roles_code])->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'work_phone', $this->work_phone])->andFilterWhere(['like', 'mobile_phone', $this->mobile_phone])->andFilterWhere(['like', 'address1', $this->address1])->andFilterWhere(['like', 'address2', $this->address2])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'province', $this->province])->andFilterWhere(['like', 'postal_code', $this->postal_code])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
Exemplo n.º 7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tech::find()->joinWith('contact');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['username'] = ['asc' => [Contact::tableName() . '.email' => SORT_ASC], 'desc' => [Contact::tableName() . '.email' => SORT_DESC]];
     $dataProvider->sort->attributes['name'] = ['asc' => [Contact::tableName() . '.name' => SORT_ASC], 'desc' => [Contact::tableName() . '.name' => SORT_DESC]];
     $dataProvider->sort->defaultOrder = ['name' => SORT_ASC];
     $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([Tech::tableName() . '.contact_id' => $this->id]);
     $query->andFilterWhere(['like', Contact::tableName() . '.email', $this->username])->andFilterWhere(['like', Contact::tableName() . '.name', $this->name]);
     return $dataProvider;
 }
Exemplo n.º 8
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['contact_id', 'startTime', 'endTime', 'roles'], 'required'], [['contact_id'], 'integer'], [['password'], 'string', 'min' => 6, 'max' => 32], [['confirm_password'], 'compare', 'compareAttribute' => 'password'], [['start_of_day', 'end_of_day'], 'date', 'format' => 'HH:mm'], [['end_of_day'], 'compare', 'operator' => '>', 'compareAttribute' => 'start_of_day'], [['roles'], 'each', 'rule' => ['string']], [['contact_id'], 'exist', 'targetClass' => Contact::className(), 'targetAttribute' => 'id'], [['contact_id'], 'unique', 'targetClass' => Tech::className(), 'message' => 'This user already has an account.'], [['roles'], 'each', 'rule' => ['in', 'range' => ArrayHelper::getColumn(Yii::$app->authManager->getRoles(), 'name')]]];
 }
Exemplo n.º 9
0
 /**
  * Finds the Contact model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Contact the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Contact::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 10
0
 /**
  * @return ContactQuery
  */
 public function getAuthor()
 {
     return $this->hasOne(Contact::className(), ['id' => 'author_id'])->inverseOf('notes');
 }
Exemplo n.º 11
0
 /**
  * @return ContactQuery
  */
 public function getApprovedBy()
 {
     return $this->hasOne(Contact::className(), ['id' => 'contact_id'])->viaTable('tbl_ticket_approval', ['ticket_id' => 'id']);
 }
Exemplo n.º 12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContacts()
 {
     return $this->hasMany(Contact::className(), ['tenant_id' => 'id']);
 }
Exemplo n.º 13
0
 /**
  * Executes the rule.
  *
  * @param string|integer $user the user ID. This should be either an integer or a string representing
  * the unique identifier of a user. See [[\yii\web\User::id]].
  * @param Item $item the role or permission that this rule is associated with
  * @param array $params parameters passed to [[ManagerInterface::checkAccess()]].
  * @return boolean a value indicating whether the rule permits the auth item it is associated with.
  */
 public function execute($user, $item, $params)
 {
     return isset($params['contact']) ? $params['contact']->className() == Contact::className() && $params['contact']->client_id !== Client::MASTER_ID : false;
 }
Exemplo n.º 14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContactId()
 {
     return $this->hasOne(Contact::className(), ['id' => 'contact_id']);
 }
Exemplo n.º 15
0
 /**
  * @return ContactQuery
  */
 public function getContacts()
 {
     return $this->hasMany(Contact::className(), ['client_id' => 'id'])->inverseOf('client');
 }
Exemplo n.º 16
0
 /**
  * Finds user by username
  *
  * @param string $username
  * @return Tech|User|null
  */
 public static function findByUsername($username)
 {
     $contact = Contact::find()->where(['email' => $username])->one();
     if ($contact) {
         return $contact->user;
     }
     return null;
 }
Exemplo n.º 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContacts()
 {
     return $this->hasMany(Contact::className(), ['contact_category_id' => 'id']);
 }
Exemplo n.º 18
0
 /**
  * Finds the Contact model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $company_id
  * @param integer $user_id
  * @return Contact the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($company_id, $user_id)
 {
     if (($model = Contact::findOne(['company_id' => $company_id, 'user_id' => $user_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 19
0
 /**
  * @return ContactQuery
  */
 public function getCreatedBy()
 {
     return $this->hasOne(Contact::className(), ['id' => 'created_by']);
 }
Exemplo n.º 20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContacts()
 {
     return $this->hasMany(Contact::className(), ['roles_code' => 'code']);
 }