/** * Mark project as pinned * * @param Project $project * @param User $user * @return boolean */ function pinProject($project, $user) { if (PinnedProjects::isPinned($project, $user, false)) { return true; } // if PinnedProjects::dropUserCache($user); return db_execute('INSERT INTO ' . TABLE_PREFIX . 'pinned_projects (project_id, user_id) VALUES (?, ?)', $project->getId(), $user->getId()); }
/** * Render pin/unpin icon * * Parameters: * * - project - Selected project * - user - Check pinned state agains this user * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_project_pinned($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 $user = array_var($params, 'user'); if (!instance_of($user, 'User')) { return new InvalidParamError('user', $user, '$user is expected to be an instance of User class', true); } // if require_once SMARTY_PATH . '/plugins/block.link.php'; $repeat = false; if (PinnedProjects::isPinned($project, $user)) { return smarty_block_link(array('href' => $project->getUnpinUrl(), 'title' => lang('Unpin'), 'class' => lang('unpin'), 'method' => 'post'), '<img src="' . get_image_url('icons/pinned.16x16.gif') . '" alt="" />', $smarty, $repeat); } else { return smarty_block_link(array('href' => $project->getPinUrl(), 'title' => lang('Pin to Top'), 'class' => lang('pin_to_top'), 'method' => 'post'), '<img src="' . get_image_url('icons/not-pinned.16x16.gif') . '" alt="" />', $smarty, $repeat); } // if }
/** * Return all active project this user is involved in * * @param boolean $pinned_first * @return array */ function getActiveProjects($pinned_first = false) { if ($this->active_projects === false) { $this->active_projects = Projects::findByUser($this, PROJECT_STATUS_ACTIVE); } // if if ($pinned_first) { if (is_foreachable($this->active_projects)) { $pinned = array(); $not_pinned = array(); foreach ($this->active_projects as $active_project) { if (PinnedProjects::isPinned($active_project, $this)) { $pinned[] = $active_project; } else { $not_pinned[] = $active_project; } // if } // foreach if (count($pinned) && count($not_pinned)) { return array_merge($pinned, $not_pinned); } elseif (count($pinned)) { return $pinned; } elseif (count($not_pinned)) { return $not_pinned; } else { return null; } // if } else { return null; } // if } else { return $this->active_projects; } // if }
/** * Return project options * * @param User $user * @return array */ 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'))); $options->add('edit_status', array('url' => $this->getEditStatusUrl(), 'text' => lang('Change Status'))); $options->add('edit_icon', array('url' => $this->getEditIconUrl(), 'text' => lang('Change Icon'))); } // if if ($this->canDelete($user)) { $options->add('delete', array('text' => lang('Delete'), 'url' => $this->getDeleteUrl(), 'method' => 'post', 'confirm' => lang('Are you sure that you want to delete this project and all related objects? This cannot be undone!'))); } // if if (PinnedProjects::isPinned($this, $user)) { $options->add('pin_unpin', array('text' => lang('Remove from Favorites'), 'url' => $this->getUnpinUrl(), 'method' => 'post')); } else { $options->add('pin_unpin', array('text' => lang('Add to Favorites'), 'url' => $this->getPinUrl(), 'method' => 'post')); } // if //BOF: task 04 | AD $options->add('manage_milestone_categories', array('url' => $this->getManageMilestoneCategoriesUrl(), 'text' => lang('Manage Milestone Categories'))); //EOF: task 04 | AD event_trigger('on_project_options', array(&$options, &$this, &$user)); $this->options[$user->getId()] = $options; } // if return $this->options[$user->getId()]; }