[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_Post.class.php (source)

   1  <?php
   2  class MP_Post
   3  {
   4      const meta_key = MailPress_post::meta_key;
   5      const meta_key_order =  MailPress_post::meta_key_order;
   6  
   7  	public static function exists($mp_mail_id, $post_id) 
   8      {
   9          return MP_Mail_meta::get( $mp_mail_id, self::meta_key, $post_id );
  10      }
  11  
  12  	public static function insert($mp_mail_id, $post_id) 
  13      {
  14          if (self::exists($mp_mail_id, $post_id)) return;
  15  
  16          $meta_value   = MP_Mail_meta::get( $mp_mail_id, self::meta_key_order );
  17          $meta_value[$post_id] = $post_id;
  18          if (!MP_Mail_meta::add( $mp_mail_id, self::meta_key_order, $meta_value, true ))
  19              MP_Mail_meta::update( $mp_mail_id, self::meta_key_order, $meta_value );
  20  
  21          return MP_Mail_meta::add( $mp_mail_id, self::meta_key, $post_id );
  22      }
  23  
  24  	public static function delete($mp_mail_id, $post_id) 
  25      {
  26          $meta_value   = MP_Mail_meta::get( $mp_mail_id, self::meta_key_order );
  27          unset($meta_value[$post_id]);
  28          if (empty($meta_value)) MP_Mail_meta::delete( $mp_mail_id, self::meta_key_order );
  29          else                 MP_Mail_meta::update( $mp_mail_id, self::meta_key_order, $meta_value );
  30  
  31          return MP_Mail_meta::delete( $mp_mail_id, self::meta_key, $post_id );
  32      }
  33  
  34  	public static function delete_post($post_id) 
  35      {
  36          global $wpdb;
  37          $mails = $wpdb->get_results( $wpdb->prepare( "SELECT mp_mail_id FROM $wpdb->mp_mailmeta WHERE meta_key = %s AND meta_value = %s", self::meta_key, $post_id ) );
  38          if (!$mails) return true;
  39          foreach($mails as $mail) self::delete( $mail->mp_mail_id, $post_id );
  40          return true;
  41      }
  42  
  43  // retourne les drafts d'un post
  44  	public static function get_term_objects($post_id)
  45      {
  46          global $wpdb;
  47          $mails = $wpdb->get_results( $wpdb->prepare( "SELECT mp_mail_id FROM $wpdb->mp_mailmeta WHERE meta_key = %s AND meta_value = %s ORDER BY mp_mail_id;", self::meta_key, $post_id ) );
  48          if (!$mails) return array();
  49          foreach($mails as $mail) $_objects[$mail->mp_mail_id] = $mail->mp_mail_id;
  50          return $_objects;
  51      }
  52  
  53  	public static function get_object_terms( $mp_mail_id )
  54      {
  55          $_terms = MP_Mail_meta::get( $mp_mail_id, self::meta_key_order );
  56          return $_terms;
  57      }
  58  
  59  	public static function object_have_relations( $mp_mail_id )
  60      {
  61          return MP_Mail_meta::get( $mp_mail_id, self::meta_key );
  62      }
  63  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1