Mnemo::countMemos PHP Method

countMemos() public static method

Returns the number of notes in notepads that the current user owns.
public static countMemos ( ) : integer
return integer The number of notes that the user owns.
    public static function countMemos()
    {
        static $count;
        if (isset($count)) {
            return $count;
        }
        $notepads = self::listNotepads(true, Horde_Perms::ALL);
        $count = 0;
        foreach (array_keys($notepads) as $notepad) {
            $storage = $GLOBALS['injector']->getInstance('Mnemo_Factory_Driver')->create($notepad);
            $storage->retrieve();
            $count += count($storage->listMemos());
        }
        return $count;
    }

Usage Example

コード例 #1
0
ファイル: Application.php プロジェクト: horde/horde
 /**
  * Add additional items to the sidebar.
  *
  * @param Horde_View_Sidebar $sidebar  The sidebar object.
  */
 public function sidebar($sidebar)
 {
     $perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
     if (Mnemo::getDefaultNotepad(Horde_Perms::EDIT) && ($perms->hasAppPermission('max_notes') === true || $perms->hasAppPermission('max_notes') > Mnemo::countMemos())) {
         $sidebar->addNewButton(_("_New Note"), Horde::url('memo.php')->add('actionID', 'add_memo'));
     }
     $url = Horde::url('');
     $edit = Horde::url('notepads/edit.php');
     $user = $GLOBALS['registry']->getAuth();
     $sidebar->containers['my'] = array('header' => array('id' => 'mnemo-toggle-my', 'label' => _("My Notepads"), 'collapsed' => false));
     if (!$GLOBALS['prefs']->isLocked('default_notepad')) {
         $sidebar->containers['my']['header']['add'] = array('url' => Horde::url('notepads/create.php'), 'label' => _("Create a new Notepad"));
     }
     $sidebar->containers['shared'] = array('header' => array('id' => 'mnemo-toggle-shared', 'label' => _("Shared Notepads"), 'collapsed' => true));
     foreach (Mnemo::listNotepads() as $name => $notepad) {
         $url->add(array('display_notepad' => $name, 'actionID' => in_array($name, $GLOBALS['display_notepads']) ? 'remove_displaylist' : 'add_displaylist'));
         $row = array('selected' => in_array($name, $GLOBALS['display_notepads']), 'url' => $url, 'label' => Mnemo::getLabel($notepad), 'color' => $notepad->get('color') ?: '#dddddd', 'edit' => $edit->add('n', $notepad->getName()), 'type' => 'checkbox');
         if ($notepad->get('owner') == $user) {
             $sidebar->addRow($row, 'my');
         } else {
             $sidebar->addRow($row, 'shared');
         }
     }
 }
All Usage Examples Of Mnemo::countMemos