Пример #1
0
 public static function insert($table, $data)
 {
     Trace::addMessage(__CLASS__, sprintf('Inserting into table:"%s" with data:"%s"', $table, print_r($data, true)));
     $result = parent::insert($table, $data);
     Trace::addMessage(__CLASS__, sprintf('Insert into %s finished', $table));
     return $result;
 }
Пример #2
0
 /**
  * 
  * Создает объект права 
  * @param string $path строка набора объектов разделенная символом "/"  
  */
 public static function create($path, $title = '')
 {
     // Разрезаем путь
     $path = self::getPath($path);
     // Для каждого элемента пути
     $parentId = 0;
     $fullPath = '';
     foreach ($path as $key => $row) {
         // Получаем каждый элемент (имя, parent)
         $condition = array('parentId' => $parentId, 'name' => $row);
         if (empty($fullPath)) {
             $fullPath .= $row;
         } else {
             $fullPath .= '/' . $row;
         }
         $el = DBSimple::get(ACL_TABLE, $condition);
         // Если элемент не существует, создаем его
         if (empty($el)) {
             $insertCondition = $condition;
             $insertCondition['fullPath'] = $fullPath;
             $parentId = DBSimple::insert(ACL_TABLE, $insertCondition);
         } else {
             $parentId = $el['id'];
         }
     }
     /**
      * Если указан тайтл, то сохраняем его 
      */
     if (!empty($title)) {
         $whereCondition = array('id' => $parentId);
         $setCondition = array('title' => $title);
         DBSimple::update(ACL_TABLE, $setCondition, $whereCondition);
     }
     return $parentId;
 }
Пример #3
0
 public static function dbFixture($tableName, $data)
 {
     $sql = sprintf(' TRUNCATE `%s` ', $tableName);
     \Faid\DB::post($sql);
     //
     foreach ($data as $row) {
         \Faid\DBSimple::insert($tableName, $row);
     }
 }
Пример #4
0
 public function onInsert(\Extasy\ORM\QueryBuilder $queryBuilder)
 {
     if (empty($this->aValue)) {
         return;
     }
     foreach ($this->aValue as $row) {
         $row = IntegerHelper::toNatural($row);
         DBSimple::insert($this->tableName, array($this->innerKey => $this->document->id->getValue(), $this->foreighnKey => $row));
     }
 }
Пример #5
0
    protected function createTable()
    {
        $sql = <<<SQL
create table `test_document` (
\t`id` int not null auto_increment,
\t`name` varchar(255 ) not null default '',
\tprimary key (`id`)
);
SQL;
        DB::post($sql);
        DBSimple::insert(Model::TableName, array('name' => 'sitemap document'));
    }
Пример #6
0
 protected function storeValue()
 {
     $userId = $this->document->id->getValue();
     if (empty($userId)) {
         return;
     }
     DBSimple::delete(self::UIDTable, array('user_id' => $userId));
     foreach ($this->aValue as $network => $uid) {
         $network = Network::getByName($network);
         DBSimple::insert(self::UIDTable, array('date' => date('Y-m-d H:i:s'), 'network_id' => $network->id->getValue(), 'user_id' => $this->document->id->getValue(), 'uid' => $uid));
     }
 }
Пример #7
0
 public static function quickRegister($user, $authPassed, $method = 'default')
 {
     if (!empty($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER['REMOTE_ADDR'];
         if ('::1' == $ip) {
             $ip = '127.0.0.1';
         }
     } else {
         $ip = '127.0.0.1';
     }
     $userId = !empty($user) ? $user->id->getValue() : 0;
     \Faid\DBSimple::insert(self::TableName, array('host' => ip2long($ip), 'date' => date('Y-m-d H:i:s'), 'user_id' => $userId, 'status' => !empty($authPassed) ? self::SuccessStatus : self::FailStatus, 'method' => $method));
     \CMSLog::addMessage(__CLASS__, sprintf('Login attemp into user with id="%d", operation status - %s', $userId, !empty($authPassed) ? 'success' : 'fail'));
 }
Пример #8
0
    public function setUp()
    {
        parent::setUp();
        self::dropTable();
        $sql = <<<SQL

\t\tCREATE TABLE `test_model` (
\t\t \tid int not null auto_increment,
\t\t \tname varchar(255) not null,
\t\t \tprimary key (`id` )
\t\t)

SQL;
        DB::post($sql);
        DBSimple::insert('test_model', array('id' => 1, 'name' => self::fixtureName));
    }
Пример #9
0
 public function setUp()
 {
     DB::post('truncate table test_model');
     DBSimple::insert('test_model', array('id' => 1, 'name' => self::fixtureName));
 }