diff --git a/lib/groupnoprofileexception.php b/lib/groupnoprofileexception.php new file mode 100644 index 0000000000..cd9ff812b7 --- /dev/null +++ b/lib/groupnoprofileexception.php @@ -0,0 +1,74 @@ +. + * + * @category Exception + * @package StatusNet + * @author Evan Prodromou + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +/** + * Class for an exception when the group profile is missing + * + * @category Exception + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +class GroupNoProfileException extends NoProfileException +{ + public $group = null; + + /** + * constructor + * + * @param User_group $user User_group that's missing a profile + */ + + public function __construct(User_group $group) + { + $this->group = $group; + + // TRANS: Exception text shown when no profile can be found for a user. + // TRANS: %1$s is a user nickname, $2$d is a user ID (number). + $message = sprintf(_('User %1$s (%2$d) has no profile record.'), + $group->nickname, $group->id); + + parent::__construct($group->profile_id, $message); + } + + /** + * Accessor for user + * + * @return User_group the group that triggered this exception + */ + + public function getGroup() + { + return $this->group; + } +} diff --git a/lib/noprofileexception.php b/lib/noprofileexception.php new file mode 100644 index 0000000000..eebdc3bafe --- /dev/null +++ b/lib/noprofileexception.php @@ -0,0 +1,59 @@ +. + * + * @category Exception + * @package StatusNet + * @author Evan Prodromou + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +/** + * Parent class for an exception when a profile is missing + * + * @category Exception + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +class NoProfileException extends NoProfileException +{ + public $profile_id = null; + + public function __construct($profile_id, $msg=null) + { + $this->id = (int)$profile_id; + + if ($msg === null) { + // TRANS: Exception text shown when no profile can be found for a user. + // TRANS: %1$s is a user nickname, $2$d is a user ID (number). + $msg = sprintf(_('User %1$s (%2$d) has no profile record.'), + $group->nickname, $group->id); + } + + parent::__construct($msg, 404); + } +} diff --git a/lib/usernoprofileexception.php b/lib/usernoprofileexception.php index 954d31b0d1..83478040c2 100644 --- a/lib/usernoprofileexception.php +++ b/lib/usernoprofileexception.php @@ -2,7 +2,7 @@ /** * StatusNet, the distributed open-source microblogging tool * - * class for an exception when the user profile is missing + * Class for an exception when the user profile is missing * * PHP version 5 * @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Class for an exception when the user profile is missing @@ -41,9 +39,9 @@ if (!defined('STATUSNET')) { * @link http://status.net/ */ -class UserNoProfileException extends ServerException +class UserNoProfileException extends NoProfileException { - var $user = null; + protected $user = null; /** * constructor @@ -51,7 +49,7 @@ class UserNoProfileException extends ServerException * @param User $user User that's missing a profile */ - public function __construct($user) + public function __construct(User $user) { $this->user = $user; @@ -60,7 +58,7 @@ class UserNoProfileException extends ServerException $message = sprintf(_('User %1$s (%2$d) has no profile record.'), $user->nickname, $user->id); - parent::__construct($message); + parent::__construct($user->id, $message); } /**