Esempio n. 1
0
 public function configure()
 {
     unset($this['lft'], $this['rgt'], $this['level'], $this['root_id'], $this['decision_id'], $this['files_list'], $this['created_at'], $this['updated_at'], $this['created_by'], $this['updated_by'], $this['type_id'], $this['item_id']);
     $this->widgetSchema['notes'] = $this->widgetSchema['additional_info'] = new laWidgetFormCKEditor(array('config' => array('height' => '75px')));
     $this->widgetSchema['upload'] = new laWidgetFileUpload();
     $this->widgetSchema['work_progress'] = new sfWidgetFormInputRange(array('min' => 0, 'max' => 100));
     /** @var sfWidget $widget */
     foreach ($this->widgetSchema->getFields() as $widget) {
         $widget->setAttribute('class', 'form-control');
     }
     /* Get all tags and create input field */
     $tags = array();
     foreach ($this->getObject()->getTagAlternative() as $tag) {
         $tags[] = $tag->Tag->name;
     }
     $this->widgetSchema['tags'] = new sfWidgetFormInputText(array(), array('value' => implode(',', $tags), 'class' => 'tags_input', 'data-role' => 'tagsinput'));
     /* Create field with relations */
     $related_alternatives_choices = array();
     if ($this->getOption('user')) {
         foreach (AlternativeTable::getInstance()->getListForUser($this->getOption('user')->getGuardUser()) as $alternative) {
             $related_alternatives_choices[$alternative->getId()] = $alternative->getName() . ' (' . $alternative->getDecision()->getName() . ')';
         }
     }
     unset($related_alternatives_choices[$this->getObject()->getId()]);
     $related_alternatives_default = array();
     foreach ($this->getObject()->getAlternativeRelation() as $related_alternative) {
         $related_alternatives_default[] = $related_alternative->to_id;
     }
     $this->widgetSchema['related_alternatives'] = new sfWidgetFormSelectMany(array('choices' => $related_alternatives_choices));
     $this->widgetSchema['related_alternatives']->setDefault($related_alternatives_default);
     $notify_date_native = $this->getObject()->getNotifyDate();
     $due_date_native = $this->getObject()->getDueDate();
     $due_data = new DateTime($this->getObject()->getDueDate());
     $notify_date = new DateTime($this->getObject()->getNotifyDate());
     $this->widgetSchema['notify_date'] = new sfWidgetFormInputText(array(), array('value' => '', 'data-value' => !empty($notify_date_native) && $notify_date_native !== '0000-00-00 00:00:00' ? $notify_date->format('Y/m/j') : ''));
     $this->widgetSchema['due_date'] = new sfWidgetFormInputText(array(), array('value' => '', 'data-value' => !empty($due_date_native) && $due_date_native !== '0000-00-00 00:00:00' ? $due_data->format('Y/m/j') : ''));
     if ($this->getOption('user')) {
         $assigned_to = array('' => '');
         $team_users = sfGuardUserTable::getInstance()->getUsersInTeamQuery($this->getOption('user')->getGuardUser())->execute();
         foreach ($team_users as $team_user) {
             $assigned_to[$team_user->getId()] = $team_user->getUserName();
         }
         $this->widgetSchema['assigned_to'] = new sfWidgetFormChoice(array('choices' => $assigned_to), array('class' => 'form-control'));
         if ($this->getObject()->isNew()) {
             $this->widgetSchema['assigned_to']->setDefault($this->getOption('user')->getGuardUser()->getId());
         }
     }
     $this->disableCSRFProtection();
 }
Esempio n. 2
0
 public function load()
 {
     //  $this->statuses = array('Draft', 'Reviewed', 'Planned', 'Doing', 'Finished', 'Parked');
     /** @var RoleFilter[] $roleFilters  */
     $alternatives = AlternativeTable::getInstance()->findBy('decision_id', $this->decision_id);
     foreach ($alternatives as $alternative) {
         $this->statuses[] = $alternative->status;
     }
     /** @var RoleFilter[] $roleFilters  */
     $statusFilters = StatusFilterTable::getInstance()->findBy('decision_id', $this->decision_id);
     foreach ($statusFilters as $statusFilter) {
         $this->data[] = $statusFilter->status;
     }
     $this->statuses = array_unique($this->statuses);
 }
Esempio n. 3
0
 public function load()
 {
     $this->products_number = AlternativeTable::getInstance()->countForDecision($this->decision_id);
     $this->criteria_number = PlannedAlternativeMeasurementTable::getInstance()->countForRole($this->role_id);
     $this->price = $this->products_number * $this->criteria_number * self::PRICE_RATIO;
     if ($this->price <= 500) {
         $this->days_number = 7;
     } else {
         if ($this->price > 500 && $this->price <= 2000) {
             $this->days_number = 14;
         } else {
             $this->days_number = 21;
         }
     }
 }
Esempio n. 4
0
 public function load(sfGuardUser $user, $decision_id)
 {
     $this->criteria = CriterionTable::getInstance()->getArrayForUser($user, $decision_id);
     $alternatives = AlternativeTable::getInstance()->getArrayForUser($user, $decision_id);
     $values = AlternativeMeasurementTable::getInstance()->getForDashboard($user, $decision_id);
     foreach ($alternatives as $alternative) {
         $this->body[$alternative['id']][0] = $alternative['name'];
         foreach ($this->criteria as $criterion) {
             $cell = new stdClass();
             $cell->measurement = str_replace(' ', '_', $criterion['measurement']);
             $cell->value = isset($values[$alternative['id']][$criterion['id']]) ? $values[$alternative['id']][$criterion['id']] : null;
             $this->body[$alternative['id']][$criterion['id']] = $cell;
         }
     }
 }
Esempio n. 5
0
 /**
  * @param sfWebRequest $request
  */
 public function executeIndex(sfWebRequest $request)
 {
     $decision_id = $request->getParameter('decision_id', false);
     $this->decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id);
     $this->forward404Unless($this->decision);
     $this->forward404Unless($this->getUser()->verifyLightAccess($this->getContext()));
     $this->criteriaAnalyze = new CriteriaAnalyze();
     $this->criteriaAnalyze->setDecisionId($decision_id);
     $this->criteriaAnalyze->load();
     $this->logicalFilter = new LogicalFilterView();
     $this->logicalFilter->setDecisionId($decision_id);
     $this->logicalFilter->load();
     $this->roleFilter = new RoleFilterView();
     $this->roleFilter->setDecisionId($decision_id);
     $this->roleFilter->load();
     $this->statusFilter = new StatusFilterView();
     $this->statusFilter->setDecisionId($decision_id);
     $this->statusFilter->load();
     $this->tagFilter = new TagFilterView();
     $this->tagFilter->setDecisionId($decision_id);
     $this->tagFilter->load();
     $this->stackedBarChart = new StackedBarChart();
     $this->stackedBarChart->setDecisionId($decision_id);
     $this->stackedBarChart->setCriteriaValues($this->criteriaAnalyze->getCriteriaValues());
     $this->stackedBarChart->setRoleFilterData($this->roleFilter->getData());
     $this->stackedBarChart->setStatusFilterData($this->statusFilter->getData());
     $this->stackedBarChart->setTagFilterData($this->tagFilter->getDataForSQL());
     $this->stackedBarChart->setFilteredAlternativesIds($this->logicalFilter->getFilteredAlternativesIds());
     $this->stackedBarChart->load();
     $this->costAnalyze = new CostAnalyze();
     $this->costAnalyze->setDecisionId($decision_id);
     $this->costAnalyze->setSortedAlternativeIds($this->stackedBarChart->getSortedAlternativeIds());
     $this->costAnalyze->setRoleFilterData($this->roleFilter->getData());
     $this->costAnalyze->setStatusFilterData($this->statusFilter->getData());
     $this->costAnalyze->setTagFilterData($this->tagFilter->getDataForSQL());
     $this->costAnalyze->setCumulativeData($this->stackedBarChart->getCumulativeData());
     $this->costAnalyze->setFilteredAlternativesIds($this->logicalFilter->getFilteredAlternativesIds());
     $this->costAnalyze->load();
     // release planner
     $this->alternatives_json = AlternativeTable::getInstance()->getDashboardReleaseJSON($decision_id, $this->stackedBarChart->getSortedAlternativeIds());
     $this->releases = ProjectReleaseTable::getInstance()->getList($decision_id);
 }
Esempio n. 6
0
 public function load()
 {
     /** @var RoleFilter[] $roleFilters  */
     $alternatives = AlternativeTable::getInstance()->findBy('decision_id', $this->decision_id);
     foreach ($alternatives as $alternative) {
         $tagAlternatives = TagAlternativeTable::getInstance()->findBy('alternative_id', $alternative->id);
         foreach ($tagAlternatives as $tagAlternative) {
             $this->tags[$tagAlternative->Tag->id] = $tagAlternative->Tag->name;
         }
     }
     /** @var RoleFilter[] $roleFilters  */
     $tagFilters = TagFilterTable::getInstance()->findBy('decision_id', $this->decision_id);
     foreach ($tagFilters as $tagFilter) {
         $this->data[] = $tagFilter->Tag->name;
         $ta_by_name = Doctrine_Query::create()->from('TagAlternative ta')->select('ta.id as id, a.id as a_id')->leftJoin('ta.Tag t')->leftJoin('ta.Alternative a')->where("t.name = ?", $tagFilter->Tag->name)->andWhere('a.decision_id = ?', $this->decision_id)->execute();
         foreach ($ta_by_name as $v) {
             $this->data_for_sql[] = $v->a_id;
         }
     }
     $this->tags = array_unique($this->tags);
 }
 public function advancedImport()
 {
     foreach ($this->prepareData() as $item) {
         $alternative = null;
         if (array_key_exists('id', $item) && !empty($item['id'])) {
             $alternative = AlternativeTable::getInstance()->createQuery('a')->leftJoin('a.Decision d')->leftJoin('d.User u')->leftJoin('u.TeamMember tm')->whereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($this->guard_user))->andWhere('a.item_id = ?', $item['id'])->andWhere('d.id = ?', $this->decision->getId())->fetchOne();
         }
         if (!is_object($alternative)) {
             $alternative = new Alternative();
             $alternative->setDecision($this->decision);
             $alternative->setCreatedBy($this->created_and_updated_by);
             $alternative->setUpdatedBy($this->created_and_updated_by);
         }
         $alternative->setName($item['name']);
         foreach (array('status', 'work progress', 'additional info', 'notes', 'due date', 'notify date') as $prop) {
             if (array_key_exists($prop, $item) && !empty($item[$prop])) {
                 $alternative->{str_replace(' ', '_', $prop)} = $item[$prop];
             }
         }
         if (array_key_exists('tags', $item)) {
             // Process tags
             $tags_request = array_map('trim', explode(',', $item['tags']));
             $tags = array();
             foreach ($alternative->getTagAlternative() as $tag) {
                 $tags[] = $tag->Tag->name;
             }
             foreach (array_diff($tags_request, $tags) as $result) {
                 Tag::newTag($this->guard_user, $alternative->getId(), $result, 'alternative');
             }
             foreach (array_diff($tags, $tags_request) as $result) {
                 Tag::removeTag($this->guard_user, $alternative->getId(), $result, 'alternative');
             }
         }
         $alternative->save();
     }
 }
Esempio n. 8
0
 public function getItemDeleteResponse(sfGuardUser $user)
 {
     /** @var sfWebRequest $request */
     $request = $this->getRequest();
     $alternative = AlternativeTable::getInstance()->getOneForUser($user, $request->getParameter('id'));
     if (is_object($alternative)) {
         $alternative->delete();
         $result = array('status' => 'success');
     } else {
         $result = array('status' => 'error', 'error' => sprintf('Item with id %d does not exist', $request->getParameter('id')));
     }
     return $result;
 }
Esempio n. 9
0
 /**
  * @param sfWebRequest $request
  * @return sfView
  */
 public function executeImportFromCustomFields(sfWebRequest $request)
 {
     $decision_id = $request->getParameter('decision_id', false);
     $decision = DecisionTable::getInstance()->getDecisionForUser($this->getUser()->getGuardUser(), $decision_id);
     $this->forward404Unless(is_object($decision));
     $header = $request->getParameter('header');
     $data = $request->getParameter('data');
     if (array_search('name', $header) === false) {
         return $this->renderText(json_encode(array('status' => 'error', 'text' => 'Please ensure that data field "Name" is mapped to a column in your SpreadSheet.')));
     }
     foreach ($data as $item) {
         $alternative = null;
         if (array_key_exists('id', $item) && !empty($item['id'])) {
             $alternative = AlternativeTable::getInstance()->createQuery('a')->leftJoin('a.Decision d')->leftJoin('d.User u')->leftJoin('u.TeamMember tm')->whereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($this->getUser()->getGuardUser()))->andWhere('a.item_id = ?', $item['id'])->andWhere('d.id = ?', $decision->getId())->fetchOne();
         }
         if (!is_object($alternative)) {
             $alternative = new Alternative();
             $alternative->setDecision($decision);
             $alternative->setCreatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
             $alternative->setUpdatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
         }
         $custom_fields = array();
         foreach ($item as $prop => $value) {
             if (array_key_exists($prop, $header)) {
                 if ($header[$prop] == '_new') {
                     $custom_fields[$prop] = $value;
                 } elseif (!in_array($header[$prop], array('id')) && in_array($header[$prop], array('name', 'status', 'work progress', 'additional info', 'notes', 'due date', 'notify date', 'tags'))) {
                     if ($header[$prop] == 'tags') {
                         // Process tags
                         $tags_request = array_map('trim', explode(',', $value));
                         $tags = array();
                         foreach ($alternative->getTagAlternative() as $tag) {
                             $tags[] = $tag->Tag->name;
                         }
                         foreach (array_diff($tags_request, $tags) as $result) {
                             Tag::newTag($this->getUser()->getGuardUser(), $alternative->getId(), $result, 'alternative');
                         }
                         foreach (array_diff($tags, $tags_request) as $result) {
                             Tag::removeTag($this->getUser()->getGuardUser(), $alternative->getId(), $result, 'alternative');
                         }
                     } else {
                         $alternative->{str_replace(' ', '_', $header[$prop])} = $value;
                     }
                 }
             }
         }
         if ($custom_fields) {
             $alternative->setCustomFields(json_encode($custom_fields));
         }
         if (!$alternative->getName()) {
             $alternative->setName('New ' . InterfaceLabelTable::getInstance()->get($this->getUser()->getGuardUser(), InterfaceLabelTable::ITEM_TYPE));
         }
         $alternative->save();
     }
     return $this->renderText(json_encode(array('status' => 'success')));
 }
Esempio n. 10
0
 public function executeUpdate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
     $this->forward404Unless($alternative = Doctrine_Core::getTable($this->model)->find(array($request->getParameter('id'))), sprintf('Object decision does not exist (%s).', $request->getParameter('id')));
     $form = new AlternativeForm($alternative, array('user' => $this->getUser()));
     $alternative->setUpdatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $form->save();
         // Create log
         $log = new Log();
         $log->injectDataAndPersist($alternative, $this->getUser()->getGuardUser(), array('action' => 'edit'));
         // Process tags
         $tags_request = json_decode($request->getParameter('tags'));
         $tags = array();
         foreach ($alternative->getTagAlternative() as $tag) {
             $tags[] = $tag->Tag->name;
         }
         foreach (array_diff($tags_request, $tags) as $result) {
             Tag::newTag($this->getUser()->getGuardUser(), $request->getParameter('id'), $result, 'alternative');
         }
         foreach (array_diff($tags, $tags_request) as $result) {
             Tag::removeTag($this->getUser()->getGuardUser(), $request->getParameter('id'), $result, 'alternative');
         }
         // Process links
         $links = array();
         foreach ($alternative->getAlternativeLink() as $link) {
             $links[$link->id] = $link->link;
         }
         $links_request_new = array();
         $links_request_old = array();
         $links_request = json_decode($request->getParameter('links'), true);
         foreach ($links_request as $link_request) {
             if (is_array($link_request) && array_key_exists('id', $link_request)) {
                 $links_request_old[$link_request['id']] = $link_request['link'];
             } else {
                 $links_request_new[] = $link_request;
             }
         }
         foreach ($links_request_new as $link_request_new) {
             $link = new AlternativeLink();
             $link->link = $link_request_new['link'];
             $link->alternative_id = $request->getParameter('id');
             $link->save();
         }
         foreach (array_diff(array_keys($links), array_keys($links_request_old)) as $result) {
             AlternativeLinkTable::getInstance()->find($result)->delete();
         }
         foreach ($links_request_old as $key => $link) {
             if ($links_request_old[$key] !== $links[$key]) {
                 $alternative_link = AlternativeLinkTable::getInstance()->find($key);
                 $alternative_link->link = $links_request_old[$key];
                 $alternative_link->save();
             }
         }
         // Process related alternatives
         $related_alternatives_request = json_decode($request->getParameter('related_alternatives'), true);
         if (!$related_alternatives_request) {
             $related_alternatives_request = array();
         }
         $related_alternatives = array();
         foreach ($alternative->getAlternativeRelation() as $related_alternative) {
             $related_alternatives[] = $related_alternative->to_id;
         }
         foreach (array_diff($related_alternatives_request, $related_alternatives) as $result) {
             if (AlternativeTable::getInstance()->getOneForUser($this->getUser()->getGuardUser(), $result)) {
                 $alternative_relation = new AlternativeRelation();
                 $alternative_relation->setFromId($alternative->getId());
                 $alternative_relation->setToId($result);
                 $alternative_relation->setCreatedBy(Alternative::generateUpdateAndCreatedBy($this->getUser()->getGuardUser()));
                 $alternative_relation->save();
             }
         }
         foreach (array_diff($related_alternatives, $related_alternatives_request) as $result) {
             AlternativeRelationTable::getInstance()->findByFromIdAndToId($alternative->getId(), $result)->delete();
         }
         $alternative->refresh(true);
         return $this->renderText(json_encode($alternative->getRowData()));
     } else {
         return $this->renderPartial('form', array('form' => $form));
     }
 }
Esempio n. 11
0
 public function executeAlternativeVote(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     $alternative_id = $request->getParameter('id');
     $voted_items_ids = $this->getUser()->getAttribute('voted_items_ids', array());
     if (!in_array($alternative_id, $voted_items_ids)) {
         /** @var Alternative $alternative */
         $alternative = AlternativeTable::getInstance()->getForVote($alternative_id);
         $alternative->score++;
         $alternative->save();
         $voted_items_ids[] = $alternative->id;
         $this->getUser()->setAttribute('voted_items_ids', $voted_items_ids);
         return $this->renderText($alternative->score);
     }
     return sfView::NONE;
 }