本文整理汇总了PHP中Kronolith::getDriver方法的典型用法代码示例。如果您正苦于以下问题:PHP Kronolith::getDriver方法的具体用法?PHP Kronolith::getDriver怎么用?PHP Kronolith::getDriver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kronolith
的用法示例。
在下文中一共展示了Kronolith::getDriver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addResource
/**
* Adds a new resource to storage
*
* @param Kronolith_Resource_Base $resource
*
* @return unknown_type
*/
public static function addResource(Kronolith_Resource_Base $resource)
{
// Create a new calendar id.
$calendar = uniqid(mt_rand());
$resource->set('calendar', $calendar);
$driver = Kronolith::getDriver('Resource');
return $driver->save($resource);
}
示例2: setUpBeforeClass
public static function setUpBeforeClass()
{
return;
parent::setUpBeforeClass();
self::createKolabShares(self::$setup);
list($share, $other_share) = self::_createDefaultShares();
self::$driver = Kronolith::getDriver('Kolab', $share->getName());
self::$type = 'Kolab';
}
示例3: setUpBeforeClass
public static function setUpBeforeClass()
{
self::$callback = array(__CLASS__, 'getDb');
parent::setUpBeforeClass();
$migrator = new Horde_Db_Migration_Migrator($GLOBALS['injector']->getInstance('Horde_Db_Adapter'), null, array('migrationsPath' => __DIR__ . '/../../../../../../migration', 'schemaTableName' => 'kronolith_test_schema'));
$migrator->up();
list($share, $other_share) = self::_createDefaultShares();
self::$driver = Kronolith::getDriver('Sql', $share->getName());
self::$type = 'Sql';
}
示例4: execute
/**
* @throws Kronolith_Exception
*/
public function execute()
{
switch ($this->_vars->submitbutton) {
case _("Save"):
$new_name = $this->_vars->get('name');
$this->_resource->set('name', $new_name);
$this->_resource->set('description', $this->_vars->get('description'));
$this->_resource->set('response_type', $this->_vars->get('responsetype'));
$this->_resource->set('email', $this->_vars->get('email'));
/* Update group memberships */
$driver = Kronolith::getDriver('Resource');
$existing_groups = $driver->getGroupMemberships($this->_resource->getId());
$new_groups = $this->_vars->get('category');
$new_groups = is_null($new_groups) ? array() : $new_groups;
foreach ($existing_groups as $gid) {
$i = array_search($gid, $new_groups);
if ($i === false) {
// No longer in this group
$group = $driver->getResource($gid);
$members = $group->get('members');
$idx = array_search($this->_resource->getId(), $members);
if ($idx !== false) {
unset($members[$idx]);
reset($members);
$group->set('members', $members);
$group->save();
}
} else {
// We know it's already in the group, remove it so we don't
// have to check/add it again later.
unset($new_groups[$i]);
}
}
reset($new_groups);
foreach ($new_groups as $gid) {
$group = $driver->getResource($gid);
$members = $group->get('members');
$members[] = $this->_resource->getId();
$group->set('members', $members);
$group->save();
}
try {
$this->_resource->save();
} catch (Exception $e) {
throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage()));
}
return $this->_resource;
case _("Delete"):
Horde::url('resources/delete.php')->add('c', $this->_vars->c)->redirect();
break;
case _("Cancel"):
Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)->redirect();
break;
}
}
示例5: _handleAutoCompleter
/**
*/
protected function _handleAutoCompleter($input)
{
$ret = array();
// For now, return all resources.
$resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array(), 'name');
foreach ($resources as $r) {
if (strpos(Horde_String::lower($r->get('name')), Horde_String::lower($input)) !== false) {
$ret[] = array('name' => $r->get('name'), 'code' => $r->getId());
}
}
return $ret;
}
示例6: __construct
/**
* @throws Kronolith_Exception
*/
public function __construct($vars)
{
parent::__construct($vars, _("Create Resource Group"));
$resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array('isgroup' => 0));
$enum = array();
foreach ($resources as $resource) {
$enum[$resource->getId()] = htmlspecialchars($resource->get('name'));
}
$this->addVariable(_("Name"), 'name', 'text', true);
$this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
$this->addVariable(_("Resources"), 'members', 'multienum', false, false, null, array('enum' => $enum));
$this->setButtons(array(_("Create")));
}
示例7: initialize
/**
* Attempts to open a connection to the SQL server.
*
* @throws Kronolith_Exception
*/
public function initialize()
{
if (empty($this->_params['db'])) {
throw new InvalidArgumentException('Missing required Horde_Db_Adapter instance');
}
try {
$this->_db = $this->_params['db'];
} catch (Horde_Exception $e) {
throw new Kronolith_Exception($e);
}
$this->_params = array_merge(array('table' => 'kronolith_resources'), $this->_params);
$this->_driver = Kronolith::getDriver();
$this->_columns = $this->_db->columns($this->_params['table']);
}
示例8: __construct
/**
* @throws Kronolith_Exception
*/
public function __construct($vars, $resource)
{
$this->_resource = $resource;
parent::__construct($vars, sprintf(_("Edit %s"), $resource->get('name')));
$resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array('isgroup' => 0));
$enum = array();
foreach ($resources as $r) {
$enum[$r->getId()] = htmlspecialchars($r->get('name'));
}
$this->addHidden('', 'c', 'text', true);
$this->addVariable(_("Name"), 'name', 'text', true);
$this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
$this->addVariable(_("Resources"), 'members', 'multienum', false, false, null, array('enum' => $enum));
$this->setButtons(array(_("Save"), array('class' => 'horde-delete', 'value' => _("Delete")), array('class' => 'horde-cancel', 'value' => _("Cancel"))));
}
示例9: execute
/**
* @throws Kronolith_Exception
*/
public function execute()
{
if ($this->_vars->get('submitbutton') == _("Cancel")) {
Horde::url($GLOBALS['prefs']->getValue('defaultview') . '.php', true)->redirect();
}
if (!$this->_resource->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
throw new Kronolith_Exception(_("Permission denied"));
}
// Delete the resource.
try {
Kronolith::getDriver('Resource')->delete($this->_resource);
} catch (Exception $e) {
throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $e->getMessage()));
}
}
示例10: execute
/**
* @throws Kronolith_Exception
*/
public function execute()
{
$new = array('name' => $this->_vars->get('name'), 'description' => $this->_vars->get('description'), 'response_type' => $this->_vars->get('responsetype'), 'email' => $this->_vars->get('email'));
$resource = Kronolith_Resource::addResource(new Kronolith_Resource_Single($new));
/* Do we need to add this to any groups? */
$groups = $this->_vars->get('category');
if (!empty($groups)) {
foreach ($groups as $group_id) {
$group = Kronolith::getDriver('Resource')->getResource($group_id);
$members = $group->get('members');
$members[] = $resource->getId();
$group->set('members', $members);
$group->save();
}
}
}
示例11: search
/**
* Searches for resources that are tagged with all of the requested tags.
*
* @param array $tags Either a tag_id, tag_name or an array.
* @param array $filter Array of filter parameters.
* - type (string) - only return either events or
* calendars, not both.
* - user (array) - only include objects owned by
* these users.
* - calendar (array) - restrict to events contained
* in these calendars.
*
* @return A hash of 'calendars' and 'events' that each contain an array
* of calendar_ids and event_uids respectively.
*/
public function search($tags, $filter = array())
{
$args = array();
/* These filters are mutually exclusive */
if (array_key_exists('user', $filter)) {
/* semi-hack to see if we are querying for a system-owned share -
* will need to get the list of all system owned shares and query
* using a calendar filter instead of a user filter. */
if (empty($filter['user'])) {
// @TODO: No way to get only the system shares the current
// user can see?
$calendars = $GLOBALS['injector']->getInstance('Kronolith_Shares')->listSystemShares();
$args['calendarId'] = array();
foreach ($calendars as $name => $share) {
if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
$args['calendarId'][] = $name;
}
}
} else {
// Items owned by specific user(s)
$args['userId'] = $filter['user'];
}
} elseif (!empty($filter[self::TYPE_CALENDAR])) {
// Only events located in specific calendar(s)
if (!is_array($filter[self::TYPE_CALENDAR])) {
$filter[self::TYPE_CALENDAR] = array($filter[self::TYPE_CALENDAR]);
}
$args['calendarId'] = $filter[self::TYPE_CALENDAR];
}
/* Add the tags to the search */
$args['tagId'] = $GLOBALS['injector']->getInstance('Content_Tagger')->getTagIds($tags);
/* Restrict to events or calendars? */
$cal_results = $event_results = array();
if (empty($filter['type']) || $filter['type'] == self::TYPE_CALENDAR) {
$args['typeId'] = $this->_type_ids[self::TYPE_CALENDAR];
$cal_results = $GLOBALS['injector']->getInstance('Content_Tagger')->getObjects($args);
}
if (empty($filter['type']) || $filter['type'] == 'event') {
$args['typeId'] = $this->_type_ids['event'];
$event_results = $GLOBALS['injector']->getInstance('Content_Tagger')->getObjects($args);
}
$results = array('calendars' => array_values($cal_results), 'events' => !empty($args['calendarId']) && count($event_results) ? Kronolith::getDriver()->filterEventsByCalendar(array_values($event_results), $args['calendarId']) : array_values($event_results));
return $results;
}
示例12: execute
/**
* Purge old events.
*
* @throws Kronolith_Exception
* @throws Horde_Exception_NotFound
*/
public function execute()
{
/* Get the current time minus the number of days specified in
* 'purge_events_keep'. An event will be deleted if it has an end
* time prior to this time. */
$del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
$del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep');
/* Need to have Horde_Perms::DELETE on a calendar to delete events
* from it */
$calendars = Kronolith::listInternalCalendars(true, Horde_Perms::DELETE);
/* Start building the search */
$kronolith_driver = Kronolith::getDriver();
$query = new StdClass();
$query->start = null;
$query->end = $del_time;
$query->status = null;
$query->calendars = array(Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']) => array_keys($calendars));
$query->creator = $GLOBALS['registry']->getAuth();
/* Perform the search */
$days = Kronolith::search($query);
$count = 0;
foreach ($days as $events) {
foreach ($events as $event) {
/* Delete if no recurrence, or if we are past the last occurence */
if (!$event->recurs() || $event->recurrence->nextRecurrence($del_time) == false) {
if ($event->calendar != $kronolith_driver->calendar) {
$kronolith_driver->open($event->calendar);
}
try {
$kronolith_driver->deleteEvent($event->id, true);
++$count;
} catch (Exception $e) {
Horde::log($e, 'ERR');
throw $e;
}
}
}
}
$GLOBALS['notification']->push(sprintf(ngettext("Deleted %d event older than %d days.", "Deleted %d events older than %d days.", $count), $count, $GLOBALS['prefs']->getValue('purge_events_keep')));
}
示例13: isFree
/**
* Determine if the resource is free during the time period for the
* supplied event.
*
* @param Kronolith_Event $event The event to check availability for.
*
* @return boolean
* @throws Kronolith_Exception
*/
public function isFree(Kronolith_Event $event)
{
/* Fetch Events */
$busy = Kronolith::getDriver('Resource', $this->get('calendar'))->listEvents($event->start, $event->end, array('show_recurrence' => true));
/* No events at all during time period for requested event */
if (!count($busy)) {
return true;
}
/* Check for conflicts, ignoring the conflict if it's for the
* same event that is passed. */
foreach ($busy as $events) {
foreach ($events as $e) {
if (!($e->status == Kronolith::STATUS_CANCELLED || $e->status == Kronolith::STATUS_FREE) && $e->uid !== $event->uid) {
// Comparing to zero allows the events to start at the same
// the previous event ends.
if (!($e->start->compareDateTime($event->end) >= 0) && !($e->end->compareDateTime($event->start) <= 0)) {
return false;
}
}
}
}
return true;
}
示例14: readForm
//.........这里部分代码省略.........
if ($end_hour != 12) {
$end_hour += 12;
}
} elseif ($end_hour == 12) {
$end_hour = 0;
}
}
$this->end = new Horde_Date(array('hour' => $end_hour, 'min' => $end_min, 'month' => $end_month, 'mday' => $end_day, 'year' => $end_year), $this->timezone);
if ($this->end->compareDateTime($this->start) < 0) {
$this->end = new Horde_Date($this->start);
}
}
$this->allday = false;
// Alarm.
if (!is_null($alarm = Horde_Util::getFormData('alarm'))) {
if ($alarm) {
$value = Horde_Util::getFormData('alarm_value');
$unit = Horde_Util::getFormData('alarm_unit');
if ($value == 0) {
$value = $unit = 1;
}
$this->alarm = $value * $unit;
// Notification.
if (Horde_Util::getFormData('alarm_change_method')) {
$types = Horde_Util::getFormData('event_alarms');
$methods = array();
if (!empty($types)) {
foreach ($types as $type) {
$methods[$type] = array();
switch ($type) {
case 'notify':
$methods[$type]['sound'] = Horde_Util::getFormData('event_alarms_sound');
break;
case 'mail':
$methods[$type]['email'] = Horde_Util::getFormData('event_alarms_email');
break;
case 'popup':
break;
}
}
}
$this->methods = $methods;
} else {
$this->methods = array();
}
} else {
$this->alarm = 0;
$this->methods = array();
}
}
// Recurrence.
$this->recurrence = $this->readRecurrenceForm($this->start, $this->timezone, $this->recurrence);
// Convert to local timezone.
$this->setTimezone(false);
// Resources
$existingResources = $this->_resources;
if (Horde_Util::getFormData('isajax', false)) {
$resources = array();
} else {
$resources = $session->get('kronolith', 'resources', Horde_Session::TYPE_ARRAY);
}
$newresources = Horde_Util::getFormData('resources');
if (!empty($newresources)) {
foreach (explode(',', $newresources) as $id) {
try {
$resource = Kronolith::getDriver('Resource')->getResource($id);
} catch (Kronolith_Exception $e) {
$GLOBALS['notification']->push($e->getMessage(), 'horde.error');
continue;
}
if (!$resource instanceof Kronolith_Resource_Group || $resource->isFree($this)) {
$resources[$resource->getId()] = array('attendance' => Kronolith::PART_REQUIRED, 'response' => Kronolith::RESPONSE_NONE, 'name' => $resource->get('name'));
} else {
$GLOBALS['notification']->push(_("No resources from this group were available"), 'horde.error');
}
}
}
$this->_resources = $resources;
// Check if we need to remove any resources
$merged = $existingResources + $this->_resources;
$delete = array_diff(array_keys($existingResources), array_keys($this->_resources));
foreach ($delete as $key) {
// Resource might be declined, in which case it won't have the event
// on it's calendar.
if ($merged[$key]['response'] != Kronolith::RESPONSE_DECLINED) {
try {
Kronolith::getDriver('Resource')->getResource($key)->removeEvent($this);
} catch (Kronolith_Exception $e) {
$GLOBALS['notification']->push('foo', 'horde.error');
}
}
}
// Tags.
$this->tags = Horde_Util::getFormData('tags', $this->tags);
// Geolocation
if (Horde_Util::getFormData('lat') && Horde_Util::getFormData('lon')) {
$this->geoLocation = array('lat' => Horde_Util::getFormData('lat'), 'lon' => Horde_Util::getFormData('lon'), 'zoom' => Horde_Util::getFormData('zoom'));
}
$this->initialized = true;
}
示例15: sprintf
if (Kronolith::showAjaxView()) {
Horde::url('', true)->setAnchor('event')->redirect();
}
/* Check permissions. */
$url = Horde::url($prefs->getValue('defaultview') . '.php', true)->add(array('month' => Horde_Util::getFormData('month'), 'year' => Horde_Util::getFormData('year')));
$perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
if ($perms->hasAppPermission('max_events') !== true && $perms->hasAppPermission('max_events') <= Kronolith::countEvents()) {
Horde::permissionDeniedError('kronolith', 'max_events', sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')));
$url->redirect();
}
$display_resource = $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS);
$calendar_id = Horde_Util::getFormData('calendar', empty($display_resource) ? 'internal_' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT) : 'resource_' . $display_resource[0]);
if ($calendar_id == 'internal_' || $calendar_id == 'resource_') {
$url->redirect();
}
$event = Kronolith::getDriver()->getEvent();
$session->set('kronolith', 'attendees', $event->attendees);
$session->set('kronolith', 'resources', $event->getResources());
$date = Horde_Util::getFormData('datetime');
if ($date) {
$event->start = new Horde_Date($date);
} else {
$date = Horde_Util::getFormData('date', date('Ymd')) . '000600';
$event->start = new Horde_Date($date);
if ($prefs->getValue('twentyFour')) {
$event->start->hour = 12;
}
}
$event->end = new Horde_Date($event->start);
if (Horde_Util::getFormData('allday')) {
$event->end->mday++;