/**
 * Build menu
 *
 * @param Menu $menu
 * @param User $user
 * @return array
 */
function status_handle_on_build_menu(&$menu, &$user)
{
    if ($user->isAdministrator() || $user->getSystemPermission('can_use_status_updates')) {
        $last_visit = UserConfigOptions::getValue('status_update_last_visited', $user);
        $menu->addToGroup(array(new MenuItem('status', lang('Status'), assemble_url('status_updates'), get_image_url('icon_menu.gif', STATUS_MODULE), StatusUpdates::countNewMessagesForUser($user, $last_visit))), 'main');
    }
    // if
}
 /**
  * Drop all status messages by parent
  *
  * @param StatusUpdate $parent
  * @return boolean
  */
 function dropByParent($parent)
 {
     return StatusUpdates::delete(array('parent_id = ?', $parent->getId()));
 }
 /**
  * Drop this record from database
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     db_begin_work();
     $delete = parent::delete();
     if ($delete && !is_error($delete)) {
         StatusUpdates::dropByParent($this);
         db_commit();
         return true;
     } else {
         db_rollback();
         return $delete;
     }
     // if
 }
 /**
  * Rss for status updates
  * 
  * @param void
  * @return void
  */
 function rss()
 {
     require_once ANGIE_PATH . '/classes/feed/init.php';
     $archive_url = assemble_url('status_updates');
     $selected_user = $this->request->get('user_id');
     if ($selected_user) {
         if (!in_array($selected_user, $this->logged_user->visibleUserIds())) {
             $this->httpError(HTTP_ERR_FORBIDDEN);
         }
         // if
         $user = Users::findById($selected_user);
         if (!instance_of($user, 'User')) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
         $archive_url = assemble_url('status_updates', array('user_id' => $user->getId()));
         $latest_status_updates = StatusUpdates::findByUser($user, 20);
         $feed = new Feed(lang(":display_name's Status Updates", array('display_name' => $user->getDisplayName())), $archive_url);
     } else {
         $latest_status_updates = StatusUpdates::findVisibleForUser($this->logged_user, 20);
         $feed = new Feed(lang('Status Updates'), $archive_url);
     }
     // if
     if (is_foreachable($latest_status_updates)) {
         foreach ($latest_status_updates as $status_update) {
             $this->smarty->assign(array('status_update' => $status_update));
             $item = new FeedItem(str_excerpt($status_update->getMessage(), 50), $status_update->getViewUrl(), $this->smarty->fetch(get_template_path('feed_item', 'status', STATUS_MODULE)), $status_update->getLastUpdateOn());
             $item->setId($status_update->getId());
             $feed->addItem($item);
         }
         // foreach
     }
     // if
     print render_rss_feed($feed);
     die;
 }