Example #1
0
 /**
  * Insert pattern
  * @param PatternDto $pattern
  * @return number
  */
 public function insert($pattern)
 {
     $patternId = -1;
     try {
         $this->dp->getDB()->beginTransaction();
         // Change tag of pattern (all column name)
         $tag = '';
         foreach ($pattern->header as $key => $column) {
             $tag .= $column->header . ' ';
         }
         // Get account id
         $accDao = new AccountDao($this->dp);
         $acc = $accDao->getByFbId($pattern->info->accountid);
         $pattern->info->accountid = $acc->id;
         // Insert pattern;
         $pattern->info->tag = $tag;
         $patternId = $this->patternDao->insert($pattern->info);
         $columnIdArr = array();
         foreach ($pattern->header as $key => $column) {
             $column->patternid = $patternId;
             $columnId = $this->patternHeaderDao->insert($column);
             $columnIdArr[] = $columnId;
         }
         for ($i = 0; $i < count($pattern->data); $i++) {
             $detail = $pattern->data[$i];
             $detail->patternid = $patternId;
             $detail->columnid = $columnIdArr[$i % $pattern->info->columnsize];
             $this->patternDetailDao->insert($detail);
         }
         $this->dp->getDB()->commit();
     } catch (Exception $ex) {
         // Something went wrong rollback!
         $this->dp->getDB()->rollBack();
         Plog::log($ex->getMessage());
     }
     return $patternId;
 }
Example #2
0
<?php

require '../../plog/classes/plog.php';
Plog::set_config(include '../../plog/config.php');
$log = Plog::factory(__FILE__);
$log->debug('hello world');
$log->info('今晚打老虎');
Example #3
0
 /**
  * Replace #property# with value
  * @param String $sql
  * @param Oject $object
  * @return String sql
  */
 private function queryProcess($sql, $object)
 {
     $prop = "";
     preg_match_all("/#[a-zA-Z0-9_]+#/", $sql, $matches, PREG_SET_ORDER);
     $isArray = is_array($object);
     foreach ($matches as $val) {
         $prop = str_replace("#", "", $val[0]);
         // 			if($isArray){
         // 				$sql=str_replace($val[0], $object[$prop], $sql);
         // 			}else{
         // 				$sql=str_replace($val[0], $object->$prop, $sql);
         // 			}
         $propVal;
         if ($isArray) {
             if (!is_string($object[$prop]) && is_null($object[$prop])) {
                 $propVal = 'null';
             } else {
                 $propVal = $object[$prop];
             }
         } else {
             if (!is_string($object->{$prop}) && is_null($object->{$prop})) {
                 $propVal = 'null';
             } else {
                 $propVal = $object->{$prop};
             }
         }
         $sql = str_replace($val[0], $propVal, $sql);
     }
     if (OUT_SQL) {
         Plog::out($sql);
     }
     return $sql;
 }
Example #4
0
 public static function set_config($config)
 {
     self::$_config = $config;
 }