/**
  * Add template objects to the view
  * @param template_id
  * @return array
  */
 function add_template_object_to_view($template_id)
 {
     $objects = array();
     $conditions = array('conditions' => '`template_id` = ' . $template_id);
     $tasks = TemplateTasks::findAll($conditions);
     $milestones = TemplateMilestones::findAll($conditions);
     foreach ($milestones as $milestone) {
         $objectId = $milestone->getObjectId();
         $id = $milestone->getId();
         $objectTypeName = $milestone->getObjectTypeName();
         $objectName = $milestone->getObjectName();
         $manager = get_class($milestone->manager());
         $ico = "ico-milestone";
         $action = "add";
         $objects[] = $this->prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, null, null, null, $ico);
     }
     foreach ($tasks as $task) {
         $objectId = $task->getObjectId();
         $id = $task->getId();
         $objectTypeName = $task->getObjectTypeName();
         $objectName = $task->getObjectName();
         $manager = get_class($task->manager());
         $milestoneId = $task instanceof TemplateTask ? $task->getMilestoneId() : '0';
         $subTasks = $task->getSubTasks();
         $parentId = $task->getParentId();
         $ico = "ico-task";
         $action = "add";
         $objects[] = $this->prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, $milestoneId, $subTasks, $parentId, $ico);
     }
     return $objects;
 }
示例#2
0
/**
 * Renders select milestone box
 *
 * @param string $name
 * @param Project $project
 * @param integer $selected ID of selected milestone
 * @param array $attributes Array of additional attributes
 * @return string
 * @throws InvalidInstanceError
 */
function select_milestone($name, $context = null, $selected = null, $attributes = null)
{
    if (!isset($attributes['template_milestone'])) {
        $milestones = ProjectMilestones::getActiveMilestonesByUser(logged_user(), $context);
    } else {
        //add conditions
        if (isset($attributes['template_id']) && $attributes['template_id'] != 0) {
            $tmp_id = $attributes['template_id'];
            $conditions = '(`session_id` =  0 AND `template_id` = ' . $tmp_id . ' OR `session_id` =  ' . logged_user()->getId() . ')';
        } else {
            $conditions = '`session_id` =  ' . logged_user()->getId();
        }
        $milestones = TemplateMilestones::findAll(array('conditions' => $conditions));
    }
    if (is_array($attributes)) {
        if (!isset($attributes['class'])) {
            $attributes['class'] = 'select_milestone';
        }
    } else {
        $attributes = array('class' => 'select_milestone');
    }
    $options = array(option_tag(lang('none'), 0));
    if (is_array($milestones)) {
        foreach ($milestones as $milestone) {
            $option_attributes = $milestone->getId() == $selected ? array('selected' => 'selected') : null;
            $options[] = option_tag($milestone->getObjectName(), $milestone->getId(), $option_attributes);
        }
    }
    return select_box($name, $options, $attributes);
}