Example #1
0
 /**
  * Short description of method removePropertyValues
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource resource
  * @param  Property property
  * @param  array options
  * @return boolean
  */
 public function removePropertyValues(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $options = array())
 {
     $returnValue = (bool) false;
     // Optional params
     $pattern = isset($options['pattern']) && !is_null($options['pattern']) ? $options['pattern'] : null;
     $like = isset($options['like']) && $options['like'] == true ? true : false;
     //build query:
     $query = 'DELETE FROM statements WHERE subject = ? AND predicate = ?';
     $objectType = $this->getPersistence()->getPlatForm()->getObjectTypeCondition();
     $conditions = array();
     if (is_string($pattern)) {
         if (!is_null($pattern)) {
             $searchPattern = Utils::buildSearchPattern($this->getPersistence(), $pattern, $like);
             $conditions[] = '( ' . $objectType . ' ' . $searchPattern . ' )';
         }
     } else {
         if (is_array($pattern)) {
             if (count($pattern) > 0) {
                 $multiCondition = "( ";
                 foreach ($pattern as $i => $patternToken) {
                     $searchPattern = Utils::buildSearchPattern($this->getPersistence(), $patternToken, $like);
                     if ($i > 0) {
                         $multiCondition .= " OR ";
                     }
                     $multiCondition .= '(' . $objectType . ' ' . $searchPattern . ' )';
                 }
                 $conditions[] = "{$multiCondition} ) ";
             }
         }
     }
     foreach ($conditions as $i => $additionalCondition) {
         $query .= " AND ( {$additionalCondition} ) ";
     }
     //be sure the property we try to remove is included in an updatable model
     $query .= ' AND ' . $this->getModelWriteSqlCondition();
     if ($property->isLgDependent()) {
         $query .= ' AND (' . $this->getPersistence()->getPlatForm()->isNullCondition('l_language') . ' OR l_language = ?) ';
         $returnValue = $this->getPersistence()->exec($query, array($resource->getUri(), $property->getUri(), \common_session_SessionManager::getSession()->getDataLanguage()));
     } else {
         $returnValue = $this->getPersistence()->exec($query, array($resource->getUri(), $property->getUri()));
     }
     if (!$returnValue) {
         $returnValue = false;
     }
     return (bool) $returnValue;
 }