101 $image_nicename =
null;
102 $image_mimetype =
null;
103 $image_display =
null;
104 $image_weight =
null;
106 if (
'xoopsimage' != strtolower(get_class($image))) {
109 if (!$image->isDirty()) {
112 if (!$image->cleanVars()) {
115 foreach ($image->cleanVars as $k => $v) {
118 if ($image->isNew()) {
119 $image_id = $this->db->genId(
'image_image_id_seq');
120 $sql = sprintf(
'INSERT INTO %s (image_id, image_name, image_nicename, image_mimetype, image_created, image_display, image_weight, imgcat_id) VALUES (%u, %s, %s, %s, %u, %u, %u, %u)', $this->db->prefix(
'image'), $image_id, $this->db->quoteString($image_name), $this->db->quoteString($image_nicename), $this->db->quoteString($image_mimetype), time(), $image_display, $image_weight, $imgcat_id);
121 if (!$result = $this->db->query($sql)) {
124 if (empty($image_id)) {
125 $image_id = $this->db->getInsertId();
127 if (isset($image_body) &&
'' != $image_body) {
128 $sql = sprintf(
'INSERT INTO %s (image_id, image_body) VALUES (%u, %s)', $this->db->prefix(
'imagebody'), $image_id, $this->db->quoteString($image_body));
129 if (!$result = $this->db->query($sql)) {
130 $sql = sprintf(
'DELETE FROM %s WHERE image_id = %u', $this->db->prefix(
'image'), $image_id);
131 $this->db->query($sql);
135 $image->assignVar(
'image_id', $image_id);
137 $sql = sprintf(
'UPDATE %s SET image_name = %s, image_nicename = %s, image_display = %u, image_weight = %u, imgcat_id = %u WHERE image_id = %u', $this->db->prefix(
'image'), $this->db->quoteString($image_name), $this->db->quoteString($image_nicename), $image_display, $image_weight, $imgcat_id, $image_id);
138 if (!$result = $this->db->query($sql)) {
141 if (isset($image_body) &&
'' != $image_body) {
142 $sql = sprintf(
'UPDATE %s SET image_body = %s WHERE image_id = %u', $this->db->prefix(
'imagebody'), $this->db->quoteString($image_body), $image_id);
143 if (!$result = $this->db->query($sql)) {
144 $this->db->query(sprintf(
'DELETE FROM %s WHERE image_id = %u', $this->db->prefix(
'image'), $image_id));
181 public function &
getObjects($criteria =
null, $id_as_key =
false, $getbinary =
false)
186 $sql =
'SELECT i.*, b.image_body FROM '.$this->db->prefix(
'image').
' i LEFT JOIN '.$this->db->prefix(
'imagebody').
' b ON b.image_id=i.image_id';
188 $sql =
'SELECT * FROM '.$this->db->prefix(
'image');
190 if (isset($criteria) && $criteria instanceof \criteriaelement) {
191 $sql .=
' '.$criteria->renderWhere();
192 $sort = !in_array($criteria->getSort(), [
'image_id',
'image_created',
'image_mimetype',
'image_display',
'image_weight']) ?
'image_weight' : $criteria->getSort();
193 $sql .=
' ORDER BY '.$sort.
' '.$criteria->getOrder();
194 $limit = $criteria->getLimit();
195 $start = $criteria->getStart();
197 $result = $this->db->query($sql, $limit, $start);
201 while ($myrow = $this->db->fetchArray($result)) {
203 $image->assignVars($myrow);
207 $ret[$myrow[
'image_id']] =& $image;
240 public function &
getList($imgcat_id, $image_display =
null)
243 if (isset($image_display)) {
244 $criteria->add(
new Criteria(
'image_display', (
int)$image_display));
246 $images =& $this->
getObjects($criteria,
false,
true);
248 foreach (array_keys($images) as $i) {
249 $ret[$images[$i]->getVar(
'image_name')] = $images[$i]->getVar(
'image_nicename');