本文整理汇总了PHP中Collection::create_from_template方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::create_from_template方法的具体用法?PHP Collection::create_from_template怎么用?PHP Collection::create_from_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::create_from_template方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copy_collections
/**
* Makes a literal copy of a list of collections for this user.
*
* @param array $templateids A list of collectionids to copy.
*/
public function copy_collections($templateids, $checkviewaccess = true)
{
if (!$templateids) {
// Nothing to do
return;
}
if (!is_array($templateids)) {
throw new SystemException('User->copy_collections: templateids must be a list of templates to copy for the user');
}
require_once get_config('libroot') . 'collection.php';
$collections = array();
$results = get_records_select_array('collection', 'id IN (' . implode(', ', db_array_to_ph($templateids)) . ')', $templateids, '', 'id, name');
foreach ($results as $result) {
$collections[$result->id] = $result;
}
db_begin();
foreach ($templateids as $tid) {
Collection::create_from_template(array('owner' => $this->get('id'), 'title' => $collections[$tid]->name), $tid, $this->get('id'), $checkviewaccess);
}
db_commit();
}
示例2: group_create
//.........这里部分代码省略.........
$data['hidemembersfrommembers'] = isset($data['hidemembersfrommembers']) ? intval($data['hidemembersfrommembers']) : 0;
$data['groupparticipationreports'] = isset($data['groupparticipationreports']) ? intval($data['groupparticipationreports']) : 0;
$data['usersautoadded'] = isset($data['usersautoadded']) ? intval($data['usersautoadded']) : 0;
$data['quota'] = get_config_plugin('artefact', 'file', 'defaultgroupquota');
if (!empty($data['invitefriends']) && !empty($data['suggestfriends'])) {
throw new InvalidArgumentException("group_create: a group cannot enable both invitefriends and suggestfriends");
}
$data['invitefriends'] = isset($data['invitefriends']) ? intval($data['invitefriends']) : 0;
$data['suggestfriends'] = isset($data['suggestfriends']) ? intval($data['suggestfriends']) : 0;
if (isset($data['shortname']) && strlen($data['shortname'])) {
// This is a group whose details and membership can be updated automatically, using a
// webservice api or possibly csv upload.
// On updates to this group, it will be identified using the institution and shortname
// which must be unique.
// The $USER object will be set to someone with at least institutional admin permission.
global $USER;
if (empty($data['institution'])) {
throw new SystemException("group_create: a group with a shortname must have an institution; shortname: " . $data['shortname']);
}
if (!$USER->can_edit_institution($data['institution'])) {
throw new AccessDeniedException("group_create: cannot create a group in this institution");
}
if (!preg_match('/^[a-zA-Z0-9_.-]{2,255}$/', $data['shortname'])) {
$message = get_string('invalidshortname', 'group') . ': ' . $data['shortname'];
$message .= "\n" . get_string('shortnameformat', 'group');
throw new UserException($message);
}
if (record_exists('group', 'shortname', $data['shortname'], 'institution', $data['institution'])) {
throw new UserException('group_create: group with shortname ' . $data['shortname'] . ' and institution ' . $data['institution'] . ' already exists');
}
if (empty($data['members'])) {
$data['members'] = array($USER->get('id') => 'admin');
}
} else {
if (!empty($data['institution'])) {
throw new SystemException("group_create: group institution only available for api-controlled groups");
}
$data['shortname'] = null;
}
if (get_config('cleanurls') && (!isset($data['urlid']) || strlen($data['urlid']) == 0)) {
$data['urlid'] = generate_urlid($data['name'], get_config('cleanurlgroupdefault'), 3, 30);
$data['urlid'] = group_get_new_homepage_urlid($data['urlid']);
}
if (!is_array($data['members']) || count($data['members']) == 0) {
throw new InvalidArgumentException("group_create: at least one member must be specified for adding to the group");
}
if (!isset($data['submittableto'])) {
$data['submittableto'] = $data['grouptype'] != 'standard';
}
if (!isset($data['editroles'])) {
$data['editroles'] = $data['grouptype'] == 'standard' ? 'all' : 'notmember';
} else {
if (!in_array($data['editroles'], array_keys(group_get_editroles_options()))) {
throw new InvalidArgumentException("group_create: invalid option for page editroles setting");
}
}
if (!isset($data['editwindowstart'])) {
$data['editwindowstart'] = null;
}
if (!isset($data['editwindowend'])) {
$data['editwindowend'] = null;
}
if (!isset($data['sendnow'])) {
$data['sendnow'] = null;
}
db_begin();
$id = insert_record('group', (object) array('name' => $data['name'], 'description' => isset($data['description']) ? $data['description'] : null, 'urlid' => isset($data['urlid']) ? $data['urlid'] : null, 'grouptype' => $data['grouptype'], 'category' => isset($data['category']) ? intval($data['category']) : null, 'jointype' => $jointype, 'ctime' => $data['ctime'], 'mtime' => $data['ctime'], 'public' => $data['public'], 'usersautoadded' => $data['usersautoadded'], 'quota' => $data['quota'], 'institution' => !empty($data['institution']) ? $data['institution'] : null, 'shortname' => $data['shortname'], 'request' => isset($data['request']) ? intval($data['request']) : 0, 'submittableto' => intval($data['submittableto']), 'allowarchives' => !empty($data['submittableto']) && !empty($data['allowarchives']) ? intval($data['allowarchives']) : 0, 'editroles' => $data['editroles'], 'hidden' => $data['hidden'], 'hidemembers' => $data['hidemembers'], 'hidemembersfrommembers' => $data['hidemembersfrommembers'], 'groupparticipationreports' => $data['groupparticipationreports'], 'invitefriends' => $data['invitefriends'], 'suggestfriends' => $data['suggestfriends'], 'editwindowstart' => $data['editwindowstart'], 'editwindowend' => $data['editwindowend'], 'sendnow' => isset($data['sendnow']) ? $data['sendnow'] : null, 'viewnotify' => isset($data['viewnotify']) ? $data['viewnotify'] : null, 'feedbacknotify' => isset($data['feedbacknotify']) ? $data['feedbacknotify'] : null), 'id', true);
foreach ($data['members'] as $userid => $role) {
insert_record('group_member', (object) array('group' => $id, 'member' => $userid, 'role' => $role, 'ctime' => $data['ctime']));
}
// Copy views for the new group
$templates = get_column('view_autocreate_grouptype', 'view', 'grouptype', $data['grouptype']);
$templates = get_records_sql_array("\n SELECT v.id, v.title, v.description\n FROM {view} v\n INNER JOIN {view_autocreate_grouptype} vag ON vag.view = v.id\n LEFT JOIN {collection_view} cv ON v.id = cv.view\n WHERE vag.grouptype = 'standard'\n AND cv.view IS NULL", array());
if ($templates) {
require_once get_config('libroot') . 'view.php';
foreach ($templates as $template) {
list($view) = View::create_from_template(array('group' => $id, 'title' => $template->title, 'description' => $template->description), $template->id, null, false);
$view->set_access(array(array('type' => 'group', 'id' => $id, 'startdate' => null, 'stopdate' => null, 'role' => null)));
}
}
// Copy collections for the new group
$templates = get_records_sql_array("\n SELECT DISTINCT c.id, c.name\n FROM {view} v\n INNER JOIN {view_autocreate_grouptype} vag ON vag.view = v.id\n INNER JOIN {collection_view} cv ON v.id = cv.view\n INNER JOIN {collection} c ON cv.collection = c.id\n WHERE vag.grouptype = ?", array($data['grouptype']));
if ($templates) {
require_once 'collection.php';
foreach ($templates as $template) {
Collection::create_from_template(array('group' => $id), $template->id, null, false, true);
}
}
$data['id'] = $id;
// install the homepage
if ($t = get_record('view', 'type', 'grouphomepage', 'template', 1, 'owner', 0)) {
require_once 'view.php';
$template = new View($t->id, (array) $t);
list($homepage) = View::create_from_template(array('group' => $id, 'title' => $template->get('title'), 'description' => $template->get('description'), 'type' => 'grouphomepage'), $t->id, 0, false);
}
insert_record('view_access', (object) array('view' => $homepage->get('id'), 'accesstype' => $data['public'] ? 'public' : 'loggedin', 'ctime' => db_format_timestamp(time())));
handle_event('creategroup', $data);
db_commit();
return $id;
}
示例3: copyview
/**
* Copy a view via a 'copy' url
* Currently for copying a page via a 'copy' button on view/view.php
*
* @param integer $id View id
* @param bool $istemplate (optional) If you want to mark as template
* @param integer $groupid (optional) The group to copy the view to
* @param integer $collectionid (optional) Provide the collection id to indicate we want
* to copy collection the view belongs to
*/
function copyview($id, $istemplate = false, $groupid = null, $collectionid = null)
{
global $USER, $SESSION;
// check that the user can copy view
$view = new View($id);
if (!$view->is_copyable()) {
throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
}
// set up a packet of values to send to the create_from_template function
$values = array('new' => 1, 'owner' => $USER->get('id'), 'template' => (int) $istemplate);
if (!empty($groupid) && is_int($groupid)) {
$values['group'] = $groupid;
}
if (!empty($collectionid)) {
require_once get_config('libroot') . 'collection.php';
list($collection, $template, $copystatus) = Collection::create_from_template($values, $collectionid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('collectioncopywouldexceedquota', 'collection'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
}
$SESSION->add_ok_msg(get_string('copiedpagesblocksandartefactsfromtemplate', 'collection', $copystatus['pages'], $copystatus['blocks'], $copystatus['artefacts'], $template->get('name')));
redirect(get_config('wwwroot') . 'collection/edit.php?copy=1&id=' . $collection->get('id'));
} else {
list($view, $template, $copystatus) = View::create_from_template($values, $id);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view'));
redirect(get_config('wwwroot') . 'view/view.php?id=' . $id);
}
$SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view', $copystatus['blocks'], $copystatus['artefacts'], $template->get('title')));
redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id'));
}
}
示例4: createview_submit
function createview_submit(Pieform $form, $values)
{
global $SESSION;
$values['template'] = !empty($values['istemplate']) ? 1 : 0;
// Named 'istemplate' in the form to prevent confusion with 'usetemplate'
if (!empty($values['submitcollection'])) {
require_once get_config('libroot') . 'collection.php';
$templateid = $values['copycollection'];
unset($values['copycollection']);
unset($values['usetemplate']);
list($collection, $template, $copystatus) = Collection::create_from_template($values, $templateid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('collectioncopywouldexceedquota', 'collection'));
redirect(get_config('wwwroot') . 'view/choosetemplate.php');
}
$SESSION->add_ok_msg(get_string('copiedpagesblocksandartefactsfromtemplate', 'collection', $copystatus['pages'], $copystatus['blocks'], $copystatus['artefacts'], $template->get('name')));
redirect(get_config('wwwroot') . 'collection/edit.php?copy=1&id=' . $collection->get('id'));
} else {
if (isset($values['usetemplate'])) {
$templateid = $values['usetemplate'];
unset($values['usetemplate']);
list($view, $template, $copystatus) = View::create_from_template($values, $templateid);
if (isset($copystatus['quotaexceeded'])) {
$SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view'));
redirect(get_config('wwwroot') . 'view/choosetemplate.php');
}
$SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view', $copystatus['blocks'], $copystatus['artefacts'], $template->get('title')));
} else {
$view = View::create($values);
}
}
redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id'));
}