/** * Get all of the products of a given Breeder * * @param Breeder $breeder * @return Collection */ public function forBreeder(Breeder $breeder) { $products = $breeder->products()->where('status', 'requested')->get(); $reservations = $breeder->reservations()->get(); $items = []; // Include all "requested" products foreach ($products as $product) { if ($product->quantity == 0) { continue; } $itemDetail = []; $itemDetail['uuid'] = (string) Uuid::uuid4(); $itemDetail['id'] = $product->id; $itemDetail['reservation_id'] = 0; $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name; $itemDetail['breeder_id'] = $product->breeder_id; $itemDetail['farm_province'] = FarmAddress::find($product->farm_from_id)->province; $itemDetail['name'] = $product->name; $itemDetail['type'] = $product->type; $itemDetail['age'] = $this->computeAge($product->birthdate); $itemDetail['breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name); $itemDetail['quantity'] = $product->quantity; $itemDetail['adg'] = $product->adg; $itemDetail['fcr'] = $product->fcr; $itemDetail['bft'] = $product->backfat_thickness; $itemDetail['status'] = $product->status; $itemDetail['customer_id'] = 0; $itemDetail['customer_name'] = ''; $itemDetail['date_needed'] = ''; $itemDetail['special_request'] = ''; array_push($items, (object) $itemDetail); } // Include "reserved" / "paid" / "on_delivery" / "sold" products foreach ($reservations as $reservation) { $product = Product::find($reservation->product_id); $itemDetail = []; $itemDetail['uuid'] = (string) Uuid::uuid4(); $itemDetail['id'] = $product->id; $itemDetail['reservation_id'] = $reservation->id; $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name; $itemDetail['breeder_id'] = $product->breeder_id; $itemDetail['farm_province'] = FarmAddress::find($product->farm_from_id)->province; $itemDetail['name'] = $product->name; $itemDetail['type'] = $product->type; $itemDetail['age'] = $this->computeAge($product->birthdate); $itemDetail['breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name); $itemDetail['quantity'] = $reservation->quantity; $itemDetail['adg'] = $product->adg; $itemDetail['fcr'] = $product->fcr; $itemDetail['bft'] = $product->backfat_thickness; $itemDetail['status'] = $reservation->order_status; $itemDetail['customer_id'] = $reservation->customer_id; $itemDetail['customer_name'] = Customer::find($reservation->customer_id)->users()->first()->name; $itemDetail['date_needed'] = $this->transformDateSyntax($reservation->date_needed); $itemDetail['special_request'] = $reservation->special_request; array_push($items, (object) $itemDetail); } // dd($items); return collect($items)->toJson(); }
public static function getBreedItems() { $breedItems = []; /** * @var Breed $breed */ foreach (Breed::find()->pets()->all() as $breed) { $breedItems[] = ['label' => $breed->name, 'url' => \Yii::$app->urlManager->createUrl(['/site/breed', 'id' => $breed->id])]; } return $breedItems; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Breed::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, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'common_status_id' => $this->common_status_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * @return Response */ public function index() { Animal::truncate(); $animals = Import::all(); $breeds = Breed::where('species', '=', 'Dog')->orderBy('name')->lists('name', 'id'); $stati = \Config::get('rescue.status'); $no_breed = \Config::get('rescue.select_breed_id'); foreach ($animals as $animal) { $pri_breed_id = array_search($animal->pri_breed, $breeds); if (FALSE != $pri_breed_id) { $sec_breed_id = array_search($animal->sec_breed, $breeds); if (FALSE == $sec_breed_id) { $sec_breed_id = $no_breed; } $status = array_search($animal->status, $stati); if (FALSE == $status) { $status = 0; } Animal::create(array('id' => $animal, 'name' => $animal->name, 'species' => $animal->species, 'pri_breed_id' => $pri_breed_id, 'sec_breed_id' => $sec_breed_id, 'mixed_breed' => $animal->mix == '1' ? TRUE : FALSE, 'date_of_birth' => $animal->date_of_birth, 'gender' => $animal->gender, 'altered' => $animal->altered == 1 ? TRUE : FALSE, 'intake_date' => $animal->intake_date, 'status_id' => $status, 'status_date' => $animal->status_date, 'foster' => $animal->foster, 'picture' => $animal->picture, 'description' => $animal->description)); } } return '<h2>Import Complete: ' . Animal::Count() . ' Records Imported</h2>'; }
<div class="brood-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'date')->widget(DatePicker::classname(), ['options' => ['placeholder' => Yii::t('app', 'Enter birth date ...')], 'type' => DatePicker::TYPE_COMPONENT_APPEND, 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd'], 'removeButton' => false, 'language' => \app\models\Lang::getCurrent()['local']]); ?> <?php echo $form->field($model, 'breed_id')->dropDownList(\app\models\Breed::getAll()); ?> <?php echo $form->field($model, 'common_status_id')->dropDownList(\app\models\CommonStatus::getAll()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
public function pets() { return $this->andWhere([Breed::tableName() . '.common_status_id' => CommonStatus::ACTIVE])->joinWith("broods.pets", true, 'INNER JOIN'); }
/** * @return \yii\db\ActiveQuery */ public function getBreeds() { return $this->hasMany(Breed::className(), ['common_status_id' => 'id']); }
/** * Get breed ids of products based from breed filter value * * @param String $breedParameter * @return Array */ private function getBreedIds($breedParameter) { $tempBreedIds = []; foreach (explode(' ', $breedParameter) as $breedName) { if ($breedName == 'crossbreed') { // Get all breed ids that contain '+' in their breed name $crossbreeds = Breed::where('name', 'like', '%+%')->get(); foreach ($crossbreeds as $crossbreed) { array_push($tempBreedIds, $crossbreed->id); } continue; } else { $breedInstance = Breed::where('name', $breedName)->get()->first()->id; } array_push($tempBreedIds, $breedInstance); } return $tempBreedIds; }
public function load_breeds() { $data = array("apikey" => \Config::get('rescue_groups_org.apikey'), "objectType" => "animalBreeds", "objectAction" => "publicList", "search" => array("resultLimit" => 300, "fields" => array("breedID", "breedName"))); $this->breed_list = $this->postToApi($data); $count = 0; // var_dump($this->breed_list); foreach ($this->breed_list['data'] as $key => $value) { var_dump($key, $value); try { $breedName = $value['name']; $speciesName = $value['species']; $breedArray = ['id' => $key, 'name' => $breedName, 'species' => $speciesName, 'description_url' => 'http://en.wikipedia.org/wiki/' . str_replace(' ', '_', $breedName)]; Breed::create($breedArray); $count++; } catch (Exception $e) { print "<p>" . $e->getMessage() . "</p>"; } } print "Created {$count} Breeds</p></p>"; return View::make('pages.breed.load', compact('breeds')); }
/** * @return \yii\db\ActiveQuery */ public function getBreed() { return $this->hasOne(Breed::className(), ['id' => 'breed_id']); }
public function getBreeds() { return ArrayHelper::map(Breed::find()->puppies()->all(), 'id', 'name'); }
public function actionPuppiesBreed($id) { $model = Breed::findOne($id); if (!$model) { throw new NotFoundHttpException('The requested page does not exist.'); } return $this->render('puppiesBreed', ['model' => $model]); }
$this->params['breadcrumbs'][] = $this->title; ?> <div class="pet-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create Pet'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'petImages', 'value' => function ($data) { if ($data->petImages) { return "<img src='/" . $data->petImages[0]->source_url . "' />"; } return "<img src='/' />"; }, 'format' => 'raw', 'contentOptions' => ['class' => 'grid-image'], 'filter' => false], 'name', 'date_create', 'date_update', ['attribute' => 'breed_id', 'filter' => \app\models\Breed::getAll(), 'value' => 'brood.breed.name'], ['attribute' => 'brood_id', 'filter' => \app\models\Brood::getAllWithDate(), 'value' => function ($data) { return $data->brood->name . " " . $data->brood->date; }], ['attribute' => 'pet_status_id', 'filter' => \app\models\PetStatus::getAll(), "value" => "petStatus.name"], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * Finds the Breed model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Breed the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Breed::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'mother_name')->textInput(); ?> <?php echo $form->field($model, 'mother_link')->textInput(); ?> <?php echo $form->field($model, 'father_name')->textInput(); ?> <?php echo $form->field($model, 'father_link')->textInput(); ?> <?php echo $form->field($model, 'breed_id')->dropDownList(\app\models\Breed::getAll(), ['prompt' => Yii::t('app', '-- select breed --'), 'data-url' => '/pet/subcategory']); ?> <?php echo $form->field($model, 'brood_id')->dropDownList(\app\models\Brood::getAllWithDate($model->breed_id), ['prompt' => Yii::t('app', '-- select brood --')]); ?> <?php echo $form->field($model, 'pet_status_id')->dropDownList(\app\models\PetStatus::getAll()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
/** * Get items in the Swine Cart * [!]AJAX * * @param Request $request * @return JSON/Array */ public function getSwineCartItems(Request $request) { if ($request->ajax()) { $customer = $this->user->userable; $swineCartItems = $customer->swineCartItems()->where('if_requested', 0)->get(); $items = []; foreach ($swineCartItems as $item) { $itemDetail = []; $product = Product::find($item->product_id); $itemDetail['item_id'] = $item->id; $itemDetail['product_id'] = $item->product_id; $itemDetail['product_name'] = $product->name; $itemDetail['product_type'] = $product->type; $itemDetail['product_breed'] = Breed::find($product->breed_id)->name; $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name; $itemDetail['breeder'] = Breeder::find($product->breeder_id)->users()->first()->name; $itemDetail['token'] = csrf_token(); array_push($items, $itemDetail); } $itemsCollection = collect($items); return $itemsCollection->toJson(); } else { $customer = $this->user->userable; $swineCartItems = $customer->swineCartItems()->where('if_rated', 0)->get(); $products = []; $log = $customer->transactionLogs()->get(); $history = []; foreach ($swineCartItems as $item) { $itemDetail = []; $product = Product::find($item->product_id); $reviews = Breeder::find($product->breeder_id)->reviews()->get(); $itemDetail['request_status'] = $item->if_requested; $itemDetail['request_quantity'] = $item->quantity; $itemDetail['status'] = $item->reservation_id ? ProductReservation::find($item->reservation_id)->order_status : $product->status; $itemDetail['staus'] = $product->status; $itemDetail['item_id'] = $item->id; $itemDetail['customer_id'] = $customer->id; $itemDetail['breeder_id'] = $product->breeder_id; $itemDetail['breeder'] = Breeder::find($product->breeder_id)->users()->first()->name; $itemDetail['product_id'] = $item->product_id; $itemDetail['product_province'] = FarmAddress::find($product->farm_from_id)->province; $itemDetail['product_name'] = $product->name; $itemDetail['product_type'] = $product->type; $itemDetail['product_quantity'] = $product->quantity; $itemDetail['product_breed'] = $this->transformBreedSyntax(Breed::find($product->breed_id)->name); $itemDetail['product_birthdate'] = $this->transformDateSyntax($product->birthdate); $itemDetail['product_age'] = $this->computeAge($product->birthdate); $itemDetail['product_adg'] = $product->adg; $itemDetail['product_fcr'] = $product->fcr; $itemDetail['product_backfat_thickness'] = $product->backfat_thickness; $itemDetail['other_details'] = $product->other_details; $itemDetail['avg_delivery'] = $reviews->avg('rating_delivery'); $itemDetail['avg_transaction'] = $reviews->avg('rating_transaction'); $itemDetail['avg_productQuality'] = $reviews->avg('rating_productQuality'); if ($item->date_needed == '0000-00-00') { $itemDetail['date_needed'] = ''; } else { $itemDetail['date_needed'] = $this->transformDateSyntax($item->date_needed); } $itemDetail['special_request'] = $item->special_request; $itemDetail['img_path'] = '/images/product/' . Image::find($product->primary_img_id)->name; if ($item->transactionLog) { $itemDetail['status_transactions'] = json_decode($item->transactionLog->status_transactions, true); } else { $itemDetail['status_transactions'] = ["requested" => '', "reserved" => '', "on_delivery" => '', "paid" => '', "sold" => '', "rated" => '']; } array_push($products, (object) $itemDetail); } $products = collect($products); $history = collect($history); $token = csrf_token(); $customerId = $customer->id; return view('user.customer.swineCart', compact('products', 'history', 'token', 'customerId')); } }
use app\models\Breed; /* @var $this yii\web\View */ /* @var $searchModel app\models\BroodSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Broods'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="brood-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create Brood'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'date', 'date_create', 'date_update', ['attribute' => 'breed_id', 'filter' => Breed::getAll(), 'value' => 'breed.name'], ['attribute' => 'common_status_id', 'value' => function ($data) { return $data->common_status_id == CommonStatus::ACTIVE ? '<span class="status-button status-active glyphicon glyphicon-refresh"></span>' : '<span class="status-button status-inactive glyphicon glyphicon-refresh"></span>'; }, 'format' => 'raw', 'filter' => CommonStatus::getAll()], ['class' => 'yii\\grid\\ActionColumn']], 'options' => ['data-url' => Yii::$app->urlManager->createUrl(['brood/change-status']), 'class' => 'grid']]); ?> </div>