class NewsletterNewsletterController in Newsletter 7
Newsletter Newsletter Controller
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
Expanded class hierarchy of NewsletterNewsletterController
1 string reference to 'NewsletterNewsletterController'
- newsletter_entity_info in ./
newsletter.module - Implements hook_entity_info().
File
- includes/
newsletter.newsletter.controller.inc, line 11 - Controller class definition file for newsletter_newsletter entity.
View source
class NewsletterNewsletterController extends DrupalDefaultEntityController {
public function __construct($entityType) {
parent::__construct('newsletter_newsletter');
}
/**
*
*/
public function create($title, $ntid, $custom = FALSE) {
$newsletter = new stdClass();
$newsletter->title = $title;
$newsletter->ntid = $ntid;
$newsletter->custom = $custom ? 1 : 0;
$newsletter->send_id = 0;
$this
->saveNew($newsletter);
return $newsletter;
}
/**
* Saves a new custom newsletter to database.
*
* @param $newsletter
* A full newsletter object.
*/
protected function saveNew($newsletter) {
$max_send_id = db_query('SELECT MAX(send_id) as send_id
FROM {newsletter_newsletter}
WHERE title = :title AND ntid = :ntid', array(
':title' => $newsletter->title,
':ntid' => $newsletter->ntid,
))
->fetchField();
if ($max_send_id != '') {
$newsletter->send_id = ++$max_send_id;
}
drupal_write_record('newsletter_newsletter', $newsletter);
module_invoke_all('entity_insert', $newsletter, 'newsletter_newsletter');
}
/**
* Saves a newsletter to database.
*
* @param $newsletter
* A full newsletter object.
*/
public function save($newsletter) {
if (empty($newsletter->nnid)) {
return isset($newsletter->title) && isset($newsletter->ntid) ? $this
->saveNew($newsletter) : FALSE;
}
drupal_write_record('newsletter_newsletter', $newsletter, 'nnid');
field_attach_update('newsletter_newsletter', $newsletter);
module_invoke_all('entity_update', $newsletter, 'newsletter_newsletter');
}
/**
*
*/
public function saveDraft($subscribers, $draft) {
$drafts = variable_get('newsletter_custom_drafts', array());
$drafts[$draft->nnid] = array(
'subscribers' => $subscribers,
'ntid' => $draft->ntid,
);
variable_set('newsletter_custom_drafts', $drafts);
}
public function delete($nnid) {
$newsletter = newsletter_newsletter_load($nnid);
$deleted = db_delete('newsletter_newsletter')
->condition('nnid', $nnid)
->execute();
module_invoke_all('entity_delete', $newsletter, 'newsletter_newsletter');
// It's necessary to clear the caches when an entity is deleted.
cache_clear_all();
$this
->resetCache();
return $deleted ? TRUE : FALSE;
}
public function deleteDraft($nnid) {
$drafts = variable_get('newsletter_custom_drafts', array());
if (!empty($drafts[$nnid])) {
unset($drafts[$nnid]);
variable_set('newsletter_custom_drafts', $drafts);
// Also delete from database.
return $this
->delete($nnid);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalDefaultEntityController:: |
protected | property | Whether this entity type should use the static cache. | |
DrupalDefaultEntityController:: |
protected | property | Static cache of entities, keyed by entity ID. | |
DrupalDefaultEntityController:: |
protected | property | Array of information about the entity. | |
DrupalDefaultEntityController:: |
protected | property | Entity type for this controller instance. | |
DrupalDefaultEntityController:: |
protected | property | Additional arguments to pass to hook_TYPE_load(). | |
DrupalDefaultEntityController:: |
protected | property | Name of the entity's ID field in the entity database table. | |
DrupalDefaultEntityController:: |
protected | property | Name of entity's revision database table field, if it supports revisions. | |
DrupalDefaultEntityController:: |
protected | property | The table that stores revisions, if the entity supports revisions. | |
DrupalDefaultEntityController:: |
protected | function | Attaches data to entities upon loading. | 4 |
DrupalDefaultEntityController:: |
protected | function | Builds the query to load the entity. | 4 |
DrupalDefaultEntityController:: |
protected | function | Gets entities from the static cache. | 1 |
DrupalDefaultEntityController:: |
protected | function | Stores entities in the static entity cache. | |
DrupalDefaultEntityController:: |
protected | function | Ensures integer entity IDs are valid. | |
DrupalDefaultEntityController:: |
protected | function | Callback for array_filter that removes non-integer IDs. | |
DrupalDefaultEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::load(). Overrides DrupalEntityControllerInterface:: |
|
DrupalDefaultEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::resetCache(). Overrides DrupalEntityControllerInterface:: |
|
NewsletterNewsletterController:: |
public | function | ||
NewsletterNewsletterController:: |
public | function | ||
NewsletterNewsletterController:: |
public | function | ||
NewsletterNewsletterController:: |
public | function | Saves a newsletter to database. | |
NewsletterNewsletterController:: |
public | function | ||
NewsletterNewsletterController:: |
protected | function | Saves a new custom newsletter to database. | |
NewsletterNewsletterController:: |
public | function |
Constructor: sets basic variables. Overrides DrupalDefaultEntityController:: |