Esempio n. 1
0
 public function update_crop()
 {
     $id = $_POST['id'];
     $common_name = $_POST['common-name'];
     $scientific_name = $_POST['scientific-name'];
     $harvest_time = $_POST['harvest-time'];
     $months = $_POST['months'];
     $details = $_POST['details'];
     Crop::update($id, $common_name, $scientific_name, $harvest_time, $months, $details);
     $crops = Crop::all();
     require_once 'views/crops/admin.php';
 }
 public function edit($id)
 {
     $product = Product::find($id);
     $crop = Crop::all()->lists('crop_name', 'id');
     return View::make('products.edit')->with('product', $product)->with('title', "Edit Product")->with('crop', $crop);
 }
 public function crop()
 {
     $isPost = $this->request->isPost();
     if ($isPost) {
         $crop = new Crop($this->request->post('avatar_src', null), $this->request->post('avatar_data', null), !empty($this->request->files['avatar_file']) ? $this->request->files['avatar_file'] : null);
         $response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $crop->getResult(true));
         echo json_encode($response);
         return true;
     }
     return $this->response->render('admin/crop');
 }
Esempio n. 4
0
 /**
  * Remove the specified resource from storage.
  * DELETE /crops/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $crop = Crop::find($id);
     $crop->delete();
     return Redirect::route('crops.index')->with('success', 'Successfully Deleted');
 }
 public function testIndexHasCrops()
 {
     Crop::shouldReceive('all')->once()->andReturn($this->collection);
     $this->call('GET', '/');
     $this->assertViewHas('crops', $this->collection);
 }
Esempio n. 6
0
 public function apply($resource)
 {
     // Extract arguments
     @(list(, $w_ratio, $h_ratio, $position) = func_get_args());
     $w_ratio = (double) $w_ratio;
     $h_ratio = (double) $h_ratio;
     if ($w_ratio <= 0 or $h_ratio <= 0) {
         throw new Exception("Ratio cannot be null or negative");
     }
     // Get resolution
     $w_src = imagesx($resource);
     $h_src = imagesy($resource);
     if ($w_src === false or $h_src === false) {
         throw new Exception("An error was encountered while getting image resolution");
     }
     // Compute basic chop dimensions
     $w_tmp = round($h_src / $h_ratio * $w_ratio);
     $h_tmp = round($w_src / $w_ratio * $h_ratio);
     if ($w_tmp > $h_tmp) {
         $width = $w_src;
         $height = $h_tmp;
     } else {
         $width = $w_tmp;
         $height = $h_src;
     }
     // Compute position
     switch ($position) {
         case self::LEFT:
             $x = 0;
             if ($w_ratio < $h_ratio) {
                 $y = 0;
             } elseif ($w_ratio > $h_ratio) {
                 $y = round(($h_src - $height) / 2);
             } else {
                 $y = round(($h_src - $height) / 2);
             }
             break;
         case self::RIGHT:
             $x = $w_src - $width;
             if ($w_ratio < $h_ratio) {
                 $y = 0;
             } elseif ($w_ratio > $h_ratio) {
                 $y = round(($h_src - $height) / 2);
             } else {
                 $y = round(($h_src - $height) / 2);
             }
             break;
         case self::TOP:
             if ($w_ratio < $h_ratio) {
                 $x = round(($w_src - $width) / 2);
             } elseif ($w_ratio > $h_ratio) {
                 $x = 0;
             } else {
                 $x = round(($w_src - $width) / 2);
             }
             $y = 0;
             break;
         case self::BOTTOM:
             if ($w_ratio < $h_ratio) {
                 $x = round(($w_src - $width) / 2);
             } elseif ($w_ratio > $h_ratio) {
                 $x = 0;
             } else {
                 $x = round(($w_src - $width) / 2);
             }
             $y = $h_src - $height;
             break;
         case self::CENTERED:
         default:
             if ($w_ratio < $h_ratio) {
                 $x = round(($w_src - $width) / 2);
                 $y = 0;
             } elseif ($w_ratio > $h_ratio) {
                 $x = 0;
                 $y = round(($h_src - $height) / 2);
             } else {
                 $x = round(($w_src - $width) / 2);
                 $y = round(($h_src - $height) / 2);
             }
     }
     // Chop image
     return parent::apply($resource, $x, $y, $width, $height);
 }