Ejemplo n.º 1
0
 public function addAction()
 {
     if ($this->request->isPost()) {
         $data = $this->request->getPost();
         //load from url
         if ($from_url = $this->request->getPost('from-url')) {
             $data['image'] = $this->request->getPost('image-url');
         } else {
             $file = $this->getRequest()->getFiles('image');
             $data['image'] = 'image';
         }
         $validate = \Sticks\Beans\Stickers::getInputFilter();
         $validate->setData($data);
         $errors = array();
         if ($validate->isValid()) {
             $data = $validate->getValues();
             $img_path = APPLICATION_PATH . '/public/source/sticks/';
             $em = $this->getServiceLocator()->get('em');
             $stick_bean = new Stickers($em);
             $imagebean = new ImageLoader($em, $img_path);
             if ($from_url == 1) {
                 $imagebean->loadFromUrl($data['image']);
             } else {
                 $imagebean->loadFromForm($data['image']);
             }
             if (!count($imagebean->getErrors())) {
                 $data['image'] = $imagebean->getLastSaveImage();
                 $stick_bean->create($data);
             } else {
                 $errors[] = $imagebean->getErrors();
             }
         }
         \Custom\Ajax\Json::response(1, 'Sticked!', $validate->getMessages() + $errors);
     }
 }
Ejemplo n.º 2
0
 public function testCreate()
 {
     $il = new ImageLoader($this->em);
     $il->setDestination('/home/admin/repo/vasabi/public/source/users/');
     $il->loadFromUrl('http://cdn.techlineinfo.com/wp-content/uploads/2010/05/User.png');
     $this->assertCount(0, $il->getErrors());
     $data = array('username' => 'Вася', 'email' => '*****@*****.**', 'password' => 'aaa', 'image' => $il->getLastSaveImage());
     $id = $this->object->create($data, true);
     $this->assertTrue($id->getId() > 0);
     return $id;
 }