Example #1
0
 public function getMerchantRelationsFullMeta()
 {
     $user = new User();
     $website = new Website();
     $director = new Director();
     $address = new \App\Models\Address();
     $bank = new Bank();
     $brand = new Brand();
     $merchantFullMeta = ['user' => $user->getMeta(), 'merchant' => [$this->getMeta()], 'bank' => [$bank->getMeta()], 'address' => [$address->getMeta()], 'brand' => [$brand->getMeta()], 'websites' => [$website->getMeta()], 'directors' => [$director->getMeta()]];
     return $merchantFullMeta;
 }
Example #2
0
 public function store(Request $request, $user_as_merchant_model)
 {
     //http://stackoverflow.com/questions/28594076/seed-multiple-rows-at-once-laravel-5
     $Dir_id = Director::orderBy('id', 'desc')->take(1)->get();
     foreach ($Dir_id as $DI) {
         $Did = $DI->id;
     }
     if (!isset($Did)) {
         $Did = 0;
     }
     $Did = $Did + 1;
     $length = count($request->get('directors'));
     //
     $directors = $this->collectDirectorFormData($request, $user_as_merchant_model);
     // every key has an arr except merchant_id
     $director = new Director();
     $directorsRecords[] = null;
     $director_model[] = null;
     //lets create a record
     $files = $request->file('directorImages');
     for ($i = 0; $i < $length; $i++) {
         $files_name = $files[$i]->getClientOriginalName();
         $destination = 'public/images/director/' . $Did . '/';
         if ($files[$i]->move($destination, $files_name)) {
             $record = ['name' => $directors['name'][$i], 'nric' => $directors['nric'][$i], 'country_id' => $directors['country_id'][$i], 'photo_1' => $destination . $files_name, 'merchant_id' => $directors['merchant_id']];
             $directorsRecords[] = $record;
             // dd($record);// ["name" => "ds"      ,      "nric" => "23123", "country_id" => "13",  "merchant_id" => 2]
         }
         $Did = $Did + 1;
     }
     unset($directorsRecords[0]);
     // as first record is null  => $directorsRecords[] = null;  so remove it to prevent an extra entry in db
     foreach ($directorsRecords as $directorSingleRecord) {
         $director_model[] = $director->create($directorSingleRecord);
     }
     unset($director_model[0]);
     // as first modal is null  =>  $director_model[] = null;  so remove it to prevent an ambiguity for user(developer)
     return $director_model;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Director::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', 'nombres', $this->nombres])->andFilterWhere(['like', 'apellidos', $this->apellidos]);
     return $dataProvider;
 }
Example #4
0
 /** GET RANDOM RESULT **/
 public function getRandomResult()
 {
     $numTotalFilms = 1000;
     // Get the first 1000 films
     $filmIds = Film::orderBy('rating', 'desc')->limit($numTotalFilms)->select('id')->lists('id')->toArray();
     // Random retrieve 1 of them
     $offset = rand(0, $numTotalFilms - 1);
     $filmId = array_slice($filmIds, $offset, 1);
     // 5 of 6 times, we'll show director, instead of actor
     $value = rand(1, 6);
     if ($value == 1) {
         // 1 of 4 possibilities: actor/actress
         $name = Cast::where('id', '=', $filmId)->select('name')->lists('name')->first();
         $filmIds = Cast::where('name', '=', $name)->select('id')->lists('id')->toArray();
         $type = 'actor';
     } else {
         $name = Director::where('id', '=', $filmId)->select('name')->lists('name')->first();
         $filmIds = Director::where('name', '=', $name)->select('id')->lists('id')->toArray();
         $type = 'director';
     }
     $result = $this->_buildResultSingle($type, $name, $filmIds);
     return $result;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDirector()
 {
     return $this->hasOne(Director::className(), ['id' => 'directorid']);
 }
Example #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     /*
             $brand_name_array = $request->get('brand_name');
             Models used fo registering a merchant
             User, Bank, Buyer, Address, Merchant, Brand, Website and Director
     */
     $user = new User();
     $user_model = $user->store($request);
     //return new user record in db
     $bank = new Bank();
     $bank_model = $bank->store($request);
     if ($request['indication'] == 'buyer') {
         return "no functionality implemented";
         $buyer = new Buyer();
         $buyer_model = $buyer->store($request, $user_model);
     }
     if ($request['indication'] == 'merchant') {
         //TODO: for adding address first create address then add address id to merchant table
         //country_id   => working
         $address = new Address();
         $address_model = $address->store($request);
         // user_id, country_id, address_id, bank_id => working
         $user_as_merchant = new Merchant();
         $user_as_merchant_model = $user_as_merchant->store($request, $user_model, $bank_model, $address_model);
         /*
          * Document table
          */
         $documents = new Document();
         $documents_model = $documents->store($request, $user_as_merchant_model);
         //todo: add brand
         //1)create merchant and get model
         //2)create all brand and get all models
         //3)sync merchant model with brand models in merchantbrand table
         $brand = new Brand();
         $brand_models = $brand->store($request, $user_as_merchant_model, $address_model);
         //now syncing
         $user_as_merchant_model->attachBrands($user_as_merchant_model, $brand_models);
         //http://laravel.com/docs/5.1/eloquent-relationships#inserting-many-to-many-relationships
         //for storing web sites in "merchantwebsite" table
         //first create merchant and get id
         //then create websites and get website model array like director
         //then attach merchant with each website id
         $website = new Website();
         $website_models = $website->store($request);
         //attachment with merchant in "merchantwebsite" table
         $user_as_merchant->attachWebsites($website_models, $user_as_merchant_model);
         $director = new Director();
         $director_model = $director->store($request, $user_as_merchant_model);
         /*save all FKs of directors & merchants to merchantdirectos tables */
         $user_as_merchant_model->attachDirectors($director_model, $user_as_merchant_model);
         \Session::flash(Config::get('messages.key.name'), $this->messageHandler->success('merchantRegistered', null, null, true, true, true));
     }
     return redirect()->back();
 }
 /**
  * Finds the Director model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Director the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Director::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDirectors()
 {
     return $this->hasMany(Director::className(), ['personaid' => 'id']);
 }