Example #1
0
 public function insert(array $values, $returnInserted = false)
 {
     if (empty($values['time'])) {
         $values['time'] = $this->getDi()->sqlDateTime;
     }
     return parent::insert($values, $returnInserted);
 }
Example #2
0
 function selectAllRecords()
 {
     $q = $this->query();
     $ret = array();
     while ($row = $this->db->fetchRow($q)) {
         $ret[] = $this->table->createRecord($row);
     }
     return $ret;
 }
Example #3
0
 /**
  * Select records on given "page"
  * @param int $pageNum page# to display, starting from 0
  * @param int $count records per page
  * @return array of Am_Record
  */
 function selectPageRecords($pageNum, $count)
 {
     if ($count <= 0) {
         throw new Am_Exception_InternalError("count could not be empty in " . __METHOD__);
     }
     $q = $this->query($pageNum * $count, $count);
     $ret = array();
     while ($row = $this->db->fetchRow($q)) {
         $ret[] = $this->table->createRecord($row);
     }
     return $ret;
 }
 public function load($keyOrTicketId, $throwExceptions = true)
 {
     if (preg_match('/^\\d+$/', trim($keyOrTicketId), $matches)) {
         return parent::load($matches[0], $throwExceptions);
     } else {
         $keyOrTicketId = filterId($keyOrTicketId);
         $found = $this->findFirstByTicketMask($keyOrTicketId);
         if (!$found && $throwExceptions) {
             throw new Am_Exception_InternalError("Ticket with mask [{$keyOrTicketId}] not found");
         }
         return $found;
     }
 }
Example #5
0
 function start($tag, $attributes)
 {
     if (!$this->table) {
         return;
     }
     switch ($tag) {
         case 'row':
             $this->record = $this->table->createRecord();
             foreach ($this->record->getTable()->getFields(true) as $k) {
                 if (!empty($this->parentKeys[$k])) {
                     $this->record->set($k, $this->parentKeys[$k]);
                 }
             }
             $this->record->disableInsertPkCheck(true);
             break;
     }
 }
Example #6
0
 public function insert(array $values, $returnInserted = false)
 {
     if (empty($values['tm'])) {
         $values['tm'] = $this->getDi()->sqlDateTime;
     }
     if (empty($values['remote_addr'])) {
         $values['remote_addr'] = $_SERVER['REMOTE_ADDR'];
     }
     return parent::insert($values, $returnInserted);
 }
Example #7
0
 /** @return Am_Di $di */
 function getDi()
 {
     return $this->_table->getDi();
 }
Example #8
0
 public function delete($key)
 {
     parent::delete($key);
     if ($this->_groupTableConfig) {
         $table = $this->_groupTableConfig[Am_Protect_Table::GROUP_TABLE];
         $uidField = $this->_groupTableConfig[Am_Protect_Table::GROUP_UID];
         $this->_db->query("DELETE FROM {$table} WHERE ?#=?", $uidField, $key);
     }
 }
Example #9
0
 public function delete($key)
 {
     parent::delete($key);
     $this->_db->query("DELETE FROM ?_resource_resource_category WHERE resource_category_id=?d", $key);
 }
Example #10
0
 public function delete($key)
 {
     parent::delete($key);
     $this->_db->query("DELETE FROM ?_product_product_category WHERE product_category_id=?d", $key);
 }
Example #11
0
 public function delete($key)
 {
     parent::delete($key);
     $this->_db->query("DELETE FROM ?_user_user_group WHERE user_group_id=?d", $key);
 }
Example #12
0
 function __construct(Am_Protect_Databased $plugin, $db = null, $table = null, $key = null, $recordClass = null)
 {
     $this->_plugin = $plugin;
     parent::__construct($db, $table, $key, $recordClass);
 }
 public function addFieldSelect($name, Am_Table $table, $title, array $options)
 {
     $fs = $this->form->addFieldset()->setLabel($title . ' Columns: ' . $table->getName(true));
     $sampleRows = $table->getAdapter()->select("SELECT * FROM ?#\n            LIMIT ?d,3", $table->getName(true), max($table->countBy() - 3, 0));
     $sample = "<div style='color: lightgray'>";
     foreach ($sampleRows as $r) {
         $sample .= nl2br(Am_Controller::escape(substr(print_r($r, true), 0, 1024))) . "\n";
     }
     $sample .= "</div>";
     $fs->addStatic()->setLabel('Sample Rows')->setContent($sample);
     $fields = $table->getFields(true);
     $fields = array_merge(array(''), $fields);
     foreach ($options as $k => $v) {
         $el = $fs->addSelect('field[' . $name . '][' . $k . ']')->setLabel($v)->loadOptions(array_combine($fields, $fields));
         if (!in_array($k, array('Am_Protect_SessionTable::FIELD_UID', 'Am_Protect_SessionTable::FIELD_IP', 'Am_Protect_SessionTable::FIELD_UA', 'Am_Protect_SessionTable::FIELD_CREATED', 'Am_Protect_SessionTable::FIELD_CHANGED'))) {
             $el->addRule('required');
         }
     }
 }
Example #14
0
 protected function _simpleSort(Am_Table $table, $item, $after, $before)
 {
     $after = $after ? $after['id'] : null;
     $before = $before ? $before['id'] : null;
     $id = $item['id'];
     $table_name = $table->getName();
     $pk = $table->getKeyField();
     $db = Am_Di::getInstance()->db;
     $item = $table->load($id);
     if ($before) {
         $beforeItem = $table->load($before);
         $sign = $beforeItem->sort_order > $item->sort_order ? '-' : '+';
         $newSortOrder = $beforeItem->sort_order > $item->sort_order ? $beforeItem->sort_order - 1 : $beforeItem->sort_order;
         $db->query("UPDATE {$table_name}\n                SET sort_order=sort_order{$sign}1 WHERE\n                sort_order BETWEEN ? AND ? AND {$pk}<>?", min($newSortOrder, $item->sort_order), max($newSortOrder, $item->sort_order), $id);
         $db->query("UPDATE {$table_name} SET sort_order=? WHERE {$pk}=?", $newSortOrder, $id);
     } elseif ($after) {
         $afterItem = $table->load($after);
         $sign = $afterItem->sort_order > $item->sort_order ? '-' : '+';
         $newSortOrder = $afterItem->sort_order > $item->sort_order ? $afterItem->sort_order : $afterItem->sort_order + 1;
         $db->query("UPDATE {$table_name}\n                SET sort_order=sort_order{$sign}1 WHERE\n                sort_order BETWEEN ? AND ? AND {$pk}<>?", min($newSortOrder, $item->sort_order), max($newSortOrder, $item->sort_order), $id);
         $db->query("UPDATE {$table_name} SET sort_order=? WHERE {$pk}=?", $newSortOrder, $id);
     }
 }