Advertisement
tribulant

Groups

Sep 13th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. <?php
  2.  
  3. class wpmlGroup extends wpMailPlugin {
  4.    
  5.     var $model = 'wpmlGroup';
  6.     var $controller = 'groups';
  7.     var $table;
  8.    
  9.     var $fields = array(
  10.         'id'                =>  "INT(11) NOT NULL AUTO_INCREMENT",
  11.         'title'             =>  "VARCHAR(100) NOT NULL DEFAULT ''",
  12.         'created'           =>  "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'",
  13.         'modified'          =>  "DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'",
  14.         'key'               =>  "PRIMARY KEY (`id`)",
  15.     );
  16.    
  17.     var $tv_fields = array(
  18.         'id'                =>  array("INT(11)", "NOT NULL AUTO_INCREMENT"),
  19.         'title'             =>  array("VARCHAR(100)", "NOT NULL DEFAULT ''"),
  20.         'created'           =>  array("DATETIME", "NOT NULL DEFAULT '0000-00-00 00:00:00'"),
  21.         'modified'          =>  array("DATETIME", "NOT NULL DEFAULT '0000-00-00 00:00:00'"),
  22.         'key'               =>  "PRIMARY KEY (`id`)",
  23.     );
  24.    
  25.     function wpmlGroup($data = array()) {
  26.         global $wpdb, $Db;
  27.         $this -> table = $this -> pre . $this -> controller;
  28.        
  29.         if (!empty($data)) {           
  30.             foreach ($data as $dkey => $dval) {
  31.                 $this -> {$dkey} = stripslashes_deep($dval);
  32.             }
  33.         }
  34.    
  35.         return true;   
  36.     }
  37.    
  38.     function defaults() {
  39.         global $Html;
  40.        
  41.         $defaults = array(
  42.             'created'           =>  $Html -> gen_date(),
  43.             'modified'          =>  $Html -> gen_date(),
  44.         );
  45.        
  46.         return $defaults;  
  47.     }
  48.    
  49.     function validate($data = array()) {
  50.         $this -> errors = array();
  51.        
  52.         $data = (empty($data[$this -> model])) ? $data : $data[$this -> model];
  53.         $r = wp_parse_args($data, $defaults);
  54.         extract($r, EXTR_SKIP);
  55.        
  56.         if (!empty($data)) {
  57.             if (empty($title)) { $this -> errors['title'] = __('Please fill in a title for this group.', $this -> plugin_name); }
  58.         } else {
  59.             $this -> errors[] = __('No data was posted', $this -> plugin_name);
  60.         }
  61.        
  62.         return $this -> errors;
  63.     }
  64.    
  65.     function get_all_paginated($conditions = array(), $searchterm = null, $sub = 'newsletters-groups', $perpage = 15, $order = array('modified', "DESC")) {
  66.         global $wpdb;
  67.        
  68.         $paginate = new wpMailPaginate($wpdb -> prefix . "" . $this -> table, "*", $sub);
  69.         $paginate -> per_page = $perpage;
  70.         $paginate -> searchterm = (empty($searchterm)) ? false : $searchterm;
  71.         $paginate -> where = (empty($conditions)) ? false : $conditions;
  72.         $paginate -> order = $order;
  73.         $groups = $paginate -> start_paging($_GET[$this -> pre . 'page']);
  74.        
  75.         $data = array();
  76.         $data['Pagination'] = $paginate;
  77.         $data[$this -> model] = $groups;
  78.        
  79.         return $data;
  80.     }
  81.    
  82.     function select() {
  83.         global $wpdb, $Html;
  84.         $query = "SELECT `id`, `title` FROM `" . $wpdb -> prefix . "" . $this -> table . "` ORDER BY `title` ASC";
  85.  
  86.         if ($groups = $wpdb -> get_results($query)) {
  87.             if (!empty($groups)) {         
  88.                 $groupsselect = array();
  89.                
  90.                 foreach ($groups as $group) {
  91.                     $groupsselect[$group -> id] = $group -> title;
  92.                 }
  93.                
  94.                 return $groupsselect;
  95.             }
  96.         }
  97.        
  98.         return false;
  99.     }
  100. }
  101.  
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement