Ejemplo n.º 1
0
 static function AddToIndex(SearchableObject $object, $commitOnEnd = true)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('combinedid', $object->getRelObjectManager() . $object->getRelObjectId()));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('objectid', $object->getRelObjectId()));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('manager', $object->getRelObjectManager()));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('column', $object->getColumnName()));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('text', $object->getContent()));
     $doc->addField(Zend_Search_Lucene_Field::Text('workspaces', "ws" . $object->getProjectId() . " "));
     $doc->addField(Zend_Search_Lucene_Field::Text('isprivate', ($object->getIsPrivate() ? '1' : '0') . " "));
     self::GetIndex()->addDocument($doc);
     if ($commitOnEnd) {
         self::GetIndex()->commit();
     }
     return true;
 }
Ejemplo n.º 2
0
    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 = 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->setProjectId(0); TODO Feng 2 setDefault Member
	            $searchable_object->save();
	          } // if
	        } // foreach
    	} // if
    	
    	if ($wasNew){
        	SearchableObjects::dropContentByObjectColumns($this,array('uid'));
        	$searchable_object = new SearchableObject();
            
            $searchable_object->setRelObjectId($this->getObjectId());
            $searchable_object->setColumnName('uid');
            $searchable_object->setContent($this->getUniqueObjectId());

            
            $searchable_object->save();
        }
    }
 function addPropertyToSearchableObject(ObjectProperty $property)
 {
     $searchable_object = new SearchableObject();
     $searchable_object->setRelObjectManager(get_class($this->manager()));
     $searchable_object->setRelObjectId($this->getObjectId());
     $searchable_object->setColumnName('property' . $property->getId());
     $searchable_object->setContent($property->getPropertyValue());
     $searchable_object->setIsPrivate(false);
     $searchable_object->save();
 }
Ejemplo n.º 4
0
 /**
  * Adds the custom properties of an object into the database.
  * 
  * @param $object
  * @return unknown_type
  */
 function add_custom_properties($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $obj_custom_properties = array_var($_POST, 'object_custom_properties');
     $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object->getObjectTypeId());
     //Sets all boolean custom properties to 0. If any boolean properties are returned, they are subsequently set to 1.
     foreach ($customProps as $cp) {
         if ($cp->getType() == 'boolean') {
             $custom_property_value = CustomPropertyValues::getCustomPropertyValue($object->getId(), $cp->getId());
             if (!$custom_property_value instanceof CustomPropertyValue) {
                 $custom_property_value = new CustomPropertyValue();
             }
             $custom_property_value->setObjectId($object->getId());
             $custom_property_value->setCustomPropertyId($cp->getId());
             $custom_property_value->setValue(0);
             $custom_property_value->save();
         }
     }
     if (is_array($obj_custom_properties)) {
         foreach ($obj_custom_properties as $id => $value) {
             //Get the custom property
             $custom_property = null;
             foreach ($customProps as $cp) {
                 if ($cp->getId() == $id) {
                     $custom_property = $cp;
                     break;
                 }
             }
             if ($custom_property instanceof CustomProperty) {
                 // save dates in standard format "Y-m-d H:i:s", because the column type is string
                 if ($custom_property->getType() == 'date') {
                     if (is_array($value)) {
                         $newValues = array();
                         foreach ($value as $val) {
                             $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $val);
                             $newValues[] = $dtv->format("Y-m-d H:i:s");
                         }
                         $value = $newValues;
                     } else {
                         $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value);
                         $value = $dtv->format("Y-m-d H:i:s");
                     }
                 }
                 //Save multiple values
                 if (is_array($value)) {
                     CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                     foreach ($value as &$val) {
                         if (is_array($val)) {
                             // CP type == table
                             $str_val = '';
                             foreach ($val as $col_val) {
                                 $col_val = str_replace("|", "\\|", $col_val);
                                 $str_val .= ($str_val == '' ? '' : '|') . $col_val;
                             }
                             $val = $str_val;
                         }
                         if ($val != '') {
                             if (strpos($val, ',')) {
                                 $val = str_replace(',', '|', $val);
                             }
                             $custom_property_value = new CustomPropertyValue();
                             $custom_property_value->setObjectId($object->getId());
                             $custom_property_value->setCustomPropertyId($id);
                             $custom_property_value->setValue($val);
                             $custom_property_value->save();
                         }
                     }
                 } else {
                     if ($custom_property->getType() == 'boolean') {
                         $value = isset($value);
                     }
                     $cpv = CustomPropertyValues::getCustomPropertyValue($object->getId(), $id);
                     if ($cpv instanceof CustomPropertyValue) {
                         $custom_property_value = $cpv;
                     } else {
                         $custom_property_value = new CustomPropertyValue();
                     }
                     $custom_property_value->setObjectId($object->getId());
                     $custom_property_value->setCustomPropertyId($id);
                     $custom_property_value->setValue($value);
                     $custom_property_value->save();
                 }
                 //Add to searchable objects
                 if ($object->isSearchable() && ($custom_property->getType() == 'text' || $custom_property->getType() == 'list' || $custom_property->getType() == 'numeric')) {
                     $name = $custom_property->getName();
                     $searchable_object = SearchableObjects::findOne(array("conditions" => "`rel_object_id` = " . $object->getId() . " AND `column_name` = '{$name}'"));
                     if (!$searchable_object) {
                         $searchable_object = new SearchableObject();
                     }
                     if (is_array($value)) {
                         $value = implode(', ', $value);
                     }
                     $searchable_object->setRelObjectId($object->getId());
                     $searchable_object->setColumnName($name);
                     $searchable_object->setContent($value);
                     $searchable_object->save();
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 function save()
 {
     parent::save();
     $sql = "DELETE FROM " . TABLE_PREFIX . "searchable_objects\n\t\t\t\t\tWHERE rel_object_id = '" . $this->getId() . "' AND (column_name LIKE 'phone_number%'  OR column_name LIKE 'email_addres%' OR column_name LIKE 'web_url%' OR column_name LIKE 'im_value%' OR column_name LIKE 'address%')";
     DB::execute($sql);
     //save telephones on searchable_objects
     $telephones = $this->getAllPhones();
     $lengthTel = count($telephones);
     for ($i = 0; $i < $lengthTel; $i++) {
         $j = strval($i);
         $telephone = array_var($telephones, $j);
         if ($telephone instanceof ContactTelephone) {
             $telephone = $telephone->getNumber();
         } else {
             continue;
         }
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getId());
         $searchable_object->setColumnName("phone_number" . $j);
         $searchable_object->setContent($telephone);
         $searchable_object->save();
     }
     //save emails on searchable_objects
     $emails = $this->getAllEmails();
     $lengthEm = count($emails);
     for ($i = 0; $i < $lengthEm; $i++) {
         $j = strval($i);
         $email = array_var($emails, $j);
         if ($email instanceof ContactEmail) {
             $email = $email->getEmailAddress();
         } else {
             continue;
         }
         if ($email != '') {
             $searchable_object = new SearchableObject();
             $searchable_object->setRelObjectId($this->getId());
             $searchable_object->setColumnName("email_addres" . $j);
             $searchable_object->setContent($email);
             $searchable_object->save();
         }
     }
     //save web_pages on searchable_objects
     $web_pages = $this->getAllWebpages();
     $lengthWeb = count($web_pages);
     for ($i = 0; $i < $lengthWeb; $i++) {
         $j = strval($i);
         $web_page = array_var($web_pages, $j);
         if ($web_page instanceof ContactWebpage) {
             $web_page = $web_page->getUrl();
         } else {
             continue;
         }
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getId());
         $searchable_object->setColumnName("web_url" . $j);
         $searchable_object->setContent($web_page);
         $searchable_object->save();
     }
     //save im_values on searchable_objects
     $im_values = $this->getImValues();
     $lengthIm = count($im_values);
     for ($i = 0; $i < $lengthIm; $i++) {
         $j = strval($i);
         $im_value = array_var($im_values, $j);
         if ($im_value instanceof ContactImValue) {
             $im_value = $im_value->getValue();
         } else {
             continue;
         }
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getId());
         $searchable_object->setColumnName("im_value" . $j);
         $searchable_object->setContent($im_value);
         $searchable_object->save();
     }
     //save addresses on searchable_objects
     $addresses = $this->getAllAddresses();
     $lengthAd = count($addresses);
     for ($i = 0; $i < $lengthAd; $i++) {
         $j = strval($i);
         $address = array_var($addresses, $j);
         if (!$address instanceof ContactAddress) {
             continue;
         }
         $address = strval(array_var($addresses, $j)->getStreet()) . " ";
         $address .= strval(array_var($addresses, $j)->getCity()) . " ";
         $address .= strval(array_var($addresses, $j)->getState()) . " ";
         $address .= strval(array_var($addresses, $j)->getCountry()) . " ";
         $address .= strval(array_var($addresses, $j)->getZipCode());
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getId());
         $searchable_object->setColumnName("address" . $j);
         $searchable_object->setContent($address);
         $searchable_object->save();
     }
     return true;
 }
 /**
  * Save object. If object is searchable this function will add conetent of searchable fields 
  * to search index
  *
  * @param void
  * @return boolean
  */
 function save()
 {
     $result = parent::save();
     // If searchable refresh content in search table
     if ($this->isSearchable()) {
         SearchableObjects::dropContentByObject($this);
         $project = $this->getProject();
         foreach ($this->getSearchableColumns() as $column_name) {
             $content = $this->getSearchableColumnContent($column_name);
             if (trim($content) != '') {
                 $searchable_object = new SearchableObject();
                 $searchable_object->setRelObjectManager(get_class($this->manager()));
                 $searchable_object->setRelObjectId($this->getObjectId());
                 $searchable_object->setColumnName($column_name);
                 $searchable_object->setContent($content);
                 if ($project instanceof Project) {
                     $searchable_object->setProjectId($project->getId());
                 }
                 $searchable_object->setIsPrivate($this->isPrivate());
                 $searchable_object->save();
             }
             // if
         }
         // if
     }
     // if
     return $result;
 }
 function addPropertyToSearchableObject(ObjectProperty $property)
 {
     $searchable_object = new SearchableObject();
     $searchable_object->setRelObjectId($this->getObjectId());
     $searchable_object->setColumnName('property' . $property->getId());
     $searchable_object->setContent($property->getPropertyValue());
     $searchable_object->save();
 }
Ejemplo n.º 8
0
 /**
  * This event is trigered when comment that belongs to this object is updated
  *
  * @param Comment $comment
  * @return boolean
  */
 function onEditComment(Comment $comment)
 {
     if ($this->isSearchable()) {
         SearchableObjects::dropContentByObjectColumn($this, 'comment' . $comment->getId());
         $searchable_object = new SearchableObject();
         $searchable_object->setRelObjectId($this->getObjectId());
         $searchable_object->setColumnName('comment' . $comment->getId());
         $searchable_object->setContent($comment->getText());
         $searchable_object->save();
     }
     return true;
 }
 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();
     }
 }
Ejemplo n.º 10
0
 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());
 }