/** * Remove star from a given object * * @param ProjectObject $object * @param User $user * @return boolean */ function unstarObject($object, $user) { if (!$object->canView($user)) { return false; } // if if (StarredObjects::isStarred($object, $user)) { $cache_id = 'object_starred_by_' . $user->getId(); $starred_objects = cache_get($cache_id); if (!is_array($starred_objects)) { $starred_objects = StarredObjects::findObjectIdsByUser($user); } // if // Not starred? if (!in_array($object->getId(), $starred_objects)) { return true; } // if $execute = db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE object_id = ? AND user_id = ?', $object->getId(), $user->getId()); if ($execute && !is_error($execute)) { unset($starred_objects[array_search($object->getId(), $starred_objects)]); cache_set($cache_id, $starred_objects); } // if return $execute; } // if return true; }
/** * Return array of object options * * @param User $user * @return NamedList */ function getOptions($user) { if (!isset($this->options[$user->getId()])) { $options = new NamedList(); if ($this->canEdit($user)) { $options->add('edit', array('url' => $this->getEditUrl(), 'text' => lang('Edit'))); } // if if ($this->can_have_comments && $this->canChangeLockedState($user)) { if ($this->getIsLocked()) { $options->addAfter('unlock', array('url' => $this->getUnlockUrl(), 'text' => lang('Unlock Comments'), 'method' => 'post'), 'star'); } else { $options->addAfter('lock', array('url' => $this->getLockUrl(), 'text' => lang('Lock Comments'), 'method' => 'post'), 'star'); } // if } // if if (StarredObjects::isStarred($this, $user)) { $options->add('unstar', array('text' => lang('Unstar'), 'url' => $this->getUnstarUrl(), 'method' => 'post')); } else { $options->add('star', array('text' => lang('Star'), 'url' => $this->getStarUrl(), 'method' => 'post')); } // if if ($this->canMove($user)) { $options->add('move_to_project', array('text' => lang('Move to Project'), 'url' => $this->getMoveUrl())); } // if if ($this->canCopy($user)) { $options->add('copy_to_project', array('text' => lang('Copy to Project'), 'url' => $this->getCopyUrl())); } // if if ($this->canDelete($user)) { if ($this->getState() == STATE_DELETED) { $options->add('restore_from_trash', array('text' => lang('Restore from Trash'), 'url' => $this->getUntrashUrl(), 'method' => 'post')); } else { $options->add('move_to_trash', array('text' => lang('Move to Trash'), 'url' => $this->getTrashUrl(), 'method' => 'post')); } // if } // if if ($this->canChangeCompleteStatus($user)) { if ($this->isCompleted()) { $options->add('reopen', array('text' => lang('Reopen'), 'url' => $this->getOpenUrl(), 'method' => 'post')); } else { $options->add('complete', array('text' => lang('Complete'), 'url' => $this->getCompleteUrl(), 'method' => 'post')); } // if } // if if ($this->canSubscribe($user)) { if (Subscriptions::isSubscribed($user, $this)) { $options->add('unsubscribe', array('text' => lang('Unsubscribe'), 'url' => $this->getUnsubscribeUrl(), 'method' => 'post')); } else { $options->add('subscribe', array('text' => lang('Subscribe'), 'url' => $this->getSubscribeUrl(), 'method' => 'post')); } // if } // if if ($this->canEdit($user)) { if ($this->can_have_subscribers) { $options->add('manage_subscriptions', array('text' => lang('Manage Subscriptions'), 'url' => $this->getSubscriptionsUrl())); } // if if ($this->can_have_attachments) { $options->add('manage_attachments', array('text' => lang('Manage Attachments'), 'url' => $this->getAttachmentsUrl())); } // if } // if event_trigger('on_project_object_options', array(&$options, $this, $user)); $this->options[$user->getId()] = $options; } // if return $this->options[$user->getId()]; }