function it_finds_an_array_of_all_columns_based_on_a_schema_id_in_display_order()
    {
        $schema = \SchemaPeer::retrieveByPK(1);
        $schema->setLanguages(['en','fr']);
        $schema->save();

        /** @var \ImportVocab\ExportVocab $this */
        $this->setAsTemplate(true);
        $columns = $this->getSchema()->getAllProfileProperties();
        $columns->shouldHaveCount( 26 );
        $columns[1]['profile']->shouldHaveType( 'ProfileProperty' );
        $columns[9]['count']->shouldEqual( 1 );
        $columns[3]['languages']['en']->shouldEqual( 1 );
        $columns[3]['languages']['fr']->shouldEqual( 1 );
        $id = \ProfilePropertyPeer::retrieveByPK( 9 )->getId();
        $columns[12]['id']->shouldEqual( $id );
    }
Exemplo n.º 2
0
 /**
  * @param $foo
  * @return array
  */
 protected static function buildColumnArray($foo)
 {
     $bar = array();
     if (count($foo)) {
         foreach ($foo as $value) {
             foreach ($value as $key => $langArray) {
                 /** @var \ProfileProperty $profile */
                 $profile = ProfilePropertyPeer::retrieveByPK($key);
                 $order = $profile->getExportOrder();
                 $bar[$order]['profile'] = $profile;
                 $bar[$order]['id'] = $key;
                 foreach ($langArray as $lang => $count) {
                     if ($profile->getHasLanguage()) {
                         if (!isset($bar[$order]['languages'][$lang])) {
                             $bar[$order]['languages'][$lang] = 1;
                         } else {
                             if ($bar[$order]['languages'][$lang] < $count) {
                                 $bar[$order]['languages'][$lang] = $count;
                             }
                         }
                     } else {
                         if (!isset($bar[$order]['count'])) {
                             $bar[$order]['count'] = 1;
                         } else {
                             if ($bar[$order]['count'] < $count) {
                                 $bar[$order]['count'] = $count;
                             }
                         }
                     }
                 }
             }
         }
     }
     ksort($bar, SORT_NUMERIC);
     return $bar;
 }
 /**
  * updates/creates/deletes the reciprocal property
  *
  * @param  string     $action
  * @param  int        $userId
  * @param  int        $schemaId
  * @param  Connection $con
  *
  * @throws \PropelException
  */
 public function updateReciprocal($action, $userId, $schemaId, $con = null)
 {
     $inverseProfilePropertyId = $this->getProfileProperty()->getInverseProfilePropertyId();
     if (empty($inverseProfilePropertyId) and $this->getProfileProperty()->getIsReciprocal()) {
         $inverseProfilePropertyId = $this->getProfileProperty()->getId();
     }
     if (!$inverseProfilePropertyId) {
         //there's no reciprocal or inverse to process
         return;
     }
     $relatedPropertyId = $this->getRelatedSchemaPropertyId();
     if (!$relatedPropertyId) {
         $relatedProperty = SchemaPropertyPeer::retrieveByUri($this->getObject());
         if (!$relatedProperty) {
             //there's no related property in the registry
             return;
         } else {
             $relatedPropertyId = $relatedProperty->getId();
             $this->setRelatedSchemaPropertyId($relatedPropertyId);
             $this->save();
         }
     }
     $schemaPropertyID = $this->getSchemaPropertyId();
     $property = $this->getSchemaPropertyRelatedBySchemaPropertyId();
     //does the user have editorial rights to the reciprocal...
     $permission = false;
     //get the maintainers of the reciprocal property
     $maintainers = $property->getSchema()->getMaintainerIds();
     foreach ($maintainers as $maintainerId) {
         if ($userId == $maintainerId) {
             $permission = true;
             break;
         }
     }
     if (false === $permission) {
         return;
     }
     $c = new Criteria();
     $c->add(SchemaPropertyElementPeer::SCHEMA_PROPERTY_ID, $relatedPropertyId);
     $c->add(SchemaPropertyElementPeer::PROFILE_PROPERTY_ID, $inverseProfilePropertyId);
     $c->add(SchemaPropertyElementPeer::OBJECT, $property->getUri());
     $recipElement = SchemaPropertyElementPeer::doSelectOne($c, $con);
     $recipSchemaProperty = SchemaPropertyPeer::retrieveByPK($relatedPropertyId, $con);
     $recipProfileProperty = ProfilePropertyPeer::retrieveByPK($inverseProfilePropertyId, $con);
     $statusId = $this->getStatusId();
     $language = '';
     if ($recipProfileProperty) {
         $recipField = $recipProfileProperty->getName();
         if ($recipProfileProperty->getHasLanguage()) {
             $language = $this->getLanguage();
         }
     }
     //if action == deleted then
     if ('deleted' == $action && $recipElement) {
         //delete the reciprocal
         $recipElement->delete($con);
         return;
     }
     //undelete the element if it's deleted and we get this far
     if (isset($recipElement)) {
         $recipElement->setDeletedAt(null);
     }
     //if action == added, and reciprocal doesn't exist
     if ('added' == $action && !$recipElement) {
         //add the reciprocal
         $recipElement = SchemaPropertyElementPeer::createElement($recipSchemaProperty, $userId, $inverseProfilePropertyId, $statusId, $language, false, true);
     }
     //if action == updated
     if ('updated' == $action) {
         //check to see if there's a reciprocal
         if (!$recipElement) {
             //create a new one
             $recipElement = SchemaPropertyElementPeer::createElement($recipSchemaProperty, $userId, $inverseProfilePropertyId, $statusId, $language, false, true);
         }
     }
     if ($recipElement) {
         if (isset($this->importId)) {
             $recipElement->importId = $this->importId;
         }
         $recipElement->setUpdatedUserId($userId);
         $recipElement->setRelatedSchemaPropertyId($schemaPropertyID);
         $recipElement->setObject($this->getSchemaPropertyRelatedBySchemaPropertyId()->getUri());
         $recipElement->save($con);
     }
     return;
 }
 /**
  * Get the associated ProfileProperty object
  *
  * @param      Connection Optional Connection object.
  * @return     ProfileProperty The associated ProfileProperty object.
  * @throws     PropelException
  */
 public function getProfileProperty($con = null)
 {
     if ($this->aProfileProperty === null && $this->profile_property_id !== null) {
         // include the related Peer class
         include_once 'lib/model/om/BaseProfilePropertyPeer.php';
         $this->aProfileProperty = ProfilePropertyPeer::retrieveByPK($this->profile_property_id, $con);
         /* The following can be used instead of the line above to
         		   guarantee the related object contains a reference
         		   to this object, but this level of coupling
         		   may be undesirable in many circumstances.
         		   As it can lead to a db query with many results that may
         		   never be used.
         		   $obj = ProfilePropertyPeer::retrieveByPK($this->profile_property_id, $con);
         		   $obj->addProfilePropertys($this);
         		 */
     }
     return $this->aProfileProperty;
 }
Exemplo n.º 5
0
 public function executeEdit()
 {
     $this->setFlash('vocabID', $this->getVocabularyId());
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         //before the save...
         $concept_property = $this->getRequestParameter('concept_property');
         /**
          * @todo the list of skos property types that require a related concept should be in a master configuration array
          * this applies to the template too
          **/
         //check to see if the skosproperty requires a related concept
         if (!in_array($concept_property['skos_property_id'], array('3', '16', '21', '32', '33', '34', '35', '36', '37'))) {
             $concept_property['related_concept_id'] = null;
             $concept_property['scheme_id'] = null;
         }
         $conceptPropertyId = $this->getRequestParameter('id');
         $userId = $this->getUser()->getSubscriberId();
         //does the user have editorial rights to the reciprocal...
         $permission = false;
         if (isset($concept_property['related_concept_id']) and $concept_property['related_concept_id']) {
             //we want to lookup the URI of the related term
             $related_concept = ConceptPeer::retrieveByPK($concept_property['related_concept_id']);
             if ($related_concept) {
                 if ($this->getUser()->hasCredential(array(0 => 'administrator'))) {
                     $permission = true;
                 } else {
                     //get the maintainers of the reciprocal property
                     $maintainers = $related_concept->getVocabulary()->getVocabularyHasUsers();
                     /** @var VocabularyHasUser $maintainer */
                     foreach ($maintainers as $maintainer) {
                         if ($userId === $maintainer->getUserId() and $maintainer->getIsMaintainerFor()) {
                             $permission = true;
                             break;
                         }
                     }
                 }
             }
         }
         if ($permission) {
             if (isset($conceptPropertyId) && $conceptPropertyId) {
                 $this->deleteReciprocalProperty($conceptPropertyId, $concept_property['related_concept_id']);
             }
             if (isset($concept_property['related_concept_id']) and $concept_property['related_concept_id']) {
                 //we want to lookup the URI of the related term
                 $related_concept = ConceptPeer::retrieveByPK($concept_property['related_concept_id']);
                 if ($related_concept) {
                     //and overwrite whatever is in the current object TODO: move this into an javascript action in the user interface
                     $concept_property['object'] = $related_concept->getUri();
                     $this->getRequest()->getParameterHolder()->set('concept_property', $concept_property);
                 }
                 //lookup the inverse id
                 $InverseProfileId = ProfilePropertyPeer::retrieveBySkosID($concept_property['skos_property_id'])->getInverseProfilePropertyId();
                 $InverseSkosId = ProfilePropertyPeer::retrieveByPK($InverseProfileId)->getSkosId();
                 //then we create a new reciprocal property in the related term
                 $newProp = new ConceptProperty();
                 $newProp->setConceptId($concept_property['related_concept_id']);
                 $newProp->setSkosPropertyId($InverseSkosId);
                 $newProp->setSchemeId($this->concept->getVocabularyId());
                 $newProp->setRelatedConceptId($this->concept->GetId());
                 $newProp->setObject($this->concept->getUri());
                 $newProp->setStatusId($concept_property['status_id']);
                 $newProp->setIsGenerated(true);
                 $newProp->setCreatedUserId($this->getUser()->getSubscriberId());
                 $newProp->setUpdatedUserId($this->getUser()->getSubscriberId());
                 //TODO: make this the user's default language (actually the language is not relevant when defining relationships)
                 //$newProp->setLanguage($this->concept->getLanguage());
                 $newProp->setLanguage('');
                 $concept_property['language'] = '';
                 $newProp->save();
             }
         }
         //save the array back to the request parameter
         $this->requestParameterHolder->set('concept_property', $concept_property);
     }
     parent::executeEdit();
 }