/** * Renders the chart * @param IUser $logged_user * @return string */ function render(IUser $logged_user) { $db_result = DB::execute("SELECT milestone_id, COUNT(*) as count FROM " . TABLE_PREFIX . "project_objects WHERE project_id = ? AND type='Task' AND state >= ? AND visibility >= ? GROUP BY milestone_id", $this->project->getId(), STATE_VISIBLE, $logged_user->getMinVisibility()); $array_result = $db_result instanceof DBResult ? $db_result->toArrayIndexedBy('milestone_id') : false; if (is_foreachable($array_result)) { $pie_chart = new PieChart('400px', '400px', 'milestone_eta_report_pie_chart_placeholder'); $this->serie_array = array(); $this->milestones = array(); // Set data for the rest foreach ($array_result as $serie_data) { $point = new ChartPoint('1', $serie_data['count']); $serie = new ChartSerie($point); if (intval($serie_data['milestone_id'])) { $milestone = new RemediaMilestone(intval($serie_data['milestone_id'])); $label = PieChart::makeShortForPieChart($milestone->getName()); $this->milestones[] = $milestone; } else { $label = lang('No Milestone'); } //if $serie->setOption('label', $label); $this->serie_array[] = $serie; } //foreach $pie_chart->addSeries($this->serie_array); return $pie_chart->render(); } else { return '<p class="empty_slate">' . lang('There are no milestones in this project.') . '</p>'; } //if }
/** * Daily update of repositories * * @param null * @return void */ function source_handle_on_frequently() { require_once ANGIE_PATH . '/classes/xml/xml2array.php'; $results = 'Repositories updated: '; $repositories = Repositories::findByUpdateType(REPOSITORY_UPDATE_FREQUENTLY); foreach ($repositories as $repository) { // don't update projects other than active ones $project = Projects::findById($repository->getProjectId()); if ($project->getStatus() !== PROJECT_STATUS_ACTIVE) { continue; } // if $repository->loadEngine(); $repository_engine = new RepositoryEngine($repository, true); $last_commit = $repository->getLastCommit(); $revision_to = is_null($last_commit) ? 1 : $last_commit->getRevision() + 1; $logs = $repository_engine->getLogs($revision_to); if (!$repository_engine->has_errors) { $repository->update($logs['data']); $total_commits = $logs['total']; $results .= $repository->getName() . ' (' . $total_commits . ' new commits); '; if ($total_commits > 0) { $repository->sendToSubscribers($total_commits, $repository_engine); $repository->createActivityLog($total_commits); } // if } // if } // foreach return is_foreachable($repositories) && count($repositories) > 0 ? $results : 'No repositories for frequently update'; }
/** * List object comments * * Parameters: * * - object - Parent object. It needs to be an instance of ProjectObject class * - comments - List of comments. It is optional. If it is missing comments * will be loaded by calling getCommetns() method of parent object * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_object_comments_all($params, &$smarty) { $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if $logged_user = $smarty->get_template_vars('logged_user'); if (!instance_of($logged_user, 'User')) { return ''; } // if $visiblity = $logged_user->getVisibility(); // if ($object->canView($logged_user) && $object->getVisibility() == VISIBILITY_PRIVATE) { if ($object->canView($logged_user)) { $visiblity = VISIBILITY_PRIVATE; } $comments = $object->getComments($visiblity); if (is_foreachable($comments)) { foreach ($comments as $comment) { ProjectObjectViews::log($comment, $logged_user); //BOF:task_1260 $comment->set_action_request_n_fyi_flag($logged_user); //EOF:task_1260 } // foreach } // if $count_from = 0; $smarty->assign(array('_object_comments_object' => $object, '_object_comments_count_from' => $count_from, '_object_comments_comments' => $comments, '_total_comments' => sizeof($comments))); return $smarty->fetch(get_template_path('_object_comments_all', 'comments', RESOURCES_MODULE)); }
/** * Render select_default_assignment_filter control * * Parameters: * * - user - User - User using the page * - value - integer - ID of selected filter * - optional - boolean - Value is optional? * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_default_assignment_filter($params, &$smarty) { $user = array_var($params, 'user', null, true); $value = array_var($params, 'value', null, true); $optional = array_var($params, 'optional', true, true); $default_filter_id = (int) ConfigOptions::getValue('default_assignments_filter'); $default_filter = $default_filter_id ? AssignmentFilters::findById($default_filter_id) : null; $options = array(); if (instance_of($default_filter, 'AssignmentFilter') && $optional) { $options[] = option_tag(lang('-- System Default (:filter) --', array('filter' => $default_filter->getName())), ''); } // if $grouped_filters = AssignmentFilters::findGrouped($user, true); if (is_foreachable($grouped_filters)) { foreach ($grouped_filters as $group_name => $filters) { $group_options = array(); foreach ($filters as $filter) { $group_options[] = option_tag($filter->getName(), $filter->getId(), array('selected' => $value == $filter->getId())); } // foreach if (count($options) > 0) { $options[] = option_tag('', ''); } // if $options[] = option_group_tag($group_name, $group_options); } // foreach } // if return select_box($options, $params); }
/** * Settings form * * @param void * @return null */ function index() { js_assign('test_svn_url', assemble_url('admin_source_test_svn')); $source_data = $this->request->post('source'); if (!is_foreachable($source_data)) { $source_data = array('svn_path' => ConfigOptions::getValue('source_svn_path'), 'svn_config_dir' => ConfigOptions::getValue('source_svn_config_dir'), 'source_svn_use_output_redirect' => ConfigOptions::getValue('source_svn_use_output_redirect'), 'source_svn_trust_server_cert' => ConfigOptions::getValue('source_svn_trust_server_cert')); } // if if ($this->request->isSubmitted()) { $svn_path = array_var($source_data, 'svn_path', null); $svn_path = $svn_path ? with_slash($svn_path) : null; ConfigOptions::setValue('source_svn_path', $svn_path); $svn_config_dir = array_var($source_data, 'svn_config_dir') == '' ? null : array_var($source_data, 'svn_config_dir'); ConfigOptions::setValue('source_svn_config_dir', $svn_config_dir); $svn_use_output_redirection = array_var($source_data, 'source_svn_use_output_redirect') == "1"; ConfigOptions::setValue('source_svn_use_output_redirect', $svn_use_output_redirection); $svn_trust_server_certificate = array_var($source_data, 'source_svn_trust_server_cert') == "1"; ConfigOptions::setValue('source_svn_trust_server_cert', $svn_trust_server_certificate); flash_success("Source settings successfully saved"); $this->redirectTo('admin_source'); } // if if (!RepositoryEngine::executableExists()) { $this->wireframe->addPageMessage(lang("SVN executable not found. You won't be able to use this module"), 'error'); } // if $this->smarty->assign(array('source_data' => $source_data)); }
/** * Return array of ticket changes * * @param Ticket $ticket * @param integer $count * @return array */ function findByTicket($ticket, $count = null) { $count = (int) $count; if ($count < 1) { $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'ticket_changes WHERE ticket_id = ? ORDER BY version DESC', $ticket->getId()); } else { $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . "ticket_changes WHERE ticket_id = ? ORDER BY version DESC LIMIT 0, {$count}", $ticket->getId()); } // if if (is_foreachable($rows)) { $changes = array(); foreach ($rows as $row) { $change = new TicketChange(); $change->setTicketId($ticket->getId()); $change->setVersion($row['version']); $change->changes = unserialize($row['changes']); $change->created_on = $row['created_on'] ? new DateTimeValue($row['created_on']) : null; $change->created_by_id = (int) $row['created_by_id']; $change->created_by_name = $row['created_by_name']; $change->created_by_email = $row['created_by_email']; $changes[$row['version']] = $change; } // foreach return $changes; } else { return null; } // if }
/** * Join items * * array('Peter', 'Joe', 'Adam') will be join like: * * 'Peter, Joe and Adam * * where separators can be defined as paremeters. * * Parements: * * - items - array of items that need to be join * - separator - used to separate all elements except the last one. ', ' by * default * - final_separator - used to separate last element from the rest of the * string. ' and ' by default * * @param array $params * @return string */ function smarty_function_join($params, &$smarty) { $items = array_var($params, 'items'); $separator = array_var($params, 'separator', ', '); $final_separator = array_var($params, 'final_separator', lang(' and ')); if (is_foreachable($items)) { $result = ''; $items_count = count($items); $counter = 0; foreach ($items as $item) { $counter++; if ($counter < $items_count - 1) { $result .= $item . $separator; } elseif ($counter == $items_count - 1) { $result .= $item . $final_separator; } else { $result .= $item; } // if } // if return $result; } else { return $items; } // if }
/** * Return associative array with config option values by name and given * company * * @param Company $company * @return array */ function getValues($names, $company) { $result = array(); // lets get option definition instances $options = ConfigOptions::findByNames($names, COMPANY_CONFIG_OPTION); if (is_foreachable($options)) { // Now we need all company specific values we can get $values = db_execute_all('SELECT name, value FROM ' . TABLE_PREFIX . 'company_config_options WHERE name IN (?) AND company_id = ?', $names, $company->getId()); $foreachable = is_foreachable($values); // Populate result foreach ($options as $name => $option) { if ($foreachable) { foreach ($values as $record) { if ($record['name'] == $name) { $result[$name] = trim($record['value']) != '' ? unserialize($record['value']) : null; break; } // if } // foreach } // if if (!isset($result[$name])) { $result[$name] = $option->getValue(); } // if } // foreach } // if return $result; }
/** * Render select user control * * Supported paramteres: * * - all HTML attributes * - value - ID of selected user * - project - Instance of selected project, if NULL all users will be listed * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_incoming_mail_select_user($params, &$smarty) { $project = array_var($params, 'project'); if (!instance_of($project, 'Project')) { return new InvalidParamError('object', $project, '$project is expected to be an instance of Project class', true); } // if $users = Users::findForSelect(null, array_var($params, 'project')); $value = array_var($params, 'value', null, true); $options = array(option_tag(lang('Original Author'), 'original_author', $value == 'original_author' ? array('selected' => true) : null)); if (is_foreachable($users)) { foreach ($users as $company_name => $company_users) { $company_options = array(); foreach ($company_users as $user) { $option_attributes = $user['id'] == $value ? array('selected' => true) : null; $company_options[] = option_tag($user['display_name'], $user['id'], $option_attributes); } // foreach $options[] = option_group_tag($company_name, $company_options); } // if } // if return select_box($options, $params); }
/** * Render select parent object for provided project * * Supported paramteres: * * - types - type of of parent objects to be listed * - project - Instance of selected project (required) * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_project_object($params, &$smarty) { $project = array_var($params, 'project'); if (!instance_of($project, 'Project')) { return new InvalidParamError('project', $project, '$project is expected to be an instance of Project class', true); } // if $value = array_var($params, 'value'); unset($params['project']); $types = array_var($params, 'types', null); if (!$types || !is_foreachable($types = explode(',', $types))) { $types = array('ticket', 'file', 'discussion', 'page'); } // if $id_name_map = ProjectObjects::getIdNameMapForProject($project, $types); if (!is_foreachable($id_name_map)) { return false; } // if $sorted = array(); foreach ($id_name_map as $object) { $option_attributes = $value == $object['id'] ? array('selected' => true) : null; $sorted[strtolower($object['type'])][] = option_tag($object['name'], $object['id'], $option_attributes); } // foreach if (is_foreachable($sorted)) { foreach ($sorted as $sorted_key => $sorted_values) { $options[] = option_group_tag($sorted_key, $sorted_values); } // foreach } // if return select_box($options, $params); }
/** * Add sidebars to project overview page * * @param array $sidebars * @param Project $project * @param User $user * @return null */ function system_handle_on_project_overview_sidebars(&$sidebars, &$project, &$user) { // only project leader, system administrators and project manages can see last activity $can_see_last_activity = $user->isProjectLeader($project) || $user->isAdministrator() || $user->isProjectManager(); $project_users = $project->getUsers(); if (is_foreachable($project_users)) { $smarty =& Smarty::instance(); require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php'; require_once SMARTY_PATH . '/plugins/modifier.ago.php'; $output = ''; $sorted_users = Users::groupByCompany($project_users); foreach ($sorted_users as $sorted_user) { $company = $sorted_user['company']; $users = $sorted_user['users']; if (is_foreachable($users)) { $output .= '<h3><a href="' . $company->getViewUrl() . '">' . clean($company->getName()) . '</a></h3>'; $output .= '<ul class="company_users">'; foreach ($users as $current_user) { $last_seen = ''; if ($can_see_last_activity && $user->getId() != $current_user->getId()) { $last_seen = smarty_modifier_ago($current_user->getLastActivityOn()); } // if $output .= '<li><span class="icon_holder"><img src="' . $current_user->getAvatarUrl() . '" /></span> ' . smarty_function_user_link(array('user' => $current_user), $smarty) . ' ' . $last_seen . '</li>'; } // foreach $output .= '</ul>'; } // if } // foreach $sidebars[] = array('label' => lang('People on This Project'), 'is_important' => false, 'id' => 'project_people', 'body' => $output); } // if }
/** * Handle on_project_user_removed event * * @param Project $project * @param User $user * @return null */ function resources_handle_on_project_user_removed($project, $user) { $rows = db_execute('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE project_id = ?', $project->getId()); if (is_foreachable($rows)) { $object_ids = array(); foreach ($rows as $row) { $object_ids[] = (int) $row['id']; } // foreach $user_id = $user->getId(); // Assignments cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'assignments WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); cache_remove('object_assignments_*'); cache_remove('object_assignments_*_rendered'); // Starred objects cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); // Subscriptions cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'subscriptions WHERE user_id = ? AND parent_id IN (?)', $user_id, $object_ids); cache_remove('user_subscriptions_' . $user_id); // remove pinned project PinnedProjects::unpinProject($project, $user); } // if }
/** * Render object subscribers * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_object_subscriptions($params, &$smarty) { $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if js_assign('max_subscribers_count', MAX_SUBSCRIBERS_COUNT); require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php'; $subscribers = $object->getSubscribers(); if (count($subscribers) > MAX_SUBSCRIBERS_COUNT) { $smarty->assign(array('_object_subscriptions_list_subscribers' => false, '_object_subscriptions_object' => $object, '_object_subscriptions_subscribers_count' => count($subscribers), '_object_subscription_brief' => array_var($params, 'brief', false), '_object_subscriptions_popup_url' => assemble_url('object_subscribers_widget', array('object_id' => $object->getId())))); } else { $links = null; if (is_foreachable($subscribers)) { $links = array(); foreach ($subscribers as $subscriber) { $links[] = smarty_function_user_link(array('user' => $subscriber), $smarty); } // foreach } // if $smarty->assign(array('_object_subscriptions_list_subscribers' => true, '_object_subscriptions' => $subscribers, '_object_subscriptions_object' => $object, '_object_subscription_links' => $links, '_object_subscription_brief' => array_var($params, 'brief', false), '_object_subscriptions_popup_url' => assemble_url('object_subscribers_widget', array('object_id' => $object->getId())))); } // if return $smarty->fetch(get_template_path('_object_subscriptions', 'subscriptions', RESOURCES_MODULE)); }
/** * Render pagination block * * Parameters: * * - page - current_page * - total_pages - total pages * - route - route for URL assembly * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_mobile_access_paginator($params, &$smarty) { $url_params = ''; if (is_foreachable($params)) { foreach ($params as $k => $v) { if (strpos($k, 'url_param_') !== false && $v) { $url_params .= '&' . substr($k, 10) . '=' . $v; } // if } // foreach } // if $paginator = array_var($params, 'paginator', new Pager()); $paginator_url = array_var($params, 'url', ROOT_URL); $paginator_anchor = array_var($params, 'anchor', ''); $smarty->assign(array("_mobile_access_paginator_url" => $paginator_url, "_mobile_access_paginator" => $paginator, '_mobile_access_paginator_anchor' => $paginator_anchor, "_mobile_access_paginator_url_params" => $url_params)); $paginator_url = strpos($paginator_url, '?') === false ? $paginator_url . '?' : $paginator_url . '&'; if (!$paginator->isFirst()) { $smarty->assign('_mobile_access_paginator_prev_url', $paginator_url . 'page=' . ($paginator->getCurrentPage() - 1) . $url_params . $paginator_anchor); } // if if (!$paginator->isLast()) { $smarty->assign('_mobile_access_paginator_next_url', $paginator_url . 'page=' . ($paginator->getCurrentPage() + 1) . $url_params . $paginator_anchor); } // if return $smarty->fetch(get_template_path('_paginator', null, MOBILE_ACCESS_MODULE)); }
/** * Render object tasks section * * Parameters: * * - object - Selected project object * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_object_tasks($params, &$smarty) { $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if $open_tasks = $object->getOpenTasks(); if (is_foreachable($open_tasks)) { foreach ($open_tasks as $open_task) { ProjectObjectViews::log($open_task, $smarty->get_template_vars('logged_user')); } // foreach } // if $completed_tasks = $object->getCompletedTasks(COMPLETED_TASKS_PER_OBJECT); if (is_foreachable($completed_tasks)) { foreach ($completed_tasks as $completed_task) { ProjectObjectViews::log($completed_task, $smarty->get_template_vars('logged_user')); } // foreach } // if $smarty->assign(array('_object_tasks_object' => $object, '_object_tasks_open' => $open_tasks, '_object_tasks_can_reorder' => (int) $object->canEdit($smarty->get_template_vars('logged_user')), '_object_tasks_completed' => $completed_tasks, '_object_tasks_completed_remaining' => $object->countCompletedTasks() - COMPLETED_TASKS_PER_OBJECT, '_object_tasks_skip_wrapper' => array_var($params, 'skip_wrapper', false), '_object_tasks_skip_head' => array_var($params, 'skip_head', false), '_object_tasks_force_show' => array_var($params, 'force_show', true))); return $smarty->fetch(get_template_path('_object_tasks', 'tasks', RESOURCES_MODULE)); }
/** * Render object assignees list * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_object_owner($params, &$smarty) { $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if $users_table = TABLE_PREFIX . 'users'; $assignments_table = TABLE_PREFIX . 'assignments'; $rows = db_execute_all("SELECT {$assignments_table}.is_owner AS is_assignment_owner, {$users_table}.id AS user_id, {$users_table}.company_id, {$users_table}.first_name, {$users_table}.last_name, {$users_table}.email FROM {$users_table}, {$assignments_table} WHERE {$users_table}.id = {$assignments_table}.user_id AND {$assignments_table}.object_id = ? and {$assignments_table}.is_owner='1' ORDER BY {$assignments_table}.is_owner DESC", $object->getId()); if (is_foreachable($rows)) { $owner = null; foreach ($rows as $row) { if (empty($row['first_name']) && empty($row['last_name'])) { $user_link = '<a href="' . assemble_url('people_company', array('company_id' => $row['company_id'])) . '#user' . $row['user_id'] . '">' . clean($row['email']) . '</a>'; } else { $user_link = '<a href="' . assemble_url('people_company', array('company_id' => $row['company_id'])) . '#user' . $row['user_id'] . '">' . clean($row['first_name']) . '</a>'; } // if $owner .= $user_link . ' '; } // foreach } // if if (empty($owner)) { $owner = '--'; } // if return $owner; }
/** * Render object assignees list * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_mobile_access_object_assignees($params, &$smarty) { $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if $owner = $object->getResponsibleAssignee(); if (!instance_of($owner, 'User')) { Assignments::deleteByObject($object); return lang('No one is responsible'); } // if require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php'; $other_assignees = array(); $assignees = $object->getAssignees(); if (is_foreachable($assignees)) { foreach ($assignees as $assignee) { if ($assignee->getId() != $owner->getId()) { $other_assignees[] = '<a href="' . mobile_access_module_get_view_url($assignee) . '">' . clean($assignee->getName()) . '</a>'; } // if } // foreach } // if if (count($other_assignees)) { return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '. ' . lang('Other assignees') . ': ' . implode(', ', $other_assignees); } else { return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '.'; } // if }
/** * Render comments * * Parameters: * * - comments - comments that needs to be rendered * - page - current_page * - total_pages - total pages * - counter - counter for comment # * - url - base URL for link assembly * - parent - parent object * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_mobile_access_object_comments($params, &$smarty) { $url_params = ''; if (is_foreachable($params)) { foreach ($params as $k => $v) { if (strpos($k, 'url_param_') !== false && $v) { $url_params .= '&' . substr($k, 10) . '=' . $v; } // if } // foreach } // if $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if $user = array_var($params, 'user'); if (!instance_of($user, 'User')) { return new InvalidParamError('object', $user, '$user is expected to be an instance of User class', true); } // if $page = array_var($params, 'page', 1); $page = (int) array_var($_GET, 'page'); if ($page < 1) { $page = 1; } // if $counter = array_var($params, 'counter', 1); $counter = ($page - 1) * $object->comments_per_page + $counter; list($comments, $pagination) = $object->paginateComments($page, $object->comments_per_page, $user->getVisibility()); $smarty->assign(array("_mobile_access_comments_comments" => $comments, "_mobile_access_comments_paginator" => $pagination, "_mobile_access_comments_url" => mobile_access_module_get_view_url($object), "_mobile_access_comments_url_params" => $url_params, "_mobile_access_comments_counter" => $counter, "_mobile_access_comments_show_counter" => array_var($params, 'show_counter', true))); return $smarty->fetch(get_template_path('_object_comments', null, MOBILE_ACCESS_MODULE)); }
/** * Render object tags * * Parameters: * * - object - Selected object * - project - Selected project, if not present we'll get it from * $object->getProject() * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_object_tags($params, &$smarty) { $object = array_var($params, 'object'); if (!instance_of($object, 'ProjectObject')) { return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true); } // if $project = array_var($params, 'project'); if (!instance_of($project, 'Project')) { $project = $object->getProject(); } // if if (!instance_of($project, 'Project')) { return new InvalidParamError('project', $project, '$project is expected to be an instance of Project class', true); } // if $tags = $object->getTags(); if (is_foreachable($tags)) { $prepared = array(); foreach ($tags as $tag) { if (trim($tag)) { $prepared[] = '<a href="' . Tags::getTagUrl($tag, $project) . '">' . clean($tag) . '</a>'; } // if } // if return implode(', ', $prepared); } else { return '<span class="no_tags">' . lang('-- No tags --') . '</span>'; } // if }
/** * Render select category control * * Supported paramteres: * * - all HTML attributes * - project - Parent project, required * - module - Module * - controller - Controller name * - value - ID of selected category * - optional - If false there will be no -- none -- option * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_category($params, &$smarty) { static $ids = array(); $project = array_var($params, 'project', null, true); if (!instance_of($project, 'Project')) { return new InvalidParamError('project', $project, 'Project parameter is required for select category helper and it needs to be an instance of Project class', true); } // if $user = array_var($params, 'user', null, true); $module = trim(array_var($params, 'module', null, true)); if ($module == '') { return new InvalidParamError('module', $module, 'Module parameter is required for select category helper', true); } // if $controller = trim(array_var($params, 'controller', null, true)); if ($controller == '') { return new InvalidParamError('controller', $controller, 'Controller parameter is required for select category helper', true); } // if $id = array_var($params, 'id', null, true); if (empty($id)) { $counter = 1; do { $id = "select_category_{$counter}"; $counter++; } while (in_array($id, $ids)); } // if $params['id'] = $id; $value = array_var($params, 'value', null, true); $optional = array_var($params, 'optional', true, true); $options = array(); if ($optional) { $options[] = option_tag(lang('-- None --'), ''); } // if $categories = Categories::findByModuleSection($project, $module, $controller); if (is_foreachable($categories)) { foreach ($categories as $category) { $option_attributes = array('class' => 'object_option'); if ($category->getId() == $value) { $option_attributes['selected'] = true; } // if $options[] = option_tag($category->getName(), $category->getId(), $option_attributes); } // foreach } // if if (instance_of($user, 'User') && Category::canAdd($user, $project)) { $params['add_object_url'] = Category::getQuickAddUrl($project, $controller, $module); $params['object_name'] = 'category'; $params['add_object_message'] = lang('Please insert new category name'); $options[] = option_tag('', ''); $options[] = option_tag(lang('New Category...'), '', array('class' => 'new_object_option')); } // if return select_box($options, $params) . '<script type="text/javascript">$("#' . $id . '").new_object_from_select();</script>'; }
/** * Render project breadcrumbs block * * Parameters: * * - breadcrumbs - array of breadcrumbs * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_mobile_access_project_breadcrumbs($params, &$smarty) { if (!is_foreachable($breadcrumbs = array_var($params, 'breadcrumbs', null))) { return null; } $smarty->assign(array("mobile_access_project_breadcrumbs_breadcrumbs" => $breadcrumbs)); return $smarty->fetch(get_template_path('_project_breadcrumbs', null, MOBILE_ACCESS_MODULE)); }
/** * Construct named list * * @param array $data */ public function __construct($data = null) { if ($data !== null && is_foreachable($data)) { foreach ($data as $k => $v) { $this->add($k, $v); } } }
/** * Render select project helper * * Parametars: * * - value - Id of selected project * - user - Limit only to projects that can be viewed by User * - optional * * @param void * @return null */ function smarty_function_select_project($params, &$smarty) { $user = array_var($params, 'user', null, true); if (!instance_of($user, 'User')) { return new InvalidParamError('user', $user, '$user is expected to be an instance of User class', true); } // if $show_all = array_var($params, 'show_all', false) && $user->isProjectManager(); $value = array_var($params, 'value', null, true); $projects_table = TABLE_PREFIX . 'projects'; $project_users_table = TABLE_PREFIX . 'project_users'; if ($show_all) { $projects = db_execute_all("SELECT {$projects_table}.id, {$projects_table}.name, {$projects_table}.status FROM {$projects_table} WHERE {$projects_table}.type = ? ORDER BY {$projects_table}.name", PROJECT_TYPE_NORMAL); } else { $projects = db_execute_all("SELECT {$projects_table}.id, {$projects_table}.name, {$projects_table}.status FROM {$projects_table}, {$project_users_table} WHERE {$project_users_table}.user_id = ? AND {$project_users_table}.project_id = {$projects_table}.id AND {$projects_table}.type = ? ORDER BY {$projects_table}.name", $user->getId(), PROJECT_TYPE_NORMAL); } // if $exclude = (array) array_var($params, 'exclude', array(), true); $active_options = array(); $archived_options = array(); if (is_foreachable($projects)) { foreach ($projects as $k => $project) { if (in_array($project['id'], $exclude)) { continue; } // if $option_attributes = $project['id'] == $value ? array('selected' => true) : null; if ($project['status'] == PROJECT_STATUS_ACTIVE) { $active_options[] = option_tag($project['name'], $project['id'], $option_attributes); } else { $archived_options[] = option_tag($project['name'], $project['id'], $option_attributes); } // if } // if } // if $optional = array_var($params, 'optional', false, true); $options = array(); if ($optional) { $options[] = option_tag(lang(array_var($params, 'optional_caption', '-- Select Project --')), ''); $options[] = option_tag('', ''); } // if if (is_foreachable($active_options)) { $options[] = option_group_tag(lang('Active'), $active_options); } // if if (is_foreachable($active_options) && is_foreachable($archived_options)) { $options[] = option_tag('', ''); } // if if (is_foreachable($archived_options)) { $options[] = option_group_tag(lang('Archive'), $archived_options); } // if return select_box($options, $params); }
/** * Return add discussion URL * * @param Project $project * @param array $additional * @return string */ function timetracking_module_add_record_url($project, $additional = null) { $params = array('project_id' => $project->getId()); if (is_foreachable($additional)) { $params = array_merge($params, $additional); } // if return assemble_url('project_time_add', $params); }
/** * Render block of the recent activities for selected user * * - recent_activities - array of groupped recent activities * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_recent_activities($params, &$smarty) { $recents = array_var($params, 'recent_activities'); if (!is_foreachable($recents)) { return ''; } // if $smarty->assign(array('_recents' => $recents)); return $smarty->fetch(get_template_path('_recent_activities_for_selected_user', null, SYSTEM_MODULE)); }
/** * Render activities block * * Parameters: * * - activities - array of groupped activities * - project_column - show project column * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_activities($params, &$smarty) { $activities = array_var($params, 'activities'); if (!is_foreachable($activities)) { return ''; } // if $smarty->assign(array('_activities' => $activities, '_activities_project_column' => (bool) array_var($params, 'project_column', true))); return $smarty->fetch(get_template_path('_activities', null, SYSTEM_MODULE)); }
/** * Returns true if this message has replies * * @param boolean $preload * @return boolean */ function hasReplies($preload = false) { if ($preload) { $this->getReplies(); return is_foreachable($this->replies); } else { return (bool) StatusUpdates::countByParent($this); } // if }
/** * Get repositories by project id and add last commit info * * @param int $project_id * @return array of objects */ function findByProjectId($project_id) { $repositories = ProjectObjects::find(array('conditions' => "project_id = {$project_id} AND `type` = 'Repository' AND state >='" . STATE_VISIBLE . "'", 'order' => 'id asc')); if (is_foreachable($repositories)) { foreach ($repositories as $repository) { $repository->last_commit = $repository->getLastCommit(); } } return $repositories; }
/** * with_successive_milestones helper * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_with_successive_milestones($params, &$smarty) { static $counter = 1; $name = array_var($params, 'name'); if (empty($name)) { return new InvalidParamError('name', $name, '$name value is required', true); } // if $milestone = array_var($params, 'milestone'); if (!instance_of($milestone, 'Milestone')) { return new InvalidParamError('milestone', $milestone, '$milestone value is expected to be an instance of Milestone class', true); } // if $id = array_var($params, 'id'); if (empty($id)) { $id = 'with_successive_milestones_' . $counter; $counter++; } // if $value = array_var($params, 'value'); $action = array_var($value, 'action', 'dont_move'); $milestones = array_var($value, 'milestones'); if (!is_array($milestones)) { $milestones = array(); } // if $logged_user = $smarty->get_template_vars('logged_user'); $successive_milestones = Milestones::findSuccessiveByMilestone($milestone, STATE_VISIBLE, $logged_user->getVisibility()); if (!is_foreachable($successive_milestones)) { return '<p class="details">' . lang('This milestone does not have any successive milestones') . '</p>'; } // if $result = "<div class=\"with_successive_milestones\">\n<div class=\"options\">\n"; $options = array('dont_move' => lang("Don't change anything"), 'move_all' => lang('Adjust all successive milestone by the same number of days'), 'move_selected' => lang('Adjust only selected successive milestones by the same number of days')); foreach ($options as $k => $v) { $radio = radio_field($name . '[action]', $k == $action, array('value' => $k, 'id' => $id . '_' . $k)); $label = label_tag($v, $id . '_' . $k, false, array('class' => 'inline'), ''); $result .= '<span class="block">' . $radio . ' ' . $label . "</span>\n"; } // if $result .= "</div>\n<div class=\"successive_milestones\">"; foreach ($successive_milestones as $successive_milestone) { $input_attributes = array('name' => $name . '[milestones][]', 'id' => $id . '_milestones_' . $successive_milestone->getId(), 'type' => 'checkbox', 'value' => $successive_milestone->getId(), 'class' => 'auto'); if (in_array($successive_milestone->getId(), $milestones)) { $input_attributes['checked'] = true; } // if $input = open_html_tag('input', $input_attributes, true); $label = label_tag($successive_milestone->getName(), $id . '_milestones_' . $successive_milestone->getId(), false, array('class' => 'inline'), ''); $result .= '<span class="block">' . $input . ' ' . $label . "</span>\n"; } // foreach $result .= "</div>\n</div>\n"; return $result; }
/** * Update parent type for old first discussion comments to Discussion * * @param void * @return boolean */ function updateInvoicingConfigOptions() { if (array_var($this->utility->db->execute_one("SELECT COUNT(*) AS 'row_count' FROM " . TABLE_PREFIX . "modules WHERE name = 'invoicing'"), 'row_count') == 1) { $config_options_table = TABLE_PREFIX . 'config_options'; $owner_company_id = null; $owner_company_name = null; $owner_company_address = null; $row = $this->utility->db->execute_one('SELECT id, name FROM ' . TABLE_PREFIX . 'companies WHERE is_owner = ? LIMIT 1', array(true)); if (is_array($row) && isset($row['id']) && isset($row['name'])) { $owner_company_id = (int) $row['id']; $owner_company_name = trim($row['name']); } // if if ($owner_company_id) { $row = $this->utility->db->execute_one('SELECT value FROM ' . TABLE_PREFIX . 'company_config_options WHERE company_id = ? AND name = ?', array($owner_company_id, 'office_address')); if (is_array($row) && isset($row['value'])) { $owner_company_address = unserialize($row['value']); } // if } // if $company_details = array('name' => $owner_company_name ? $owner_company_name : 'Owner Company', 'details' => $owner_company_address ? $owner_company_address : null, 'company_logo' => 'invoicing_logo.jpg'); $pdf_settings = array('paper_format' => 'A4', 'paper_orientation' => 'Portrait', 'header_text_color' => '000000', 'page_text_color' => '000000', 'border_color' => '000000', 'background_color' => 'c2c2c2'); $notes = null; $rows = $this->utility->db->execute_all("SELECT name, value FROM {$config_options_table} WHERE name IN ('invoicing_company_details', 'invoicing_notes', 'invoicing_pdf_settings')"); if (is_foreachable($rows)) { foreach ($rows as $row) { switch ($row['name']) { case 'invoicing_company_details': $company_details = unserialize($row['value']); break; case 'invoicing_pdf_settings': $pdf_settings = unserialize($row['value']); break; case 'invoicing_notes': $notes = unserialize($row['value']); break; } // switch } // foreach } // if $this->utility->db->execute("DELETE FROM {$config_options_table} WHERE name IN ('invoicing_company_details', 'invoicing_notes', 'invoicing_pdf_settings')"); $new_config_options = array('invoicing_company_name' => $company_details['name'], 'invoicing_company_details' => $company_details['details'], 'invoicing_pdf_paper_format' => $pdf_settings['paper_format'], 'invoicing_pdf_paper_orientation' => $pdf_settings['paper_orientation'], 'invoicing_pdf_header_text_color' => $pdf_settings['header_text_color'], 'invoicing_pdf_page_text_color' => $pdf_settings['page_text_color'], 'invoicing_pdf_border_color' => $pdf_settings['border_color'], 'invoicing_pdf_background_color' => $pdf_settings['background_color']); $to_insert = array(); foreach ($new_config_options as $name => $value) { $to_insert[] = $this->utility->db->prepareSQL("(?, 'invoicing', 'system', ?)", array($name, serialize($value))); } // foreach $this->utility->db->execute("INSERT INTO {$config_options_table} (name, module, type, value) VALUES " . implode(', ', $to_insert)); } // if return true; }