Esempio n. 1
0
 /**
  * Global setter method
  *
  * @param string $name  name of the property we want to assign a value to
  * @param object $value a relevant value for the property
  *
  * @return void
  */
 public function __set($name, $value)
 {
     if (in_array($name, $this->pagination_fields)) {
         parent::__set($name, $value);
     } else {
         Analog::log('[MembersList] Setting property `' . $name . '`', Analog::DEBUG);
         switch ($name) {
             case 'selected':
             case 'unreachable':
                 if (is_array($value)) {
                     $name = '_' . $name;
                     $this->{$name} = $value;
                 } else {
                     if ($value !== null) {
                         Analog::log('[MembersList] Value for property `' . $name . '` should be an array (' . gettype($value) . ' given)', Analog::WARNING);
                     }
                 }
                 break;
             case 'filter_str':
                 $name = '_' . $name;
                 $this->{$name} = $value;
                 break;
             case 'field_filter':
             case 'membership_filter':
             case 'account_status_filter':
                 if (is_numeric($value)) {
                     $name = '_' . $name;
                     $this->{$name} = $value;
                 } else {
                     if ($value !== null) {
                         Analog::log('[MembersList] Value for property `' . $name . '` should be an integer (' . gettype($value) . ' given)', Analog::WARNING);
                     }
                 }
                 break;
             case 'email_filter':
                 switch ($value) {
                     case Members::FILTER_DC_EMAIL:
                     case Members::FILTER_W_EMAIL:
                     case Members::FILTER_WO_EMAIL:
                         $this->_email_filter = $value;
                         break;
                     default:
                         Analog::log('[MembersList] Value for email filter should be either ' . Members::FILTER_DC_EMAIL . ', ' . Members::FILTER_W_EMAIL . ' or ' . Members::FILTER_WO_EMAIL . ' (' . $value . ' given)', Analog::WARNING);
                         break;
                 }
                 break;
             case 'group_filter':
                 if (is_numeric($value) && $value > 0) {
                     //check group existence
                     $g = new Group();
                     $res = $g->load($value);
                     if ($res === true) {
                         $this->_group_filter = $value;
                     } else {
                         Analog::log('Group #' . $value . ' does not exists!', Analog::WARNING);
                     }
                 } else {
                     if ($value !== null && $value !== '0') {
                         Analog::log('[MembersList] Value for group filter should be an ' . 'integer (' . gettype($value) . ' given)', Analog::WARNING);
                     }
                 }
                 break;
             case 'query':
                 $this->{$name} = $value;
                 break;
             default:
                 Analog::log('[MembersList] Unable to set proprety `' . $name . '`', Analog::WARNING);
                 break;
         }
     }
 }
Esempio n. 2
0
 /**
  * Global setter method
  *
  * @param string $name  name of the property we want to assign a value to
  * @param object $value a relevant value for the property
  *
  * @return void
  */
 public function __set($name, $value)
 {
     if (in_array($name, $this->pagination_fields)) {
         parent::__set($name, $value);
     } else {
         Analog::log('[History] Setting property `' . $name . '`', Analog::DEBUG);
         $forbidden = array();
         if (!in_array($name, $forbidden)) {
             $rname = '_' . $name;
             switch ($name) {
                 case 'tri':
                     if (in_array($value, $this->_fields)) {
                         $this->orderby = $value;
                     }
                     break;
                 default:
                     $this->{$rname} = $value;
                     break;
             }
         } else {
             Analog::log('[History] Unable to set proprety `' . $name . '`', Analog::WARNING);
         }
     }
 }
Esempio n. 3
0
 /**
  * Global setter method
  *
  * @param string $name  name of the property we want to assign a value to
  * @param object $value a relevant value for the property
  *
  * @return void
  */
 public function __set($name, $value)
 {
     if (in_array($name, $this->pagination_fields)) {
         parent::__set($name, $value);
     } else {
         Analog::log('[Contributions] Setting property `' . $name . '`', Analog::DEBUG);
         $forbidden = array();
         if (!in_array($name, $forbidden)) {
             $rname = '_' . $name;
             switch ($name) {
                 case 'tri':
                     $allowed_orders = array(self::ORDERBY_DATE, self::ORDERBY_BEGIN_DATE, self::ORDERBY_END_DATE, self::ORDERBY_MEMBER, self::ORDERBY_TYPE, self::ORDERBY_AMOUNT, self::ORDERBY_DURATION);
                     if (in_array($value, $allowed_orders)) {
                         $this->orderby = $value;
                     }
                     break;
                 case 'start_date_filter':
                 case 'end_date_filter':
                     try {
                         if ($value !== '') {
                             $y = \DateTime::createFromFormat(_T("Y"), $value);
                             if ($y !== false) {
                                 $month = 1;
                                 $day = 1;
                                 if ($name === 'end_date_filter') {
                                     $month = 12;
                                     $day = 31;
                                 }
                                 $y->setDate($y->format('Y'), $month, $day);
                                 $this->{$rname} = $y->format('Y-m-d');
                             }
                             $ym = \DateTime::createFromFormat(_T("Y-m"), $value);
                             if ($y === false && $ym !== false) {
                                 $day = 1;
                                 if ($name === 'end_date_filter') {
                                     $day = $ym->format('t');
                                 }
                                 $ym->setDate($ym->format('Y'), $ym->format('m'), $day);
                                 $this->{$rname} = $ym->format('Y-m-d');
                             }
                             $d = \DateTime::createFromFormat(_T("Y-m-d"), $value);
                             if ($y === false && $ym === false && $d !== false) {
                                 $this->{$rname} = $d->format('Y-m-d');
                             }
                             if ($y === false && $ym === false && $d === false) {
                                 $formats = array(_T("Y"), _T("Y-m"), _T("Y-m-d"));
                                 $field = null;
                                 if ($name === 'start_date_filter') {
                                     $field = _T("start date filter");
                                 }
                                 if ($name === 'end_date_filter') {
                                     $field = _T("end date filter");
                                 }
                                 throw new \Exception(str_replace(array('%field', '%format'), array($field, implode(', ', $formats)), _T("Unknown date format for %field.<br/>Know formats are: %formats")));
                             }
                         } else {
                             $this->{$rname} = null;
                         }
                     } catch (\Exception $e) {
                         Analog::log('Wrong date format. field: ' . $key . ', value: ' . $value . ', expected fmt: ' . _T("Y-m-d") . ' | ' . $e->getMessage(), Analog::INFO);
                         throw $e;
                     }
                     break;
                 default:
                     $this->{$rname} = $value;
                     break;
             }
         } else {
             Analog::log('[Contributions] Unable to set proprety `' . $name . '`', Analog::WARNING);
         }
     }
 }