Exemplo n.º 1
0
 /**
  * declare a child control to the form. The given control should be a child of an other control
  * @param jFormsControl $control
  */
 public function addChildControl($control)
 {
     $this->controls[$control->ref] = $control;
     if ($control->type == 'submit') {
         $this->submits[$control->ref] = $control;
     } else {
         if ($control->type == 'reset') {
             $this->reset = $control;
         } else {
             if ($control->type == 'upload') {
                 $this->uploads[$control->ref] = $control;
             } else {
                 if ($control->type == 'hidden') {
                     $this->hiddens[$control->ref] = $control;
                 } else {
                     if ($control->type == 'htmleditor') {
                         $this->htmleditors[$control->ref] = $control;
                     }
                 }
             }
         }
     }
     $control->setForm($this);
     if (!isset($this->container->data[$control->ref])) {
         if ($control->datatype instanceof jDatatypeDateTime && $control->defaultValue == 'now') {
             $dt = new jDateTime();
             $dt->now();
             $this->container->data[$control->ref] = $dt->toString($control->datatype->getFormat());
         } else {
             $this->container->data[$control->ref] = $control->defaultValue;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Substract a date with another
  * @param jDateTime $date
  * @return jDateTime
  * @author Hadrien Lanneau <*****@*****.**>
  * @since 1.2
  */
 public function substract($date = null)
 {
     if (!$date) {
         $date = new jDateTime();
         $date->now();
     }
     $newDate = new jDateTime();
     $items = array('second', 'minute', 'hour', 'day', 'month', 'year');
     foreach ($items as $k => $i) {
         $newDate->{$i} = $date->{$i} - $this->{$i};
         if ($newDate->{$i} < 0) {
             switch ($i) {
                 case 'second':
                 case 'minute':
                     $sub = 60;
                     break;
                 case 'hour':
                     $sub = 24;
                     break;
                 case 'day':
                     switch ($this->month) {
                         // Month with 31 days
                         case 1:
                         case 3:
                         case 5:
                         case 7:
                         case 8:
                         case 10:
                         case 12:
                             $sub = 31;
                             break;
                             // Month with 30 days
                         // Month with 30 days
                         case 4:
                         case 6:
                         case 9:
                         case 11:
                             $sub = 30;
                             break;
                             // February
                         // February
                         case 2:
                             if ($this->year % 4 == 0 and !($this->year % 100 == 0 and $this->year % 400 != 0)) {
                                 // Bissextile
                                 $sub = 29;
                             } else {
                                 $sub = 28;
                             }
                             break;
                     }
                     break;
                 case 'month':
                     $sub = 12;
                     break;
                 default:
                     $sub = 0;
             }
             $newDate->{$i} = abs($sub + $newDate->{$i});
             if (isset($items[$k + 1])) {
                 $newDate->{$items[$k + 1]}--;
             }
         }
     }
     return $newDate;
 }
Exemplo n.º 3
0
 /**
  * dao handler for session stored in database
  */
 public static function daoGarbageCollector($maxlifetime)
 {
     $date = new jDateTime();
     $date->now();
     $date->sub(0, 0, 0, 0, 0, $maxlifetime);
     self::_getDao()->deleteExpired($date->toString(jDateTime::BD_DTFORMAT));
     return true;
 }
Exemplo n.º 4
0
 /**
  *
  */
 function save()
 {
     $rep = $this->getResponse('json');
     $receiver_id = $this->intParam('receiver_id', 0, true);
     $content = $this->param('content', '', true);
     //insert
     if (!empty($content) && !empty($receiver_id)) {
         $this->msg = 'Message non envoyé';
         // instanciation de la factory
         $tb = jDao::get("message");
         // creation d'un record correspondant au dao foo
         $record = jDao::createRecord("message");
         // on remplit le record
         $record->receiver_id = $receiver_id;
         $record->sender_id = jAuth::getUserSession()->id;
         $record->content = $content;
         $dt = new jDateTime();
         $dt->now();
         $record->createdate = $dt->toString(jDateTime::DB_DTFORMAT);
         // on le sauvegarde dans la base
         try {
             $tb->insert($record);
             $this->success = true;
             $this->msg = "Message envoyé ";
         } catch (Exception $e) {
             $this->success = false;
             $this->msg = "Message non envoyé ";
         }
     }
     $rep->data = array('success' => $this->success, 'msg' => $this->msg);
     return $rep;
 }