Ejemplo n.º 1
0
 public function rules()
 {
     return [[['password', 'email', 'title'], 'required', 'on' => self::SCENARIO_NEW], [['email', 'title'], 'required', 'on' => self::SCENARIO_EDIT], ['password', 'string', 'min' => Yii::$app->params['passLength']], ['password_repeat', 'compare', 'compareAttribute' => 'password', 'message' => Yii::t('app', "Passwords don't match")], [['ssid'], 'default', 'value' => helper::getSsid()], [['ssid', 'shop_id'], 'integer'], [['title'], 'string', 'max' => 100], [['description'], 'string', 'max' => 250], 'emailPattern' => ['email', 'email'], 'emailLength' => ['email', 'string', 'max' => 255], 'emailUniqueEdit' => ['email', function ($attribute) {
         if (User::findByEmail($this->email)) {
             $this->addError($attribute, $this->email . Yii::t('app', 'Email already exist'));
         }
     }, 'when' => function () {
         $user = User::findByEmail($this->email);
         if (!empty((array) $user)) {
             return Yii::$app->user->id != $user->id;
             // do not check for current user (my email)
         }
     }, 'on' => self::SCENARIO_EDIT], 'emailUniqueNew' => ['email', function ($attribute, $params) {
         $user = User::findByEmail($this->{$attribute});
         if (!empty((array) $user)) {
             $this->addError($attribute, Yii::t('app', 'Email already exist'));
         }
     }, 'on' => self::SCENARIO_NEW], 'emailTrim' => ['email', 'trim'], 'oldPassCheck' => ['password_old', function ($attribute) {
         $user = User::findIdentity($this->id);
         if (!empty((array) $user)) {
             if ($user->validatePassword($this->password_old)) {
                 $this->addError($attribute, Yii::t('app', 'Password Do not match'));
             }
         }
     }, 'on' => self::SCENARIO_EDIT]];
 }
Ejemplo n.º 2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  * @param $isAdmin true|false
  * can create Simple Manager or Admin
  */
 public function signup($isAdmin = false)
 {
     if ($this->validate()) {
         $user = new User();
         $user->firmname = $this->firmname;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             if ($isAdmin) {
                 $ssid = $user->id;
                 $user->ssid = $ssid;
                 $user->update();
                 // set's up Defaults for Admin
                 NewUserSetup::AdminSetUp($ssid);
             } else {
                 $user->ssid = helper::getSsid();
                 $user->update();
             }
             return $user;
         }
     } else {
         return null;
     }
 }
Ejemplo n.º 3
0
 public function actionWellcome()
 {
     if (Yii::$app->user->isGuest) {
         return $this->render('/user/thankYou');
     } else {
         //  $this->layout = 'shop'; // custom layout for logged users
         $model = helper::getSsid();
         return $this->render('wellcome', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Merchandise::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, 'ssid' => helper::getSsid(), 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'producer', $this->producer]);
     return $dataProvider;
 }
Ejemplo n.º 5
0
 public function tree()
 {
     $arrIN = array();
     // Model to array
     $arr = array();
     $query = CatProd::find()->where(['ssid' => helper::getSsid()])->orderBy('title')->all();
     // builds internall array
     foreach ($query as $item) {
         $arrIN[] = array('key' => $item->id, 'parent' => $item->self_id, 'title' => $item->title, 'folder' => true, 'href' => '#', 'target' => '_self');
     }
     foreach ($arrIN as $a) {
         $arr[$a['parent']][] = $a;
     }
     $tree = self::createTree($arr, $arr[0]);
     return $tree;
 }
Ejemplo n.º 6
0
 public static function getFirmName()
 {
     if (Yii::$app->session->get('firmname') == null) {
         $userObj = User::findOne(['id' => helper::getSsid()]);
         if (!empty((array) $userObj)) {
             $firmname = $userObj->firmname;
         } else {
             $firmname = null;
         }
         if ($firmname == null) {
             \Yii::getLogger()->log("Firm name not found !", Logger::LEVEL_ERROR);
             //echo "Firm name not found !";
         } else {
             Yii::$app->session->set('firmname', $firmname);
         }
     } else {
         $firmname = Yii::$app->session->get('firmname');
     }
     return $firmname;
 }
Ejemplo n.º 7
0
 public static function getShopList()
 {
     //$models = Shop::find()->asArray()->andWhere(['ssid'=>helper::getSsid()]);
     $models = Shop::findAll(['ssid' => helper::getSsid()]);
     return ArrayHelper::map($models, 'id', 'title');
 }
Ejemplo n.º 8
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['cat_id', 'warranty', 'serialno', 'type', 'units', 'ssid', 'shopID', 'manID', 'status', 'created_at', 'updated_at'], 'integer'], [['curs', 'price', 'buy', 'quantity', 'min_quantity'], 'number'], [['ssid'], 'default', 'value' => helper::getSsid()], [['producer'], 'string', 'max' => 150], [['title'], 'string', 'max' => 200], [['barcode'], 'string', 'max' => 50]];
 }
Ejemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['ssid'], 'default', 'value' => helper::getSsid()], [['ssid', 'shop_id', 'created_at', 'updated_at'], 'integer'], [['title'], 'string', 'max' => 100], [['description'], 'string', 'max' => 250]];
 }
Ejemplo n.º 10
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['self_id', 'ssid', 'shopID', 'manID', 'status', 'created_at', 'updated_at'], 'integer'], [['fixedMarkup', 'percentMarkup'], 'number'], [['ssid'], 'default', 'value' => helper::getSsid()], [['shopID'], 'default', 'value' => helper::showShopID()], [['manID'], 'default', 'value' => Yii::$app->user->id], [['self_id'], 'default', 'value' => '0'], [['title'], 'string', 'max' => 200], [['title'], 'required']];
 }