2014-08-06 00:16:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Database mapper for EchoTargetPage model
|
|
|
|
*/
|
|
|
|
class EchoTargetPageMapper extends EchoAbstractMapper {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of db fields used to construct an EchoTargetPage model
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
protected static $fields = array(
|
|
|
|
'etp_user',
|
|
|
|
'etp_page',
|
|
|
|
'etp_event'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2015-03-16 15:47:13 +00:00
|
|
|
* Fetch EchoTargetPage instances by user & page_id. The resulting
|
|
|
|
* array is indexed by the event id. Each entry contains an array
|
|
|
|
* of EchoTargetPage instances.
|
2014-08-06 00:16:10 +00:00
|
|
|
*
|
|
|
|
* @param User $user
|
2015-03-16 15:47:13 +00:00
|
|
|
* @param int|int[] $pageId One or more page ids to fetch target pages of
|
|
|
|
* @return EchoTargetPage[][]|boolean
|
2014-08-06 00:16:10 +00:00
|
|
|
*/
|
|
|
|
public function fetchByUserPageId( User $user, $pageId ) {
|
|
|
|
$dbr = $this->dbFactory->getEchoDb( DB_SLAVE );
|
|
|
|
|
|
|
|
$res = $dbr->select(
|
2016-03-09 19:01:42 +00:00
|
|
|
array( 'echo_target_page', 'echo_event' ),
|
|
|
|
array_merge( self::$fields, array( 'event_type' ) ),
|
2014-08-06 00:16:10 +00:00
|
|
|
array(
|
|
|
|
'etp_user' => $user->getId(),
|
|
|
|
'etp_page' => $pageId
|
|
|
|
),
|
2016-03-09 19:01:42 +00:00
|
|
|
__METHOD__,
|
|
|
|
array(),
|
|
|
|
array( 'echo_event' => array( 'JOIN', 'etp_event=event_id' ) )
|
2014-08-06 00:16:10 +00:00
|
|
|
);
|
|
|
|
if ( $res ) {
|
|
|
|
$targetPages = array();
|
|
|
|
foreach ( $res as $row ) {
|
2015-03-16 15:47:13 +00:00
|
|
|
$targetPages[$row->etp_event][] = EchoTargetPage::newFromRow( $row );
|
2014-08-06 00:16:10 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $targetPages;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:23:02 +00:00
|
|
|
/**
|
|
|
|
* Fetch ids of events associated with a page
|
|
|
|
*
|
|
|
|
* @param int $pageId
|
|
|
|
* @return int[]|false
|
|
|
|
*/
|
|
|
|
public function fetchEventIdsByPageId( $pageId ) {
|
|
|
|
$dbr = $this->dbFactory->getEchoDb( DB_SLAVE );
|
|
|
|
|
|
|
|
$res = $dbr->select(
|
|
|
|
array( 'echo_target_page' ),
|
|
|
|
array( 'eventId' => 'DISTINCT etp_event' ),
|
|
|
|
array(
|
|
|
|
'etp_page' => $pageId
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
if ( $res ) {
|
|
|
|
$eventIds = array();
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$eventIds[] = $row->eventId;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $eventIds;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
/**
|
|
|
|
* Insert an EchoTargetPage instance into the database
|
|
|
|
*
|
|
|
|
* @param EchoTargetPage $targetPage
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function insert( EchoTargetPage $targetPage ) {
|
|
|
|
$dbw = $this->dbFactory->getEchoDb( DB_MASTER );
|
|
|
|
|
|
|
|
$row = $targetPage->toDbArray();
|
|
|
|
|
|
|
|
$res = $dbw->insert( 'echo_target_page', $row, __METHOD__ );
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete an EchoTargetPage instance from the database
|
|
|
|
*
|
|
|
|
* @param EchoTargetPage
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function delete( EchoTargetPage $targetPage ) {
|
|
|
|
$dbw = $this->dbFactory->getEchoDb( DB_MASTER );
|
|
|
|
|
|
|
|
$res = $dbw->delete(
|
|
|
|
'echo_target_page',
|
|
|
|
array(
|
|
|
|
'etp_user' => $targetPage->getUser()->getId(),
|
|
|
|
'etp_page' => $targetPage->getPageId(),
|
|
|
|
'etp_event' => $targetPage->getEventId()
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2014-09-09 22:11:53 +00:00
|
|
|
/**
|
|
|
|
* Delete multiple EchoTargetPage records by user & event_id offset
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @param int $eventId
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function deleteByUserEventOffset( User $user, $eventId ) {
|
|
|
|
$dbw = $this->dbFactory->getEchoDb( DB_MASTER );
|
|
|
|
|
|
|
|
$res = $dbw->delete(
|
|
|
|
'echo_target_page',
|
|
|
|
array(
|
|
|
|
'etp_user' => $user->getId(),
|
|
|
|
'etp_event < ' . (int)$eventId
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-09-09 22:11:53 +00:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2014-08-06 00:16:10 +00:00
|
|
|
}
|