/** * Constructor. * * @param sfUser A sfUser instance * @param array An array of options * @param string A CSRF secret (false to disable CSRF protection, null to use the global CSRF secret) * * @see sfForm */ public function __construct(sfUser $user, $options = array(), $CSRFSecret = null) { $this->user = $user; parent::__construct(array(), $options, $CSRFSecret); // the defaults depend on the options, so set them after construction $this->setDefaults(array('max_per_page' => $user->getAttribute(self::getMaxPerPageName(), self::getMaxPerPageValue()))); }
/** * get singleton instance * @param sfUser $sfUser * @return tpyCart */ public static function getInstance(sfUser $sfUser) { if (is_null(self::$_instance)) { if ($sfUser->isAuthenticated()) { self::$_instance = tpyUserCartTable::getInstance()->findOneBySfGuardUserId($sfUser->getGuardUser()->getId()); if (false == self::$_instance) { self::$_instance = new tpyUserCart(); self::$_instance->setSfGuardUserId($sfUser->getGuardUser()->getId()); } } else { self::$_instance = new tpyCart(); self::$_instance->_user = $sfUser; self::$_instance->_items = $sfUser->getAttribute('cart_items', array(), tpyCart::SESSION_NS); } } return self::$_instance; }