<?php
/**
 * SocialEngine
 *
 * @category   Application_Core
 * @package    User
 * @copyright  Copyright 2006-2020 Webligo Developments
 * @license    http://www.socialengine.com/license/
 * @version    $Id: Avatar.php 9747 2012-07-26 02:08:08Z john $
 * @author     John
 */

/**
 * @category   Application_Core
 * @package    User
 * @copyright  Copyright 2006-2020 Webligo Developments
 * @license    http://www.socialengine.com/license/
 */

class User_Form_Signup_Avatar extends Engine_Form {

  public function init() {

    $this->setTitle('Choose Avatar')
      ->setDescription('')
      ->setAttrib('name', 'user_avatar')
      ->setAttrib('class', 'global_form');

		//Get the signup profile type from session
		$genderLabel = Engine_Api::_()->user()->getSignupGenderBeforeCreate();

		$avatars = !empty($genderLabel) ? Engine_Api::_()->getDbtable('avatars', 'user')->getAvatars(array('enabled' => 1, 'fetchAll' => 1, 'gender' => strtolower($genderLabel))) : Engine_Api::_()->getDbtable('avatars', 'user')->getAvatars(array('enabled' => 1, 'fetchAll' => 1));

    $options = array();
    foreach ($avatars as $avatar) {
      $photo = Engine_Api::_()->storage()->get($avatar->file_id, '');
      if($photo)
				$options[$avatar->file_id] = '<img src="'.$photo->getPhotoUrl().'" data-url="'.$photo->getPhotoUrl().'" alt="" />';
    }

    $this->addElement('Radio', 'avatar', array(
      'label' => '',
      'multiOptions' => $options,
      'escape' => false,
    ));

    // Buttons
    $this->addElement('Button', 'submit', array(
      'label' => 'Save',
      'type' => 'submit',
      'ignore' => true,
      'decorators' => array('ViewHelper')
    ));

    $this->addElement('Cancel', 'cancel', array(
      'label' => 'Cancel',
      'link' => true,
      // 'prependText' => ' or ',
      'href' => '',
      'onclick' => 'javascript:ajaxsmoothboxclose();',
      'decorators' => array(
        'ViewHelper'
      )
    ));
    $this->addDisplayGroup(array('submit', 'cancel'), 'buttons');
  }
}
