17 import(
'classes.spotlight.Spotlight');
24 parent::__construct();
34 'SELECT * FROM spotlights WHERE spotlight_id = ?',
39 if ($result->RecordCount() != 0) {
40 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
53 'SELECT assoc_id FROM spotlights WHERE spotlight_id = ?',
57 $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
69 'SELECT assoc_type FROM spotlights WHERE spotlight_id = ?',
73 $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
83 return array(
'title',
'description');
101 $spotlight->setId($row[
'spotlight_id']);
102 $spotlight->setAssocType($row[
'assoc_type']);
103 $spotlight->setAssocId($row[
'assoc_id']);
104 $spotlight->setPressId($row[
'press_id']);
106 $this->
getDataObjectSettings(
'spotlight_settings',
'spotlight_id', $row[
'spotlight_id'], $spotlight);
117 'spotlight_id' => $spotlight->getId()
128 'INSERT INTO spotlights
129 (assoc_type, assoc_id, press_id)
133 (
int) $spotlight->getAssocType(),
134 (
int) $spotlight->getAssocId(),
135 (
int) $spotlight->getPressId(),
140 return $spotlight->getId();
149 $returner = $this->
update(
155 WHERE spotlight_id = ?',
157 (
int) $spotlight->getAssocType(),
158 (
int) $spotlight->getAssocId(),
159 (
int) $spotlight->getPressId(),
160 (
int) $spotlight->getId()
173 return $this->
deleteById($spotlight->getId());
182 $this->
update(
'DELETE FROM spotlight_settings WHERE spotlight_id = ?', (
int) $spotlightId);
183 return $this->
update(
'DELETE FROM spotlights WHERE spotlight_id = ?', (
int) $spotlightId);
192 $spotlights = $this->getByTypeId($typeId);
193 while (($spotlight = $spotlights->next())) {
204 $spotlights = $this->getByAssocId($assocType, $assocId);
205 while ($spotlight = $spotlights->next()) {
221 ORDER BY spotlight_id DESC',
222 array((
int) $pressId),
230 while ($spotlight = $spotlightFactory->next()) {
231 $spotlightItem = $spotlight->getSpotlightItem();
232 if ($spotlightItem) {
233 $returner[$spotlight->getId()] = $spotlight;
248 $spotlights = array_values($this->
getByPressId($pressId));
250 if (count($spotlights) > 0) {
251 if (count($spotlights) <= $quantity) {
253 $returner = $spotlights;
256 for($quantity; $quantity > 0; $quantity--) {
257 $randNumber = rand(0, count($spotlights) - 1);
258 $returner[] = $spotlights[$randNumber];
259 unset($spotlights[$randNumber]);
261 $spotlights = array_values($spotlights);
266 if (count($returner) == 0) {
279 function getByAssoc($assocType, $assocId, $rangeInfo =
null) {
283 WHERE assoc_type = ? AND assoc_id = ?
284 ORDER BY spotlight_id DESC',
285 array((
int) $assocType, (
int) $assocId),
303 ORDER BY spotlight_id DESC',
304 array((
int) $assocType, (
int) $assocId),
322 ORDER BY spotlight_id DESC LIMIT 1',
323 array((
int) $assocType, (
int) $assocId)
327 if ($result->RecordCount() != 0) {
328 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
339 return $this->
_getInsertId(
'spotlights',
'spotlight_id');