canApplyOn() 정적인 공개 메소드

Check if given object can have InfoCom
static public canApplyOn ( $item ) : true
$item an object or a string
리턴 true if $object is an object that can have InfoCom
예제 #1
0
 /**
  * Add an item in the database with all it's items.
  *
  * @param $input     array    the _POST vars returned by the item form when press add
  * @param options    array    with the insert options
  *   - unicity_message : do not display message if item it a duplicate (default is yes)
  * @param $history   boolean  do history log ? (true by default)
  *
  * @return integer the new ID of the added item (or false if fail)
  **/
 function add(array $input, $options = array(), $history = true)
 {
     global $DB, $CFG_GLPI;
     if ($DB->isSlave()) {
         return false;
     }
     // Store input in the object to be available in all sub-method / hook
     $this->input = $input;
     if (isset($this->input['add'])) {
         // Input from the interface
         // Save this data to be available if add fail
         $this->saveInput();
     }
     // Call the plugin hook - $this->input can be altered
     // This hook get the data from the form, not yet altered
     Plugin::doHook("pre_item_add", $this);
     if ($this->input && is_array($this->input)) {
         if (isset($this->input['add'])) {
             $this->input['_add'] = $this->input['add'];
             unset($this->input['add']);
         }
         $this->input = $this->prepareInputForAdd($this->input);
     }
     if ($this->input && is_array($this->input)) {
         // Call the plugin hook - $this->input can be altered
         // This hook get the data altered by the object method
         Plugin::doHook("post_prepareadd", $this);
     }
     if ($this->input && is_array($this->input)) {
         //Check values to inject
         $this->filterValues(!isCommandLine());
     }
     if ($this->input && is_array($this->input)) {
         $this->fields = array();
         $table_fields = $DB->list_fields($this->getTable());
         // fill array for add
         foreach ($this->input as $key => $val) {
             if ($key[0] != '_' && isset($table_fields[$key])) {
                 $this->fields[$key] = $this->input[$key];
             }
         }
         // Auto set date_mod if exsist
         if (isset($table_fields['date_mod'])) {
             $this->fields['date_mod'] = $_SESSION["glpi_currenttime"];
         }
         if ($this->checkUnicity(true, $options)) {
             if ($this->addToDB()) {
                 $this->post_addItem();
                 $this->addMessageOnAddAction();
                 if ($this->dohistory && $history) {
                     $changes[0] = 0;
                     $changes[1] = $changes[2] = "";
                     Log::history($this->fields["id"], $this->getType(), $changes, 0, Log::HISTORY_CREATE_ITEM);
                 }
                 // Auto create infocoms
                 if (isset($CFG_GLPI["auto_create_infocoms"]) && $CFG_GLPI["auto_create_infocoms"] && Infocom::canApplyOn($this)) {
                     $ic = new Infocom();
                     if (!$ic->getFromDBforDevice($this->getType(), $this->fields['id'])) {
                         $ic->add(array('itemtype' => $this->getType(), 'items_id' => $this->fields['id']));
                     }
                 }
                 // If itemtype is in infocomtype and if states_id field is filled
                 // and item is not a template
                 if (InfoCom::canApplyOn($this) && isset($this->input['states_id']) && (!isset($this->input['is_template']) || !$this->input['is_template'])) {
                     //Check if we have to automatical fill dates
                     Infocom::manageDateOnStatusChange($this);
                 }
                 Plugin::doHook("item_add", $this);
                 // As add have suceed, clean the old input value
                 if (isset($this->input['_add'])) {
                     $this->clearSavedInput();
                 }
                 if ($this->mailqueueonaction) {
                     QueuedMail::forceSendFor($this->getType(), $this->fields['id']);
                 }
                 return $this->fields['id'];
             }
         }
     }
     $this->last_status = self::NOTHING_TO_DO;
     return false;
 }