Ejemplo n.º 1
0
 public function register($params)
 {
     $row = (array) json_decode($params['data']);
     $row['created'] = date("Y-m-d H:i:s");
     $row['enabled'] = '1';
     $row['image_id'] = '0';
     $row['role_id'] = '2';
     /**
      * @todo
      * Validation if pseudo or email already exists
      */
     $imageMapper = new ImageMapper();
     //var_dump($_FILES);
     $imageObj = $imageMapper->upload($_FILES['file'], $row['created']);
     $userObj = new User();
     $userObj->setCreated($row['created'])->setEnabled($row['enabled'])->setImageId($row['image_id'])->setRoleId($row['role_id'])->setLogin($row['login'])->setPassword(md5($row['password']))->setEmail($row['email']);
     //$userObj = $this->save($userObj);
     $imageObj->setAlt('Picture of ' . $userObj->getLogin());
     $imageObj->setTitle('Picture of ' . $userObj->getLogin());
     $imageObj->setWidth('');
     $imageObj->setHeight('');
     $imageObj = $imageMapper->save($imageObj);
     $userObj->setImageId($imageObj->getId());
     //var_dump($imageObj->getId());
     $this->save($userObj);
     return array('success' => true, 'data' => array('username' => $userObj->getLogin(), 'image' => $imageObj->getImageName(), 'image_alt' => $imageObj->getAlt(), 'image_title' => $imageObj->getTitle(), 'role' => $userObj->getRoleId() == 2 ? 'customer' : 'admin'));
 }
Ejemplo n.º 2
0
 public function add($params)
 {
     $row = (array) json_decode($params['data']);
     $imageMapper = new ImageMapper();
     $imageObj = $imageMapper->upload($_FILES['file'], time());
     $imageObj->setAlt('Picture of ' . $row['product_name']);
     $imageObj->setTitle('Picture of ' . $row['product_name']);
     $imageObj->setWidth('');
     $imageObj->setHeight('');
     $imageObj = $imageMapper->save($imageObj);
     $product = new Product();
     $product->setProductName($row['product_name'])->setTeaser($row['teaser'])->setDescription($row['description'])->setImageId($imageObj->getId())->setCategoryId($row['category_id'])->setPrice($row['price']);
     $response = $this->save($product);
     return $response;
 }