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. |
/** * 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'); } } }
} catch (Horde_Exception $e) { if ($data) { $notification->push($e, 'horde.error'); $next_step = $data->cleanup(); } else { $notification->push(_("This file format is not supported."), 'horde.error'); $next_step = Horde_Data::IMPORT_FILE; } } } /* We have a final result set. */ if (is_array($next_step)) { /* Create a Mnemo storage instance. */ $memo_storage = $GLOBALS['injector']->getInstance('Mnemo_Factory_Driver')->create($storage->get('target')); $max_memos = $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes'); $num_memos = Mnemo::countMemos(); foreach ($next_step as $row) { if ($max_memos !== true && $num_memos >= $max_memos) { Horde::permissionDeniedError('mnemo', 'max_notes', sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes'))); break; } /* Check if we need to convert from iCalendar data into an array. */ if ($row instanceof Horde_Icalendar_vnote) { $row = $storage->fromiCalendar($row); } foreach ($app_fields as $field => $null) { if (!isset($row[$field])) { $row[$field] = ''; } } /* Default the tags if there isn't one. */
$storage->move($memo_id, $notepad_target); $storage = $injector->getInstance('Mnemo_Factory_Driver')->create($notepad_target); } } $memo_desc = $storage->getMemoDescription($memo_body); if (!strlen($memo_passphrase) && Horde_Util::getFormData('memo_encrypt') == 'on') { $memo_passphrase = Mnemo::getPassphrase($memo_id); } try { $storage->modify($memo_id, $memo_desc, $memo_body, $memo_tags, $memo_passphrase); } catch (Mnemo_Exception $e) { $haveError = $e->getMessage(); } } else { /* Check permissions. */ if ($injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes') !== true && $injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) { Horde::url('list.php', true)->redirect(); } /* Creating a new note. */ $storage = $injector->getInstance('Mnemo_Factory_Driver')->create($notepad_target); $memo_desc = $storage->getMemoDescription($memo_body); try { $memo_id = $storage->add($memo_desc, $memo_body, $memo_tags, $memo_passphrase); } catch (Mnemo_Exception $e) { $haveError = $e->getMessage(); } } /* Check our results. */ if (!empty($haveError)) { $notification->push(sprintf(_("There was an error saving the note: %s"), $haveError), 'horde.warning'); } else {