Пример #1
0
 public static function update($table, $setCondition, $whereCondition)
 {
     Trace::addMessage(__CLASS__, sprintf('Updating table:"%s" with setCondition:"%s" and whereCondition:"%s"', $table, print_r($setCondition, true), print_r($whereCondition, true)));
     $result = parent::update($table, $setCondition, $whereCondition);
     Trace::addMessage(__CLASS__, sprintf('Update of %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
 protected static function insertIntoBD($szName, $szUrlKey, $szDocument, $nDocumentId, $aParent)
 {
     $szName = strip_tags($szName);
     $szName = \Faid\DB::escape($szName);
     $szUrlKey = \Faid\DB::escape($szUrlKey);
     $szDocument = \Faid\DB::escape($szDocument);
     $nDocumentId = intval($nDocumentId);
     $condition = array('parent' => $aParent['id']);
     DBSimple::update('sitemap', '`order` = `order` + 1', $condition);
     $visible = SystemRegisterHelper::getValue('/System/Sitemap/visible');
     $sql = 'INSERT INTO `%s` SET `name`="%s",`url_key`="%s",`document_name`="%s",`document_id`="%d",`parent`="%d",`order`="%d",date_created=NOW(),date_updated=NOW(),revision_count=0, `sitemap_xml_priority` = "0.1", `sitemap_xml_change`="weekly",`visible`="%d"';
     $sql = sprintf($sql, SITEMAP_TABLE, $szName, $szUrlKey, $szDocument, $nDocumentId, $aParent['id'], 0, $visible);
     DB::post($sql);
     return DB::$connection->insert_id;
 }
Пример #4
0
 public function testReload()
 {
     $fixture = 'reloaded value';
     $model = new testModel();
     $model->get(1);
     //
     DBSimple::update(testModel::TableName, array('name' => $fixture), array('id' => 1));
     //
     $model->reload();
     $this->AssertEquals($fixture, $model->name->getValue());
 }
Пример #5
0
 protected function action()
 {
     DBSimple::update(Record::tableName, array('viewed' => 1), array());
     \CMSLog::addMessage(__CLASS__, sprintf('All log records set as read'));
 }
Пример #6
0
 /**
  * @expectedException \Extasy\Users\login\UserNotConfirmedException
  */
 public function testUserNotConfirmed()
 {
     DBSimple::update(\UserAccount::getTableName(), ['confirmation_code' => 'some_value'], ['id' => 1]);
     $api = new Login();
     $api->exec();
 }
Пример #7
0
 /**
  * Устанавливает вкладки редактирования у конфига
  * @param array $data
  */
 public function setTabsheets($data = array())
 {
     $this->getTabSheets();
     // Перебор вкладок, проверяем что это массив
     if (!is_array($data)) {
         throw new CConfigException('setTabsheets empty argument ');
     }
     // удаляем все вкладки, которых нету в этом массиве
     $tabsheetsTitle = array_keys($data);
     foreach ($this->tabSheets as $key => $row) {
         $pos = array_search($row['title'], $tabsheetsTitle);
         // Если вкладка не найден в новых, киляем её
         if ($pos === false) {
             $sql = 'delete from `%s` where `id`="%d"';
             $sql = sprintf($sql, CCONFIG_TABSHEETS_TABLE, $row['id']);
             DB::post($sql);
             unset($this->tabSheets[$key]);
             break;
         }
     }
     // Удаляем все ссылки на вкладки у котролов
     DBSimple::update(CCONFIG_CONTROL_TABLE, array('tabId' => 0), array('schemaId' => $this->id));
     // Проверяем, что каждый элемент массива существует как контрол
     $order = 1;
     $controlOrder = 1;
     foreach ($data as $key => $row) {
         $tabsheetId = 0;
         $pos = false;
         foreach ($this->tabSheets as $tabInfo) {
             if ($tabInfo['title'] == $key) {
                 $tabsheetId = $tabInfo['id'];
                 break;
             }
         }
         if (empty($tabsheetId)) {
             // Нету?
             $sql = 'INSERT INTO `%s` SET `title`="%s",`schemaId`="%d",`order`="%d"';
             $sql = sprintf($sql, CCONFIG_TABSHEETS_TABLE, \Faid\DB::escape($key), $this->id, $order);
             // Создаем
             DB::post($sql);
             // Индекс вкладки сохраняем
             $tabsheetId = DB::$connection->insert_id;
         } else {
             $sql = 'UPDATE `%s` SET `order`="%d" WHERE `id`="%d"';
             $sql = sprintf($sql, CCONFIG_TABSHEETS_TABLE, $order, $tabsheetId);
             DB::post($sql);
         }
         if (is_string($row)) {
             $row = explode(',', $row);
         }
         // Перебор элементов
         foreach ($row as $controlName) {
             // Проверяем, что элемент существует
             $control = $this->searchControlByName($controlName);
             // Устанавливаем значение вкладки
             $sql = 'UPDATE `%s` SET `tabId`="%d",`order`="%d" where `id`="%d"';
             $sql = sprintf($sql, CCONFIG_CONTROL_TABLE, $tabsheetId, $controlOrder, $control->getId());
             DB::post($sql);
             $controlOrder++;
         }
         $order++;
     }
     $this->tabSheets = array();
 }
Пример #8
0
 function onAfterInsert()
 {
     $this->aValue = $this->calculateValue();
     DBSimple::update($this->document->getTableName(), array($this->szFieldName => $this->aValue), array($this->document->getIndex() => $this->document->getId()));
 }