private function __map(DBObject $dbObject)
 {
     if (empty($this->fields)) {
         return $dbObject->getFieldsList();
     }
     $data = [];
     foreach ($this->fields as $field) {
         $data[$field] = $dbObject->getFieldValue($field);
     }
     return $data;
 }
Exemple #2
0
 /**
  * Main logging method, performes log writing.
  *
  * @param int $type Log message type.
  * @param string $message Message text.
  * @param string $format Time label format.
  * @param int $time Timestamp.
  *
  * @throws LoggerException
  */
 public function log($type, $message, $format = "\\[Y-m-d H:i:s\\]", $time = null)
 {
     $msgType = null;
     switch ($type) {
         case self::LOG_INFO:
             $msgType = OutputStream::MSG_INFO;
             break;
         case self::LOG_DEBUG:
             $msgType = OutputStream::MSG_DEBUG;
             break;
         case self::LOG_SUCCESS:
             $msgType = OutputStream::MSG_SUCCESS;
             break;
         case self::LOG_WARNING:
             $msgType = OutputStream::MSG_WARNING;
             break;
         case self::LOG_ERROR:
             $msgType = OutputStream::MSG_ERROR;
             break;
         default:
             throw new LoggerException("Invalid message type");
     }
     switch ($this->direction) {
         case self::TO_OUTPUT_STREAM:
             OutputStream::msg($msgType, $message, $format, $time);
             return;
         case self::TO_FILE:
             $message = "({$type}) " . $message;
             if (strpos($message, "{{time}}") === false) {
                 $message = "{{time}} " . $message;
             }
             if (is_null($time)) {
                 $time = time();
             }
             $message = str_replace("{{time}}", date($format, $time), $message);
             file_put_contents($this->fileName, "{$message}\n", FILE_APPEND);
             return;
         case self::TO_DB:
             $this->dbObject->log($type, $message, $time = null);
             return;
         default:
             throw new LoggerException("Invalid logging output direction type");
     }
 }
 private function __map(DBObject $dbObject)
 {
     return $dbObject->getFieldValue($this->field);
 }
 private function __filter(DBObject $dbObject)
 {
     return in_array($dbObject->getFieldValue($this->field), $this->values);
 }
 private function __filter(DBObject $dbObject)
 {
     return $dbObject->getFieldValue($this->field) == $this->value;
 }
Exemple #6
0
 /**
  * Executes SQL UPDATE query to the database.
  *
  * @param DBObject $dbObject DBObject to update.
  *
  * @return integer Returns the number of affected rows on success, and -1 if
  *           the last query failed.
  */
 public static function updateDBObject($dbObject)
 {
     $fieldsList = $dbObject->getFieldsList();
     $idFieldName = $dbObject->getIdFieldName();
     $query = "UPDATE " . $dbObject->getTableName() . "\n                  SET " . DBPreparedQuery::sqlQMValuesString($fieldsList, $idFieldName) . "\n                  WHERE " . $idFieldName . " = ?\n                  LIMIT 1";
     $typesString = DBPreparedQuery::sqlTypesString($fieldsList, $idFieldName);
     if (Tools::isInteger($fieldsList[$idFieldName])) {
         $typesString .= "i";
     } else {
         $typesString .= "s";
     }
     $valuesList = self::createValuesList($fieldsList, $idFieldName);
     $valuesList[] = $dbObject->getId();
     return self::doUpdateQuery($query, $typesString, $valuesList);
 }
Exemple #7
0
 /**
  * Returns DBObject from ResultSet.
  *
  * @param DBObject $dbObject
  * @param array $resultSet Associated by table names arrays of selected
  *           fields.
  *
  * @return DBObject
  */
 public static function selectDBObjectFromResultSet($dbObject, $resultSet)
 {
     $dbObject->setFieldsValues($resultSet[$dbObject->getTableName()]);
     return $dbObject;
 }