コード例 #1
0
 /**
  * Prepare and sanitise the table data prior to saving.
  *
  * @param   JTable  $table  A reference to a JTable object.
  *
  * @return  void
  */
 protected function prepareTable(\JTable $table)
 {
     $date = DateHelper::getDate('now');
     $user = $this->container->get('user');
     $key = $table->getKeyName();
     // Alias
     if (property_exists($table, 'alias')) {
         if (!$table->alias) {
             $table->alias = JFilterOutput::stringURLSafe(trim($table->title));
         } else {
             $table->alias = JFilterOutput::stringURLSafe(trim($table->alias));
         }
         if (!$table->alias) {
             $table->alias = JFilterOutput::stringURLSafe($date->toSql(true));
         }
     }
     // Created date
     if (property_exists($table, 'created')) {
         if ($table->created) {
             $table->created = DateHelper::toServerTime($table->created);
         } else {
             $table->created = $date->toSql();
         }
     }
     // Publish_up date
     if (property_exists($table, 'publish_up')) {
         if ($table->publish_up) {
             $table->publish_up = DateHelper::toServerTime($table->publish_up);
         } else {
             $table->publish_up = $this->db->getNullDate();
         }
     }
     // Publish_down date
     if (property_exists($table, 'publish_down')) {
         if ($table->publish_down) {
             $table->publish_down = DateHelper::toServerTime($table->publish_down);
         } else {
             $table->publish_down = $this->db->getNullDate();
         }
     }
     // Modified date
     if (property_exists($table, 'modified') && $table->{$key}) {
         $table->modified = $date->toSql();
     }
     // Created user
     if (property_exists($table, 'created_by') && !$table->created_by) {
         $table->created_by = $user->get('id');
     }
     // Modified user
     if (property_exists($table, 'modified_by') && $table->{$key}) {
         $table->modified_by = $user->get('id');
     }
     // Set Ordering or Nested ordering
     if (property_exists($table, 'ordering')) {
         if (empty($table->id)) {
             $this->setOrderPosition($table);
         }
     }
 }
コード例 #2
0
 /**
  * Convert some common fields to server timezone.
  *
  * @param   object  $item    The item data object.
  * @param   array   $fields  The fields we want to convert.
  *
  * @return  object  Return converted data.
  */
 public static function itemDatesToServer($item, array $fields = null)
 {
     if (!is_object($item)) {
         throw new \InvalidArgumentException('Item should be object.');
     }
     if (!$fields) {
         $fields = array('created', 'publish_up', 'publish_down', 'modified');
     }
     foreach ($fields as $field) {
         if (property_exists($item, $field)) {
             $item->{$field} = DateHelper::toServerTime($item->{$field});
         }
     }
     return $item;
 }