コード例 #1
0
ファイル: DatabaseObject.php プロジェクト: hellsan631/logosdb
 /**
  * Ensures that data (JSON String, Objects) are turned into arrays for processing
  *
  * @param $dataToFilter
  *
  * @return array
  */
 protected static function dataToArray(&$dataToFilter)
 {
     if (!is_array($dataToFilter) && $dataToFilter !== null) {
         if (is_object($dataToFilter)) {
             $dataToFilter = (array) $dataToFilter;
         } else {
             if (Core::isJson($dataToFilter)) {
                 $dataToFilter = json_decode($dataToFilter, true);
             } else {
                 trigger_error("Tried to filter Malformed data");
             }
         }
     }
     return $dataToFilter;
 }
コード例 #2
0
ファイル: Model.php プロジェクト: hellsan631/logosdb
 /**
  * Saves multiple objects inside a DB.
  *
  * 100 Queries Run
  * <p>Average Time: 1ms per 100/0.44kb</p>
  *
  * @param $changedData
  * An array of data to be changed
  *
  * @param $conditionArray
  * Where the data is supposed to be changed
  *
  * @return bool
  */
 public static function saveMultiple($changedData, $conditionArray)
 {
     $keyChain = self::getKeyChain();
     self::dataToArray($changedData);
     self::dataToArray($conditionArray);
     $prepareStatement = "UPDATE `" . self::name() . "` SET ";
     self::_buildQuerySet($prepareStatement, $changedData, $keyChain);
     $prepareStatement .= " WHERE ";
     //This cannot be _buildWhereSet because we use two different data sets for the fetch query,
     //changedData and the conditionArray. We add the where clauses to the condition array
     //@TODO rewrite this so it uses the $conditionArray instead of $changedData, so we can use _buildQueryWhere
     foreach ($conditionArray as $key => $value) {
         if (array_key_exists($key, $keyChain)) {
             $prepareStatement .= "{$key} = :w{$key} AND ";
             $changedData["w" . $key] = $value;
         }
     }
     $prepareStatement = rtrim($prepareStatement, " AND ");
     foreach ($changedData as $key => $val) {
         $changedData[':' . $key] = mb_strpos($key, 'date') !== false ? Core::unixToMySQL($val) : $val;
         unset($changedData[$key]);
     }
     //string should look like this:
     //UPDATE fruit SET color = :color, count = :count WHERE id = :id
     return Adapter::fetchQuery($prepareStatement, $changedData, false);
 }
コード例 #3
0
ファイル: CoreTest.php プロジェクト: hellsan631/logosdb
 /**
  * @dataProvider inputJson
  */
 public function testCheckIsJson($jsonString, $expected)
 {
     $this->assertEquals($expected, Core::isJson($jsonString));
 }