/**
  * Given the object_data object (i.e. file_data) this function
  * updates all ObjectProperties (deleting or creating them when necessary)
  *
  * @param  $object_data
  */
 function save_properties($object_data)
 {
     $properties = array();
     for ($i = 0; $i < 200; $i++) {
         if (isset($object_data["property{$i}"]) && is_array($object_data["property{$i}"]) && (trim(array_var($object_data["property{$i}"], 'id')) != '' || trim(array_var($object_data["property{$i}"], 'name')) != '' || trim(array_var($object_data["property{$i}"], 'value')) != '')) {
             $name = array_var($object_data["property{$i}"], 'name');
             $id = array_var($object_data["property{$i}"], 'id');
             $value = array_var($object_data["property{$i}"], 'value');
             if ($id && trim($name) == '' && trim($value) == '') {
                 $property = ObjectProperties::findById($id);
                 $property->delete('id = $id');
             } else {
                 if ($id) {
                     SearchableObjects::dropContentByObjectColumn($this, 'property' . $id);
                     $property = ObjectProperties::findById($id);
                 } else {
                     $property = new ObjectProperty();
                     $property->setRelObjectId($this->getId());
                     $property->setRelObjectManager(get_class($this->manager()));
                 }
                 $property->setFromAttributes($object_data["property{$i}"]);
                 $property->save();
                 if ($this->isSearchable()) {
                     $this->addPropertyToSearchableObject($property);
                 }
             }
         } else {
             break;
         }
     }
     // for
 }
 function addTagsToSearchableObject()
 {
     $tag_names = $this->getTagNames();
     if (is_array($tag_names) && count($tag_names) > 0) {
         if (!$this->isNew()) {
             SearchableObjects::dropContentByObjectColumn($this, 'tags');
         }
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectManager(get_class($this->manager()));
         $searchable_object->setRelObjectId($this->getObjectId());
         $searchable_object->setColumnName('tags');
         $searchable_object->setContent(implode(' ', $tag_names));
         $searchable_object->setIsPrivate($this->isPrivate());
         $searchable_object->save();
     }
 }
 /**
  * This event is triggered when comment that belongs to this object is deleted
  *
  * @param Comment $comment
  * @return boolean
  */
 function onDeleteComment(Comment $comment)
 {
     if ($this->isSearchable()) {
         SearchableObjects::dropContentByObjectColumn($this, 'comment' . $comment->getId());
     }
 }
 function addToSearchableObjects($wasNew = false)
 {
     $columns_to_drop = array();
     if ($wasNew) {
         $columns_to_drop = $this->getSearchableColumns();
     } else {
         foreach ($this->getSearchableColumns() as $column_name) {
             if (isset($this->searchable_composite_columns[$column_name])) {
                 foreach ($this->searchable_composite_columns[$column_name] as $colName) {
                     if ($this->isColumnModified($colName)) {
                         $columns_to_drop[] = $column_name;
                         break;
                     }
                 }
             } else {
                 if ($column_name == 'body') {
                     $columns_to_drop[] = $column_name;
                 } else {
                     if ($this->getMailData()->columnExists($column_name) && $this->getMailData()->isColumnModified($column_name)) {
                         $columns_to_drop[] = $column_name;
                     } else {
                         if ($this->isColumnModified($column_name)) {
                             $columns_to_drop[] = $column_name;
                         }
                     }
                 }
             }
         }
     }
     if (count($columns_to_drop) > 0) {
         SearchableObjects::dropContentByObjectColumns($this, $columns_to_drop);
         foreach ($columns_to_drop as $column_name) {
             $content = $this->getSearchableColumnContent($column_name);
             if (trim($content) != '') {
                 $searchable_object = SearchableObjects::findById(array('rel_object_id' => $this->getObjectId(), 'column_name' => $column_name));
                 if (!$searchable_object instanceof SearchableObject) {
                     $searchable_object = new SearchableObject();
                     $searchable_object->setRelObjectId($this->getObjectId());
                     $searchable_object->setColumnName($column_name);
                 }
                 $searchable_object->setContent($content);
                 $searchable_object->setContactId($this->getAccount() instanceof MailAccount ? $this->getAccount()->getContactId() : 0);
                 $searchable_object->save();
             }
             // if
         }
         // foreach
     }
     // if
     $rows = DB::executeAll("select column_name from " . TABLE_PREFIX . "searchable_objects where rel_object_id=" . $this->getObjectId());
     if ($wasNew) {
         SearchableObjects::dropContentByObjectColumn($this, 'uid');
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getObjectId());
         $searchable_object->setColumnName('uid');
         $searchable_object->setContent($this->getUniqueObjectId());
         $searchable_object->setContactId($this->getAccount() instanceof MailAccount ? $this->getAccount()->getContactId() : 0);
         $searchable_object->save();
     }
     $rows = DB::executeAll("select column_name from " . TABLE_PREFIX . "searchable_objects where rel_object_id=" . $this->getObjectId());
 }