/**
  * findByProperties
  * @param array $properties
  * @return array of objects
  */
 public static function findByProperties(array $properties)
 {
     $object = new static();
     $filters = array();
     $values = array();
     $sql = 'select ' . $object->getPropertiesString() . ' ' . 'from ' . $object->table . ' ' . 'where ';
     foreach ($properties as $key => $value) {
         $filters[] = $key . ' = ?';
         $values[] = $value;
     }
     $sql .= join(' and ', $filters) . ';';
     return $object->fetch($sql, $values);
 }
 public function findAll($asMap = false)
 {
     $tokenMappings = array();
     $bao = new static();
     $bao->find(false);
     while ($bao->fetch()) {
         if ($asMap) {
             $tokenMappings[$bao->mailchimp_token] = $bao->civicrm_token;
         } else {
             $tokenMappings[] = array('id' => $bao->id, 'civicrm_token' => $bao->civicrm_token, 'mailchimp_token' => $bao->mailchimp_token);
         }
     }
     return $tokenMappings;
 }
Example #3
0
 /**
  * signon
  * Takes an array of keyword arguments, attempts to find the user and sign him/her on.
  **/
 public static function signon($kwargs)
 {
     $creds = array();
     if (!empty($kwargs['user_login'])) {
         $creds['user_login'] = $kwargs['user_login'];
     } elseif (!empty($kwargs['user_email'])) {
         $collection = static::$collection;
         $user = $collection::get_by(array('user_email' => $kwargs['user_email']));
         $creds['user_login'] = $user->user_login;
     } else {
         throw new JsonableException(__("Please enter your user name or email address.", 'mtv'));
     }
     if (empty($kwargs['user_pass'])) {
         throw new JsonableException(__('Please enter your password.', 'mtv'));
     }
     $creds['user_password'] = $kwargs['user_pass'];
     $result = wp_signon($creds, true);
     if (is_wp_error($result)) {
         throw new WPException($result);
     } else {
         // TODO:
         // Implement "remember me" functionality with wp_set_auth_cookie
         wp_set_auth_cookie($result->ID, true);
         // wp_set_current_user($result->ID);
     }
     $user = new static(array('id' => $result->ID));
     $user->fetch();
     return $user;
 }