Exemplo n.º 1
0
 /**
  * Редактирование категории 
  * @param  \Psr\Http\Message\ServerRequestInterface $request
  * @param  \Psr\Http\Message\ResponseInterface  $response
  */
 public function edit($request, $response)
 {
     $id = $request->getAttribute('id');
     if (!isset($id)) {
         return $response->withRedirect('/categories');
     }
     $id = (int) $id;
     $category = Model::factory('Models\\Category')->find_one($id);
     if (!isset($category->id)) {
         return $response->withRedirect('/categories');
     }
     if (isset($_POST['submit'])) {
         $data = \Ohanzee\Helper\Arr::extract($_POST, ['title'], '');
         if (!empty($_FILES['image']['name'])) {
             $image = Image::open($_FILES['image']['tmp_name']);
             $image->scaleResize($this->image_width, $this->image_height, '0xffffff');
             $filename = md5(base64_encode($image->get('png', 100))) . '.png';
             $image->save(DOCROOT . '/../aleksandr-sazhin.myjino.ru/_/' . $filename);
             $data['image'] = $filename;
         }
         $category->values($data);
         $category->save();
         return $response->withRedirect('/categories/edit/' . $category->id);
     }
     return $this->render('categories/edit.html', ['category' => $category]);
 }
Exemplo n.º 2
0
 /**
  * @covers \Ohanzee\Helper\Arr::extract()
  * @dataProvider dataDeepArray
  */
 public function testExtract($arr)
 {
     $simple = array('foo' => 'bar');
     $this->assertEquals(Arr::extract($simple, array_keys($simple)), $simple);
     $default = false;
     $paths = array('breakfast.food', 'lunch.food', 'supper.food', 'fake.key');
     $expect = array('breakfast' => array('food' => 'eggs'), 'lunch' => array('food' => 'hamburger'), 'supper' => array('food' => 'pizza'), 'fake' => array('key' => $default));
     $this->assertEquals(Arr::extract($arr['top'], $paths, $default), $expect);
 }