Ejemplo n.º 1
0
 /**
  * 
  * @param Tracker_Rule_List $rule
  * @return int The ID of the saved tracker_rule
  */
 public function insert(Tracker_Rule_List $rule)
 {
     $rule_id = $this->da->escapeInt($rule->getTrackerId());
     $rule_type = $this->da->quoteSmart(Tracker_Rule::RULETYPE_VALUE);
     $source_field_id = $this->da->escapeInt($rule->getSourceFieldId());
     if ($rule->getSourceValue() instanceof Tracker_FormElement_Field_List_Value) {
         $source_value_id = $this->da->quoteSmart($rule->getSourceValue()->getId());
     } else {
         $source_value_id = $this->da->quoteSmart($rule->getSourceValue());
     }
     $target_field_id = $this->da->escapeInt($rule->getTargetFieldId());
     if ($rule->getTargetValue() instanceof Tracker_FormElement_Field_List_Value) {
         $target_value_id = $this->da->quoteSmart($rule->getTargetValue()->getId());
     } else {
         $target_value_id = $this->da->quoteSmart($rule->getTargetValue());
     }
     $sql_insert_rule = "INSERT INTO tracker_rule (tracker_id, rule_type)\n                                VALUES ({$rule_id}, {$rule_type})";
     $this->startTransaction();
     try {
         $tracker_rule_id = $this->updateAndGetLastId($sql_insert_rule);
         $sql = "INSERT INTO tracker_rule_list (\n                        tracker_rule_id, \n                        source_field_id, \n                        source_value_id, \n                        target_field_id, \n                        target_value_id\n                        )\n                    VALUES (\n                        {$tracker_rule_id}, \n                        {$source_field_id}, \n                        {$source_value_id}, \n                        {$target_field_id}, \n                        {$target_value_id})";
         $this->retrieve($sql);
     } catch (Exception $e) {
         $this->rollBack();
         throw $e;
     }
     $this->commit();
     return $tracker_rule_id;
 }
Ejemplo n.º 2
0
 public function testGetTargetValueReturnsTargetIdSet()
 {
     $this->list_rule->setTargetValue(45);
     $this->assertEqual(45, $this->list_rule->getTargetValue());
 }