コード例 #1
0
ファイル: Editor.php プロジェクト: paletter/tms-website
 /**
  * Delete one or more rows from the database for an individual table
  *
  *  @param string $table Database table name to use
  *  @param array $ids Array of ids to remove
  *  @param string $pkey Database column name to match the ids on for the
  *    delete condition. If not given the instance's base primary key is
  *    used.
  *  @private
  */
 function _remove_table($table, $ids, $pkey = null)
 {
     if ($pkey === null) {
         $pkey = $this->_pkey;
     }
     $stmt = $this->_db->query('delete')->table($table)->or_where($pkey, $ids)->exec();
 }
コード例 #2
0
ファイル: Field.php プロジェクト: kienbk1910/RDCAdmin
 /**
  * Execute the ipOpts to get the list of options to return to the client-
  * side
  *
  * @param  \DataTables\Database $db Database instance
  * @return Array        Array of value / label options for the list
  * @internal
  */
 public function optionsExec($db)
 {
     $table = $this->_optsTable;
     if (!$table) {
         return false;
     } else {
         if (is_callable($table) && is_object($table)) {
             return $table();
         } else {
             $label = $this->_optsLabel;
             $value = $this->_optsValue;
             $formatter = $this->_optsFormat;
             $fields = array($value);
             // Create a list of the fields that we need to get from the db
             if (!is_array($label)) {
                 $fields[] = $label;
             } else {
                 $fields = array_merge($fields, $label);
             }
             // We need a default formatter if one isn't provided
             if (!$formatter) {
                 $formatter = is_array($label) ? function ($row) use($label) {
                     $a = array();
                     for ($i = 0, $ien = count($label); $i < $ien; $i++) {
                         $a[] = $row[$label[$i]];
                     }
                     return implode(' ', $a);
                 } : function ($row) use($label) {
                     return $row[$label];
                 };
             }
             // Get the data
             $rows = $db->selectDistinct($table, $fields, $this->_optsCond)->fetchAll();
             // Create the output array
             $out = array();
             for ($i = 0, $ien = count($rows); $i < $ien; $i++) {
                 $out[] = array("label" => $formatter($rows[$i]), "value" => $rows[$i][$value]);
             }
             usort($out, function ($a, $b) {
                 return strcmp($a['label'], $b['label']);
             });
             return $out;
         }
     }
 }
コード例 #3
0
ファイル: Editor.php プロジェクト: artmart/verare
 /**
  * Delete one or more rows from the database for an individual table
  *
  * @param string $table Database table name to use
  * @param array $ids Array of ids to remove
  * @param string $pkey Database column name to match the ids on for the
  *   delete condition. If not given the instance's base primary key is
  *   used.
  * @private
  */
 function _remove_table($table, $ids, $pkey = null)
 {
     if ($pkey === null) {
         $pkey = $this->_pkey;
     }
     // Check there is a field which has a set option for this table
     $count = 0;
     foreach ($this->_fields as $field) {
         if (strpos($field->dbField(), '.') === false || $this->_part($field->dbField(), 'table') === $table && $field->set() !== Field::SET_NONE) {
             $count++;
         }
     }
     if ($count > 0) {
         $this->_db->query('delete')->table($table)->or_where($pkey, $ids)->exec();
     }
 }
コード例 #4
0
ファイル: Join.php プロジェクト: FaTTeST/billenv
 /**
  * Update a row.
  *  @param \DataTables\Database $db Database reference to use
  *  @param int $parentId Parent row's primary key value
  *  @param string[] $data Data to be set for the join
  *  @private
  */
 private function _update_row($db, $parentId, $data)
 {
     if (isset($this->_join['table'])) {
         // Got a link table, just insert the pkey references
         $db->push($this->_join['table'], array($this->_join['parent'][1] => $parentId, $this->_join['child'][1] => $data[$this->_join['child'][0]]), array($this->_join['parent'][1] => $parentId));
     } else {
         // No link table, just a direct reference
         $set = array($this->_join['child'] => $parentId);
         for ($i = 0; $i < count($this->_fields); $i++) {
             $field = $this->_fields[$i];
             if ($field->apply('set', $data)) {
                 $set[$field->dbField()] = $field->val('set', $data);
             }
         }
         // Add WHERE conditions
         $where = array($this->_join['child'] => $parentId);
         for ($i = 0, $ien = count($this->_where); $i < $ien; $i++) {
             $where[$this->_where[$i]['key']] = $this->_where[$i]['value'];
             // Is there any point in this? Is there any harm?
             // Note that `whereSet` is now deprecated
             if ($this->_whereSet) {
                 if (!is_callable($this->_where[$i])) {
                     $set[$this->_where[$i]['key']] = $this->_where[$i]['value'];
                 }
             }
         }
         $db->push($this->_table, $set, $where);
     }
 }
コード例 #5
0
ファイル: Upload.php プロジェクト: kienbk1910/RDCAdmin
 /**
  * Add a record to the database for a newly uploaded file
  *
  * @param  \DataTables\Database $db Database instance
  * @return int Primary key value for the newly uploaded file
  */
 private function _dbExec($db)
 {
     $upload = $_FILES['upload'];
     $pathFields = array();
     // Insert the details requested, for the columns requested
     $q = $db->query('insert')->table($this->_dbTable);
     foreach ($this->_dbFields as $column => $prop) {
         switch ($prop) {
             case self::DB_CONTENT:
                 $q->set($column, file_get_contents($upload['tmp_name']));
                 break;
             case self::DB_CONTENT_TYPE:
             case self::DB_MIME_TYPE:
                 $finfo = finfo_open(FILEINFO_MIME);
                 $mime = finfo_file($finfo, $upload['tmp_name']);
                 finfo_close($finfo);
                 $q->set($column, $mime);
                 break;
             case self::DB_EXTN:
                 $extn = pathinfo($upload['name'], PATHINFO_EXTENSION);
                 $q->set($column, $extn);
                 break;
             case self::DB_FILE_NAME:
                 $q->set($column, $upload['name']);
                 break;
             case self::DB_FILE_SIZE:
                 $q->set($column, $upload['size']);
                 break;
             case self::DB_SYSTEM_PATH:
                 $pathFields[$column] = self::DB_SYSTEM_PATH;
                 $q->set($column, '-');
                 // Use a temporary value to avoid cases
                 break;
                 // where the db will reject empty values
             // where the db will reject empty values
             case self::DB_WEB_PATH:
                 $pathFields[$column] = self::DB_WEB_PATH;
                 $q->set($column, '-');
                 // Use a temporary value (as above)
                 break;
             default:
                 if (is_callable($prop) && is_object($prop)) {
                     // is a closure
                     $q->set($column, $prop($db, $upload));
                 } else {
                     $q->set($column, $prop);
                 }
                 break;
         }
     }
     $res = $q->exec();
     $id = $res->insertId();
     // Update the newly inserted row with the path information. We have to
     // use a second statement here as we don't know in advance what the
     // database schema is and don't want to prescribe that certain triggers
     // etc be created. It makes it a bit less efficient but much more
     // compatible
     if (count($pathFields)) {
         // For this to operate the action must be a string, which is
         // validated in the `exec` method
         $path = $this->_path($upload['name'], $id);
         $webPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path);
         $q = $db->query('update')->table($this->_dbTable)->where($this->_dbPKey, $id);
         foreach ($pathFields as $column => $type) {
             $q->set($column, $type === self::DB_WEB_PATH ? $webPath : $path);
         }
         $q->exec();
     }
     return $id;
 }