<?php /** * Pages function library */ if (isset($_POST['action'])) { if ($_POST['action'] == 'getOpis') { get_opis($_POST['projectId'], true); } } /** * Prepare the add/edit form variables * * @param ElggObject $project * @return array */ function projects_prepare_form_vars($project = null, $parent_guid = 0) { // input names => defaults $values = array('title' => '', 'description' => '', 'project_type' => '', 'cost' => '', 'organization' => '', 'funding' => '', 'status' => '', 'start_date' => '', 'end_date' => '', 'assigned_to[]' => '', 'access_id' => ACCESS_DEFAULT, 'write_access_id' => ACCESS_DEFAULT, 'tags' => '', 'upload' => '', 'container_guid' => elgg_get_page_owner_guid(), 'guid' => null, 'entity' => $project, 'parent_guid' => $parent_guid); if ($project) { foreach (array_keys($values) as $field) { if (isset($project->{$field})) { $values[$field] = $project->{$field}; } } $opis = elgg_get_entities_from_relationship(array("relationship" => "opi", "relationship_guid" => $project->guid, "inverse_relationship" => true)); $values['opis'] = $opis; } if (elgg_is_sticky_form('project')) { $sticky_values = elgg_get_sticky_values('project');
} } // need to add check to make sure user can write to container $project->container_guid = $container_guid; if ($parent_guid) { $project->parent_guid = $parent_guid; } //first opi is the project owner error_log((int) $opis[0]); $project->container_guid = (int) $opis[0]; $project->access_id = (int) 1; if ($project->save()) { //create opi relationships if ($opis) { //remove old opis first if ($oldOpis = get_opis($project->guid)) { foreach ($oldOpis as $oldOpi) { if (!in_array($oldOpi, $opis)) { remove_entity_relationship($oldOpi->guid, "opi", $project->guid); } } } foreach ($opis as $opi) { $user = get_entity($opi); if ($user) { $user->addRelationship($project->guid, 'opi'); } else { register_error("Problem registering OPI's with project."); forward(REFERER); } }
<?php $variables = elgg_get_config('projects'); //check for opis $opis = get_opis($vars['guid']); foreach ($variables as $name => $type) { ?> <div> <?php if ($name == 'assigned_to[]') { ?> <label><?php echo elgg_echo("projects:assigned_to"); ?> </label> <a class="add-opi" href="#"><?php echo elgg_echo('projects:addOpi'); ?> </a> <?php } else { ?> <label><?php echo elgg_echo("projects:{$name}"); ?> </label> <?php } if ($type == 'file') { echo elgg_view("input/file", array('name' => 'upload[]', 'multiple' => true)); } elseif ($type == 'assign_to') {
<?php /** * Page attachments * * Display attachments for a project * * @package ElggPages * * @uses $vars['projectId'] */ $projectId = $vars['projectId']; $opis = get_opis($projectId); if ($opis) { $content = "<p class='label'>OPI's</p>"; foreach ($opis as $opi) { $content .= elgg_view_entity($opi, array('full_view' => false)); } } echo $content;