static function getUniqueName()
 {
     $sibling = new self();
     do {
         $uniqid = uniqid("f");
         $where = array("name" => "= '{$uniqid}'");
         $sibling->loadObject($where);
     } while ($sibling->_id);
     return $uniqid;
 }
 /**
  * Change a particular configuration value
  *
  * @param string    $feature Feature
  * @param mixed     $value   Value
  * @param CMbObject $object  Host object
  *
  * @return null|string Store-like message
  */
 static function setConfig($feature, $value, CMbObject $object = null)
 {
     $where = array("feature" => "= '{$feature}'");
     if ($object) {
         $where["object_class"] = "= '{$object->_class}'";
         $where["object_id"] = "= '{$object->_id}'";
     } else {
         $where["object_class"] = "IS NULL";
         $where["object_id"] = "IS NULL";
     }
     $_config = new self();
     $_config->loadObject($where);
     $inherit = $value === self::INHERIT;
     if ($_config->_id && $inherit) {
         return $_config->delete();
     } elseif (!$inherit) {
         if ($object) {
             $_config->setObject($object);
         } else {
             $_config->object_id = null;
             $_config->object_class = null;
         }
         $_config->feature = $feature;
         $_config->value = $value;
         return $_config->store();
     }
     return null;
 }
 /**
  * Get a stock from a product code
  *
  * @param string $code Product code
  *
  * @return CProductStockGroup
  */
 static function getFromCode($code)
 {
     $stock = new self();
     $where = array('product.code' => "= '{$code}'");
     $ljoin = array('product' => 'product_stock_group.product_id = product.product_id');
     $stock->loadObject($where, null, null, $ljoin);
     return $stock;
 }
 /**
  * Récupération de l'uf
  *
  * @param string $code_uf  code de l'uf
  * @param string $type     type de l'uf
  * @param int    $group_id group
  * @param string $date_deb date de début
  * @param string $date_fin date de fin
  *
  * @return CUniteFonctionnelle
  */
 static function getUF($code_uf, $type = null, $group_id = null, $date_deb = null, $date_fin = null)
 {
     $uf = new self();
     if (!$code_uf) {
         return $uf;
     }
     $group_id = $group_id ? $group_id : CGroups::loadCurrent()->_id;
     $where["code"] = " = '{$code_uf}'";
     $where["type"] = " = '{$type}'";
     $where["group_id"] = " = '{$group_id}'";
     if ($date_fin) {
         $where[] = "uf.date_debut IS NULL OR uf.date_debut < '" . CMbDT::date($date_fin) . "'";
     }
     if ($date_deb) {
         $where[] = "uf.date_fin IS NULL OR uf.date_fin > '" . CMbDT::date($date_deb) . "'";
     }
     $uf->loadObject($where);
     return $uf;
 }
 /**
  * @see parent::check()
  */
 function check()
 {
     if ($this->_id) {
         $oldObj = new CDocGed();
         $oldObj->load($this->_id);
         if ($this->group_id === null) {
             $this->group_id = $oldObj->group_id;
         }
         if ($this->doc_chapitre_id === null) {
             $this->doc_chapitre_id = $oldObj->doc_chapitre_id;
         }
         if ($this->doc_categorie_id === null) {
             $this->doc_categorie_id = $oldObj->doc_categorie_id;
         }
         if ($this->num_ref === null) {
             $this->num_ref = $oldObj->num_ref;
         }
         if ($this->annule === null) {
             $this->annule = $oldObj->annule;
         }
     }
     if ($this->annule == 1) {
         return null;
     }
     $where = array();
     if ($this->_id) {
         $where["doc_ged_id"] = "!= '" . $this->_id . "'";
     }
     $where["num_ref"] = "IS NOT NULL";
     $where["group_id"] = "= '" . $this->group_id . "'";
     $where["doc_chapitre_id"] = "= '" . $this->doc_chapitre_id . "'";
     $where["doc_categorie_id"] = "= '" . $this->doc_categorie_id . "'";
     $where["num_ref"] = "= '" . $this->num_ref . "'";
     $where["annule"] = "= '0'";
     $order = "num_ref DESC";
     $sameNumRef = new self();
     $sameNumRef->loadObject($where, $order);
     if ($sameNumRef->_id) {
         return "Un document existe déjà avec la même référence";
     }
     return null;
 }
 /**
  * Get Stock from product code and service ID
  *
  * @param string $code       Product code
  * @param int    $service_id Service ID
  *
  * @return CProductStockService
  */
 static function getFromCode($code, $service_id = null)
 {
     $stock = new self();
     $where = array();
     $where['product.code'] = "= '{$code}'";
     $where['product_stock_service.object_class'] = "= 'CService'";
     // XXX
     if ($service_id) {
         $where['product_stock_service.object_id'] = "= '{$service_id}'";
     }
     $ljoin = array();
     $ljoin['product'] = 'product_stock_service.product_id = product.product_id';
     $stock->loadObject($where, null, null, $ljoin);
     return $stock;
 }
 /**
  * Get date last checklist for a type
  *
  * @param CMbObject $object Object to get the check lists of
  * @param string    $type   type de checklist
  *
  * @return date
  */
 static function getDateLastChecklist(CMbObject $object, $type)
 {
     $date_last_checklist = null;
     $ljoin = array();
     $ljoin["daily_check_list_type"] = "daily_check_list_type.daily_check_list_type_id = daily_check_list.list_type_id";
     $where = array();
     $where["daily_check_list.object_class"] = " = '{$object->_class}'";
     $where["daily_check_list.object_id"] = " = '{$object->_id}'";
     $where["daily_check_list_type.type"] = " = '{$type}'";
     $checklist = new self();
     $checklist->loadObject($where, "date DESC", null, $ljoin);
     if ($checklist->_id) {
         if ($checklist->date_validate) {
             $date_last_checklist = $checklist->date_validate;
         } else {
             $log = new CUserLog();
             $log->object_id = $checklist->_id;
             $log->object_class = $checklist->_class;
             $log->loadMatchingObject("date DESC", "user_log_id");
             $date_last_checklist = $log->date;
         }
     }
     if (!$checklist->_id || !$date_last_checklist) {
         $date_last_checklist = $checklist->date;
     }
     return $date_last_checklist;
 }
Example #8
0
 /**
  * Gets the object value at a specific date
  *
  * @param CMbObject $object The object to get the value of
  * @param datetime  $date   The date
  * @param string    $field  Field name
  *
  * @return mixed
  */
 static function getObjectValueAtDate(CMbObject $object, $date, $field)
 {
     $where = array("object_class" => "= '{$object->_class}'", "object_id" => "= '{$object->_id}'", "type" => "IN('store', 'merge')", "extra IS NOT NULL AND extra != '[]'");
     if ($date) {
         $where["date"] = ">= '{$date}'";
     }
     $where[] = "\n      fields LIKE '{$field}' OR \n      fields LIKE '{$field} %' OR \n      fields LIKE '% {$field}' OR \n      fields LIKE '% {$field} %'";
     $user_log = new self();
     $user_log->loadObject($where, "date ASC");
     if ($user_log->_id) {
         $user_log->getOldValues();
     }
     return CValue::read($user_log->_old_values, $field, $object->{$field});
 }