Joywork/constructor/Models/ObjectModel.php

100 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
class ObjectModel extends BaseModel {
public function getAll()
{
// $userAgencyId = $this->arrToString($agency_id);
$sqlObjectsData = "SELECT * FROM objects WHERE use_in_advert = 1 AND id_add_user = {$this->agent['id']}";
$objectDataQuery = $this->db->query($sqlObjectsData);
$objectData = [];
while ($objectDataResult = $this->db->fetch_assoc($objectDataQuery)) {
$object_id = $objectDataResult['id'];
$objectPrices = $this->getObjectPrice([$object_id]);
$objectPhotos = $this->getObjectPhoto([$object_id]);
$objectComments = $this->getObjectComments([$object_id]);
$objectPlan = $this->getObjectPlan([$object_id]);
$objectDataResult['prices'] = $objectPrices;
$objectDataResult['photos'] = $objectPhotos;
$objectDataResult['comments'] = $objectComments;
$objectDataResult['plan'] = $objectPlan;
$objectData[] = $objectDataResult;
}
return $objectData;
}
public function getOnlyOne($params)
{
$object_id = $params['object_id'];
$sql = "SELECT * FROM objects WHERE id = {$object_id}";
$objectDataQuery = $this->db->query($sql);
$object = $this->db->fetch_assoc($objectDataQuery);
if (!empty($object)) {
$objectPrices = $this->getObjectPrice([$object_id]);
$objectPhotos = $this->getObjectPhoto([$object_id]);
$objectComments = $this->getObjectComments([$object_id]);
$objectPlan = $this->getObjectPlan([$object_id]);
$object['prices'] = $objectPrices;
$object['photos'] = $objectPhotos;
$object['comments'] = $objectComments;
$object['plan'] = $objectPlan;
}
return $object;
}
public function getObjectPrice($object_id)
{
$objectPricesId = implode(',', array_map('intval', $object_id));
$sqlObjectPrices = "SELECT * FROM object_prices WHERE object_id IN ($objectPricesId)";
$objectPricesQuery = $this->db->query($sqlObjectPrices);
$objectPrices = [];
while ($objectPricesRes = $this->db->fetch_assoc($objectPricesQuery)) {
$objectPrices[] = $objectPricesRes;
}
return $objectPrices;
}
public function getObjectPhoto($object_id)
{
$objectPhotosId = $this->arrToString($object_id);
$sqlObjectPhotos = "SELECT objects_object_photo.sort_order, object_photo.photo
FROM objects_object_photo, object_photo
WHERE object_photo.id = objects_object_photo.object_photo_id
AND objects_object_photo.object_id = $objectPhotosId
ORDER BY objects_object_photo.sort_order";
$objectPhotosQuery = $this->db->query($sqlObjectPhotos);
$objectPhotos = [];
while ($objectPhotosRes = $this->db->fetch_assoc($objectPhotosQuery)) {
$objectPhotos[] = $objectPhotosRes;
}
return $objectPhotos;
}
public function getObjectComments($object_id) {
$objectCommentsId = $this->arrToString($object_id);
$sqlObjectComments = "SELECT * FROM user_object_comments WHERE object_id IN ($objectCommentsId)";
$objectCommentsQuery = $this->db->query($sqlObjectComments);
$objectComments = [];
while ($objectCommentsRes = $this->db->fetch_assoc($objectCommentsQuery)) {
$objectComments[] = $objectCommentsRes;
}
return $objectComments;
}
public function getObjectPlan($object_id) {
$objectPlanId = $this->arrToString($object_id);
$sqlObjectPlan = "SELECT * FROM objects_plan WHERE object_id IN ($objectPlanId)";
$objectPlanQuery = $this->db->query($sqlObjectPlan);
$objectPlan = [];
while ($objectPlanRes = $this->db->fetch_assoc($objectPlanQuery)) {
$objectPlan[] = $objectPlanRes;
}
return $objectPlan;
}
}