Пример #1
0
 /**
  * Save value of given property in given investment.
  * @param Property $prop
  * @param Investment $inv
  * @param string $value
  * @param bool $isNew
  * @param array $dbValuesList
  */
 public static function SavePropertyValueForInv(Property $prop, Investment $inv, $value, $isNew, $dbValuesList)
 {
     is_numeric($inv->GetId()) ? $get_id = (int) $inv->GetId() : ($get_id = $inv->GetId());
     is_numeric($inv->GetIdLng()) ? $get_lng_id = (int) $inv->GetIdLng() : ($get_lng_id = $inv->GetIdLng());
     is_numeric($prop->GetID()) ? $get_prop_id = (int) $prop->GetID() : ($get_prop_id = $prop->GetID());
     if ($isNew) {
         //if offer is new, then directly make insert, instead of checking if record exist in db
         if (is_array($value)) {
             foreach ($value as $val) {
                 $result = DataBase::GetDbInstance()->ExecuteQueryWithParams("INSERT INTO #S#investments_properties (investments_id, investments_id_lng, properties_id, value, `set`, hash) VALUES(?, ?, ?, ?, true, ?)", array($get_id, $get_lng_id, $get_prop_id, $val, md5($val)));
             }
         } else {
             $query = "INSERT INTO #S#investments_properties (investments_id, investments_id_lng, properties_id, value, `set`, hash) VALUES(?, ?, ?, ?, false, ?)";
             $params = array($get_id, $get_lng_id, $get_prop_id, $value, md5($value));
             $result = DataBase::GetDbInstance()->ExecuteQueryWithParams($query, $params);
         }
     } else {
         //if offer exist, check if value exist in db
         if (is_array($value)) {
             $dbvalues = array();
             if (array_key_exists($prop->GetID(), $dbValuesList)) {
                 foreach ($dbValuesList[$prop->GetID()] as $dbval) {
                     if (in_array($dbval["value"], $value)) {
                         $dbvalues[count($dbvalues)] = $dbval["value"];
                     } else {
                         //delete from database
                         $result2 = DataBase::GetDbInstance()->ExecuteQueryWithParams("DELETE FROM #S#investments_properties WHERE id=?", array((int) $dbval['id']));
                     }
                 }
             }
             foreach ($value as $val) {
                 if (!in_array($val, $dbvalues)) {
                     //insert to database
                     $result = DataBase::GetDbInstance()->ExecuteQueryWithParams("INSERT INTO #S#investments_properties (investments_id, investments_id_lng, properties_id, value, `set`, hash) VALUES(?, ?, ?, ?, true, ?)", array($get_id, $get_lng_id, $get_prop_id, $val, md5($val)));
                 }
             }
         } else {
             $row = null;
             if (array_key_exists($prop->GetID(), $dbValuesList)) {
                 $row = $dbValuesList[$prop->GetID()][0];
             }
             $query = "";
             if ($row == null) {
                 $query = "INSERT INTO #S#investments_properties (investments_id, investments_id_lng, properties_id, value, `set`, hash) VALUES(?, ?, ?, ?, false, ?)";
                 $params = array($get_id, $get_lng_id, $get_prop_id, $value, md5($value));
             } else {
                 if ($row['value'] != $value) {
                     $query = "UPDATE #S#investments_properties SET value=?, hash=? WHERE investments_id=? AND investments_id_lng=? AND properties_id=?";
                     $params = array($value, md5($value), (int) $get_id, (int) $get_lng_id, (int) $get_prop_id);
                 }
             }
             if ($query != "") {
                 $result = DataBase::GetDbInstance()->ExecuteQueryWithParams($query, $params);
             }
         }
     }
 }
Пример #2
0
 /**
  * Add or edit if exists, given investment object.
  * @param Investment $inv
  */
 public static function AddEditInvestment(Investment $inv)
 {
     $i = self::GetInvestment($inv->GetId(), $inv->GetIdLng());
     if ($i == null) {
         self::AddInvestment($inv);
     } else {
         self::EditInvestment($inv);
     }
 }