image() public method

Get image src
public image ( integer $width = 80, integer $height = 80, string $specs = 'fit', string $imagePath = null ) : string
$width integer
$height integer
$specs string
$imagePath string
return string
Exemplo n.º 1
0
 public function loginAction()
 {
     $this->getHelper('contextSwitch')->addActionContext('login', 'json')->initContext();
     $translator = Zend_Registry::get('container')->getService('translator');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $params = $request->getParams();
         $adapter = $this->_helper->service('auth.adapter');
         $adapter->setEmail($params['email'])->setPassword($params['password']);
         $result = $this->auth->authenticate($adapter);
         if ($result->getCode() == Zend_Auth_Result::SUCCESS) {
             $user = Zend_Registry::get('container')->getService('user')->getCurrentUser();
             $metaUser = new \MetaUser($user);
             $width = array_key_exists("imageWidth", $params) ? $params['imageWidth'] : 80;
             $height = array_key_exists("imageHeight", $params) ? $params['imageHeight'] : 80;
             $specification = array_key_exists("imageSpecification", $params) ? $params['imageSpecification'] : 'fit';
             $this->view->userData = array('realName' => $user->getRealName(), 'username' => $user->getUsername(), 'avatar' => $metaUser->image($width, $height, $specification));
             $this->view->response = 'OK';
         } else {
             $this->view->response = $translator->trans('Login failed.');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Get user by given id
  *
  * @ApiDoc(
  *     statusCodes={
  *         200="Returned when successful",
  *         404="Returned when the user is not found",
  *     },
  *     parameters={
  *         {"name"="id", "dataType"="integer", "required"=true, "description"="User id"},
  *         {"name"="image_type", "dataType"="string", "required"=false, "description"="User image specification (e.g. crop, fit)"},
  *         {"name"="image_width", "dataType"="integer", "required"=false, "description"="User image width"},
  *         {"name"="image_height", "dataType"="integer", "required"=false, "description"="User image height"},
  *     },
  *     output="\Newscoop\Entity\User"
  * )
  *
  * @Route("/users/{id}.{_format}", defaults={"_format"="json"}, options={"expose"=true})
  * @Method("GET")
  * @View(serializerGroups={"list"})
  *
  * @return array
  */
 public function getUserAction(Request $request, $id)
 {
     $em = $this->container->get('em');
     $imageType = $request->get('image_type');
     $imageHeight = $request->get('image_height');
     $imageWidth = $request->get('image_width');
     $user = $em->getRepository('Newscoop\\Entity\\User')->getOneActiveUser($id)->getOneOrNullResult();
     if (!$user) {
         throw new NotFoundHttpException('Result was not found.');
     }
     $metaUser = new \MetaUser($user);
     $user->setImage($metaUser->image(is_numeric($imageWidth) ? $imageWidth : 80, is_numeric($imageHeight) ? $imageHeight : 80, !is_numeric($imageType) && is_string($imageType) ? $imageType : 'crop'));
     return $user;
 }