public function addUserWriteAccess(a\User $u)
 {
     if (self::DEBUG) {
         u\DebugUtility::out("Granting write access to " . $u->getName());
     }
     $this->setAccess($u, c\T::WRITE);
     return $this;
 }
 public function appendSibling($identifier)
 {
     $this->checkStructuredData();
     if (self::DEBUG) {
         u\DebugUtility::out("Calling appendSibling");
     }
     $this->structured_data->appendSibling($identifier);
     $this->edit();
     return $this;
 }
 public function getFolder()
 {
     if ($this->isFolder() && $this->getIndexedFolderId() != NULL) {
         $service = $this->getService();
         if (self::DEBUG) {
             u\DebugUtility::out("Returning folder" . "ID " . $this->getIndexedFolderPath());
         }
         return new Folder($service, $service->createId(Folder::TYPE, $this->getIndexedFolderId()));
     }
     return NULL;
 }
 public function setDoPASV($bool)
 {
     if (!c\BooleanValues::isBoolean($bool)) {
         throw new e\UnacceptableValueException(S_SPAN . "The value {$bool} must be a boolean." . E_SPAN);
     }
     if (self::DEBUG) {
         u\DebugUtility::out($bool ? 'true' : 'false');
     }
     $this->getProperty()->doPASV = $bool;
     return $this;
 }
 public function addDynamicFieldDefinition($field_name, $type, $label, $required = false, $visibility = c\T::VISIBLE, $possible_values = "")
 {
     if ($this->hasDynamicMetadataFieldDefinition($field_name)) {
         throw new \Exception(S_SPAN . "The dynamic field definition {$field_name} already exists." . E_SPAN);
     }
     if ($type != c\T::TEXT && trim($possible_values) == "") {
         throw new e\EmptyValueException(S_SPAN . c\M::EMPTY_POSSIBLE_VALUES . E_SPAN);
     }
     $dmfd = AssetTemplate::getDynamicMetadataFieldDefinition();
     $dmfd->dynamicMetadataFieldDefinition->name = $field_name;
     $dmfd->dynamicMetadataFieldDefinition->label = $label;
     $dmfd->dynamicMetadataFieldDefinition->fieldType = $type;
     $dmfd->dynamicMetadataFieldDefinition->required = $required;
     $dmfd->dynamicMetadataFieldDefinition->visibility = $visibility;
     if ($type != c\T::TEXT) {
         $dmfd->dynamicMetadataFieldDefinition->possibleValues = new \stdClass();
         $values = u\StringUtility::getExplodedStringArray(";", $possible_values);
         $value_count = count($values);
         if ($value_count == 1) {
             $pv = new \stdClass();
             $pv->value = $values[0];
             $pv->selectedByDefault = false;
             $dmfd->dynamicMetadataFieldDefinition->possibleValues->possibleValue = $pv;
         } else {
             $dmfd->dynamicMetadataFieldDefinition->possibleValues->possibleValue = array();
             foreach ($values as $value) {
                 if (self::DEBUG) {
                     u\DebugUtility::out($value);
                 }
                 $pv = new \stdClass();
                 $pv->value = $value;
                 $pv->selectedByDefault = false;
                 $dmfd->dynamicMetadataFieldDefinition->possibleValues->possibleValue[] = $pv;
             }
         }
     }
     if (self::DEBUG && self::DUMP) {
         u\DebugUtility::dump($dmfd);
     }
     $dmfd_obj = new p\DynamicMetadataFieldDefinition($dmfd->dynamicMetadataFieldDefinition);
     $this->dynamic_metadata_field_definitions[] = $dmfd_obj;
     if (self::DEBUG && self::DUMP) {
         u\DebugUtility::dump($dmfd_obj->toStdClass());
     }
     $this->edit();
     $this->processDynamicMetadataFieldDefinition();
     return $this;
 }
 private function getType($id_string)
 {
     if (self::DEBUG) {
         u\DebugUtility::out("string: " . $id_string);
     }
     if (isset($this->service)) {
         $types = array('block', 'format');
         $type_count = count($types);
         for ($i = 0; $i < $type_count; $i++) {
             $id = $this->service->createId($types[$i], $id_string);
             $operation = new \stdClass();
             $read_op = new \stdClass();
             $read_op->identifier = $id;
             $operation->read = $read_op;
             $operations[] = $operation;
         }
         $this->service->batch($operations);
         $reply_array = $this->service->getReply()->batchReturn;
         if (self::DEBUG && self::DUMP) {
             u\DebugUtility::dump($reply_array);
         }
         for ($j = 0; $j < $type_count; $j++) {
             if ($reply_array[$j]->readResult->success == 'true') {
                 foreach (c\T::$type_property_name_map as $type => $property) {
                     //echo "$type => $property" . BR;
                     if (isset($reply_array[$j]->readResult->asset->{$property})) {
                         return $type;
                     }
                 }
             }
         }
     }
     return NULL;
 }
 private function getStructuredDataNode($xml_element, $type, $identifier)
 {
     if (self::DEBUG) {
         u\DebugUtility::out("{$type}, {$identifier}");
     }
     $obj = AssetTemplate::getStructuredDataNode();
     if ($type == c\T::GROUP) {
         $obj->type = $type;
         $obj->identifier = $identifier;
         $obj->structuredDataNodes = new \stdClass();
         $child_count = count($xml_element->children());
         $more_than_one = $child_count > 1 ? true : false;
         if ($more_than_one) {
             $obj->structuredDataNodes->structuredDataNode = array();
             foreach ($xml_element->children() as $child) {
                 $child_type = $child->getName();
                 if (self::DEBUG) {
                     u\DebugUtility::out("Child type in group: {$child_type}");
                 }
                 if (isset($child[c\T::IDENTIFIER])) {
                     $child_identifier = $child[c\T::IDENTIFIER]->__toString();
                     $child_std = $this->createChildStd($child, $child_type, $child_identifier);
                     $obj->structuredDataNodes->structuredDataNode[] = $child_std;
                 }
             }
         } else {
             $xml_array = $xml_element->children();
             //var_dump( $xml_array );
             $child = $xml_array[0];
             $child_type = $child->getName();
             if (self::DEBUG) {
                 u\DebugUtility::out("Child type in group: {$child_type}");
             }
             $child_identifier = $child[c\T::IDENTIFIER]->__toString();
             $child_std = $this->createChildStd($child, $child_type, $child_identifier);
             $obj->structuredDataNodes->structuredDataNode = $child_std;
         }
     } else {
         $obj->type = $type;
         $obj->identifier = $identifier;
     }
     return $obj;
 }
 public static function assetTreeUpdatePageConfigurationSet(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
 {
     if (isset($params['source-cascade'])) {
         $source_cascade = $params['source-cascade'];
     } else {
         echo c\M::TARGET_CASCADE_NOT_SET . BR;
         return;
     }
     if (isset($params['target-cascade'])) {
         $target_cascade = $params['target-cascade'];
     } else {
         echo c\M::TARGET_CASCADE_NOT_SET . BR;
         return;
     }
     if (isset($params['target-site'])) {
         $target_site = $params['target-site'];
     } else {
         echo c\M::TARGET_SITE_NOT_SET . BR;
         return;
     }
     if (isset($params['exception-thrown'])) {
         $exception_thrown = $params['exception-thrown'];
     } else {
         echo c\M::EXCEPTION_THROWN_NOT_SET . BR;
         return;
     }
     $source_pcs = $child->getAsset($service);
     $source_pcs_name = $source_pcs->getName();
     $source_pcs_parent_path = $source_pcs->getParentContainerPath();
     // the default definition
     $source_pcs_default_config = $source_pcs->getDefaultConfiguration();
     $source_pcs_default_config_name = $source_pcs_default_config->getName();
     $source_pcs_default_config_template_path = u\StringUtility::removeSiteNameFromPath($source_pcs_default_config->getTemplatePath());
     $source_pcs_default_config_template_name = u\StringUtility::getNameFromPath($source_pcs_default_config_template_path);
     $source_pcs_default_config_template = $source_pcs_default_config->getTemplate();
     $source_pcs_default_config_template_site = $source_pcs_default_config_template->getSiteName();
     $source_pcs_default_config_extension = $source_pcs_default_config->getOutputExtension();
     $source_pcs_default_config_type = $source_pcs_default_config->getSerializationType();
     if (self::DEBUG) {
         u\DebugUtility::out("Extension: " . $source_pcs_default_config_extension . BR . "Type: " . $source_pcs_default_config_type);
     }
     $target_pcs_default_config_template_site = $source_pcs_default_config_template_site;
     try {
         // the template must be there
         $template = $target_cascade->getAsset(Template::TYPE, $source_pcs_default_config_template_path, $target_pcs_default_config_template_site);
         $target_site_name = $target_site->getName();
         // parent must be there
         $target_parent = $target_cascade->getAsset(PageConfigurationSetContainer::TYPE, $source_pcs_parent_path, $target_site_name);
         $target_pcs = $target_cascade->createPageConfigurationSet($target_parent, $source_pcs_name, $source_pcs_default_config_name, $template, $source_pcs_default_config_extension, $source_pcs_default_config_type);
         // update other configuration sets
         $source_config_names = $source_pcs->getPageConfigurationNames();
         foreach ($source_config_names as $source_config_name) {
             // retrieve config info
             $source_config = $source_pcs->getPageConfiguration($source_config_name);
             $source_template = $source_config->getTemplate();
             $source_template_path = u\StringUtility::removeSiteNameFromPath($source_template->getPath());
             $source_template_site = $source_template->getSiteName();
             $target_template_site = $source_template_site;
             // template must be there
             $target_template = $target_cascade->getAsset(Template::TYPE, $source_template_path, $target_template_site);
             // add missing configurations
             if ($source_pcs_default_config_name != $source_config_name && !$target_pcs->hasPageConfiguration($source_config_name)) {
                 $source_config_extension = $source_config->getOutputExtension();
                 $source_config_type = $source_config->getSerializationType();
                 $source_config_publishable = $source_config->getPublishable();
                 try {
                     $target_config = $target_pcs->getPageConfiguration($source_config_name);
                 } catch (e\NoSuchPageConfigurationException $e) {
                     $target_pcs->addPageConfiguration($source_config_name, $target_template, $source_config_extension, $source_config_type);
                     $target_config = $target_pcs->getPageConfiguration($source_config_name);
                 }
                 // update config
                 $target_pcs->setOutputExtension($source_config_name, $source_config_extension);
                 $target_pcs->setSerializationType($source_config_name, $source_config_type);
                 $target_pcs->setPublishable($source_config_name, $source_config_publishable);
             }
             // config format!!!
             $source_config_format_id = $source_config->getFormatId();
             if (isset($source_config_format_id)) {
                 $source_config_format = $source_cascade->getXsltFormat($source_config_format_id);
                 $source_config_format_path = u\StringUtility::removeSiteNameFromPath($source_config_format->getPath());
                 $source_config_format_site = $source_config_format->getSiteName();
                 $target_config_format_site = $source_config_format_site;
                 try {
                     if ($exception_thrown) {
                         $target_format = $target_cascade->getAsset(XsltFormat::TYPE, $source_config_format_path, $target_config_format_site);
                     } else {
                         $target_format = $target_cascade->getXsltFormat($source_config_format_path, $target_config_format_site);
                     }
                     $source_config->setFormat($target_format);
                     $target_pcs->edit();
                 } catch (\Exception $e) {
                     $msg = "The format {$source_config_format_path} does not exist in {$target_config_format_site}. ";
                     throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e);
                 }
             }
             // set blocks and formats, if not $exception_thrown, skip missing ones
             $region_names = $target_template->getRegionNames();
             if (count($region_names) > 0) {
                 foreach ($region_names as $region_name) {
                     if (!$source_pcs->hasPageRegion($source_config_name, $region_name)) {
                         continue;
                     }
                     $source_block = $source_pcs->getPageRegion($source_config_name, $region_name)->getBlock();
                     $source_format = $source_pcs->getPageRegion($source_config_name, $region_name)->getFormat();
                     if ($source_block) {
                         $source_block_path = u\StringUtility::removeSiteNameFromPath($source_block->getPath());
                         $source_block_site = $source_block->getSiteName();
                         $source_block_type = $source_block->getType();
                         $target_block_site = $source_block_site;
                         try {
                             if ($exception_thrown) {
                                 $target_block = $target_cascade->getAsset($source_block_type, $source_block_path, $target_block_site);
                             } else {
                                 $class_name = c\T::getClassNameByType($source_block_type);
                                 $method = 'get' . $class_name;
                                 $target_block = $target_cascade->{$method}($source_block_path, $target_block_site);
                             }
                             $target_pcs->setConfigurationPageRegionBlock($source_config_name, $region_name, $target_block)->edit();
                         } catch (\Exception $e) {
                             $msg = "The block {$source_block_path} does not exist in {$target_block_site}. ";
                             throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e);
                         }
                     }
                     if ($source_format) {
                         $source_format_path = u\StringUtility::removeSiteNameFromPath($source_format->getPath());
                         $source_format_site = $source_format->getSiteName();
                         $source_format_type = $source_format->getType();
                         $target_format_site = $source_format_site;
                         try {
                             if ($exception_thrown) {
                                 $target_format = $target_cascade->getAsset($source_format_type, $source_format_path, $target_format_site);
                             } else {
                                 $class_name = c\T::getClassNameByType($source_format_type);
                                 $method = 'get' . $class_name;
                                 $target_format = $target_cascade->{$method}($source_format_path, $target_format_site);
                             }
                             $target_pcs->setConfigurationPageRegionFormat($source_config_name, $region_name, $target_format);
                         } catch (\Exception $e) {
                             $msg = "The format {$source_format_path} does not exist in {$target_format_site}. ";
                             throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e);
                         }
                     }
                 }
             }
             $target_pcs->edit();
         }
     } catch (\Exception $e) {
         //$msg = "The configuration set $source_pcs_default_config_template_path does not exist in $target_pcs_default_config_template_site. ";
         throw new e\CascadeInstancesErrorException($e);
     }
 }
<?php

require_once 'auth_tutorial7.php';
use cascade_ws_AOHS as aohs;
use cascade_ws_constants as c;
use cascade_ws_asset as a;
use cascade_ws_property as p;
use cascade_ws_utility as u;
use cascade_ws_exception as e;
try {
    echo u\ReflectionUtility::getClassName($service), BR;
    u\DebugUtility::out(u\ReflectionUtility::getClassName($service));
    //u\DebugUtility::dump( $service );
} catch (\Exception $e) {
    echo S_PRE . $e . E_PRE;
} catch (\Error $er) {
    echo S_PRE . $er . E_PRE;
}
/*
Useful code templates:
    u\ReflectionUtility::showMethodSignatures( 
        "cascade_ws_utility\ReflectionUtility" );
        
    u\ReflectionUtility::showMethodSignature( 
        "cascade_ws_asset\Page", "edit" );
        
    u\ReflectionUtility::showMethodDescription( 
        "cascade_ws_utility\ReflectionUtility", "getMethodInfoByName", true );
        
    u\ReflectionUtility::showMethodExample( 
        "cascade_ws_utility\ReflectionUtility", "getMethodInfoByName", true );
 /**
  * Create an asset object, bridging this class and the Asset classes
  * @param string 
  * @param string $type The type of the asset
  * @param string $id_path Either the ID string or the path of the asset
  * @param binary $site_name The site name
  *
  * @return mixed The asset object
  * @throw Exception if the asset cannot be retrieved
  */
 public function getAsset($type, $id_path, $site_name = NULL)
 {
     if (!in_array($type, c\T::getTypeArray())) {
         throw new e\NoSuchTypeException(S_SPAN . "The type {$type} does not exist." . E_SPAN);
     }
     $class_name = c\T::$type_class_name_map[$type];
     // get class name
     $class_name = a\Asset::NAME_SPACE . "\\" . $class_name;
     try {
         return new $class_name($this, $this->createId($type, $id_path, $site_name));
     } catch (\Exception $e) {
         if (self::DEBUG && self::DUMP) {
             u\DebugUtility::out($e->getMessage());
         }
         throw $e;
     }
 }
 public static function initialize(aohs\AssetOperationHandlerService $service)
 {
     try {
         $service->listMessages();
         if ($service->isSuccessful()) {
             $messages = $service->getListedMessages();
             $temp_msg = array();
             if (!($messages->message == NULL)) {
                 if (!is_array($messages->message)) {
                     $temp_msg[] = $messages->message;
                 } else {
                     $temp_msg = $messages->message;
                 }
                 foreach ($temp_msg as $message) {
                     $id = $message->id;
                     $to = $message->to;
                     $from = $message->from;
                     $date = $message->date;
                     $subject = trim($message->subject);
                     $body = $message->body;
                     self::$all_message_ids[] = $id;
                     $message_obj = new Message($message);
                     // store all messages
                     self::$all_messages[] = $message_obj;
                     self::$id_obj_map[$id] = $message_obj;
                     // from whom?
                     if (!isset($message_ids_from[$from])) {
                         self::$message_ids_from[$from] = array();
                     }
                     self::$message_ids_from[$from][] = $id;
                     if ($from != 'system') {
                         self::$non_system_messages[] = $message_obj;
                     }
                     if (self::DEBUG) {
                         u\DebugUtility::out($message_obj->getType());
                     }
                     if ($message_obj->getType() == Message::TYPE_EXPIRATION) {
                         self::$asset_expiration_message[] = $message_obj;
                         self::$asset_expiration_message_ids[] = $id;
                     } else {
                         if ($message_obj->getType() == Message::TYPE_PUBLISH) {
                             self::$publish_messages[] = $message_obj;
                             self::$publish_message_ids[] = $id;
                             // no issues
                             if (strpos($subject, "(0 issue(s))") !== false) {
                                 if (self::DEBUG) {
                                     echo "L::121 " . $id . BR;
                                 }
                                 self::$publish_message_ids_without_issues[] = $id;
                                 self::$publish_messages_without_issues[] = $message_obj;
                             } else {
                                 if (self::DEBUG) {
                                     echo "L::124 " . $id . BR;
                                 }
                                 self::$publish_message_ids_with_issues[] = $id;
                                 self::$publish_messages_with_issues[] = $message_obj;
                             }
                         } else {
                             if ($message_obj->getType() == Message::TYPE_UNPUBLISH) {
                                 self::$unpublish_messages[] = $message_obj;
                                 self::$unpublish_message_ids[] = $id;
                                 // no issues
                                 if (strpos($subject, "(0 issue(s))") !== false) {
                                     self::$unpublish_message_ids_without_issues[] = $id;
                                     self::$unpublish_messages_without_issues[] = $message_obj;
                                 } else {
                                     self::$unpublish_message_ids_with_issues[] = $id;
                                     self::$unpublish_messages_with_issues[] = $message_obj;
                                 }
                             } else {
                                 if ($message_obj->getType() == Message::TYPE_SUMMARY) {
                                     self::$summary_messages[] = $message_obj;
                                     self::$summary_message_ids[] = $id;
                                     // 0 failures
                                     if (strpos($subject, "(0 failures)") !== false) {
                                         self::$summary_message_ids_no_failures[] = $id;
                                         self::$summary_messages_no_failures[] = $message_obj;
                                     } else {
                                         self::$summary_message_ids_with_failures[] = $id;
                                         self::$summary_messages_with_failures[] = $message_obj;
                                     }
                                 } else {
                                     if ($message_obj->getType() == Message::TYPE_WORKFLOW) {
                                         self::$workflow_messages[] = $message_obj;
                                         self::$workflow_message_ids[] = $id;
                                         // is complete
                                         if (strpos($subject, "is complete") !== false) {
                                             self::$workflow_message_ids_is_complete[] = $id;
                                             self::$workflow_messages_complete[] = $message_obj;
                                         } else {
                                             self::$workflow_message_ids_other[] = $id;
                                             self::$workflow_messages_other[] = $message_obj;
                                         }
                                     } else {
                                         self::$other_messages[] = $message_obj;
                                         self::$other_message_ids[] = $id;
                                     }
                                 }
                             }
                         }
                     }
                     // date
                 }
                 usort(self::$all_messages, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$publish_messages, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$unpublish_messages, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$workflow_messages, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$other_messages, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$publish_messages_with_issues, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$unpublish_messages_with_issues, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$workflow_messages_other, self::NAME_SPACE . "\\" . 'Message::compare');
                 usort(self::$non_system_messages, self::NAME_SPACE . "\\" . 'Message::compare');
             }
             //var_dump( $workflow_message_ids_is_complete );
         } else {
             echo "Failed to list messages. " . $service->getMessage();
         }
     } catch (\Exception $e) {
         echo S_PRE . $e . E_PRE;
     }
 }
 public static function processStructuredDataNodePhantom($parent_id, &$node_array, $node_std, $data_definition)
 {
     if (self::DEBUG) {
         u\DebugUtility::out("Parent ID: " . $parent_id);
     }
     if (!is_array($node_std)) {
         $node_std = array($node_std);
     }
     $node_count = count($node_std);
     if (self::DEBUG) {
         u\DebugUtility::out("Node count: " . $node_count);
     }
     // these are used to calculate the index
     $previous_identifier;
     $current_identifier;
     $cur_index = 0;
     // work out the id of the current node for the data definition
     // no digits in the fully qualified identifiers
     for ($i = 0; $i < $node_count; $i++) {
         $fq_identifier = $node_std[$i]->identifier;
         if ($parent_id != '') {
             $parent_id_array = explode(self::DELIMITER, $parent_id);
             $temp = '';
             foreach ($parent_id_array as $part) {
                 if (!is_numeric($part)) {
                     $temp .= $part . self::DELIMITER;
                 }
             }
             $temp = trim($temp, self::DELIMITER);
             $fq_identifier = $temp . self::DELIMITER . $node_std[$i]->identifier;
         }
         try {
             $is_multiple = $data_definition->isMultiple($fq_identifier);
         } catch (e\NoSuchFieldException $e) {
             self::$phantoms[] = $fq_identifier;
             continue;
         }
         if (isset($current_identifier)) {
             $previous_identifier = $current_identifier;
         }
         $current_identifier = $node_std[$i]->identifier;
         // a multiple text or group, work out fully qualified identifier
         if ($is_multiple) {
             // an old one, keep counting
             if (isset($previous_identifier) && $previous_identifier == $current_identifier) {
                 $cur_index++;
             } else {
                 $cur_index = 0;
             }
         }
         if ($parent_id != '') {
             $n = new StructuredDataNodePhantom($node_std[$i], NULL, $data_definition, $cur_index, $parent_id);
         } else {
             $n = new StructuredDataNodePhantom($node_std[$i], NULL, $data_definition, $cur_index);
         }
         $n->parent_id = $parent_id;
         $node_array[$i] = $n;
     }
 }
 public function setDynamicFieldValue($field, $values)
 {
     if (!is_array($values)) {
         $values = array($values);
     }
     $v_count = count($values);
     if ($this->metadata_set == NULL) {
         $this->metadata_set = a\Asset::getAsset($this->service, a\MetadataSet::TYPE, $this->metadata_set_id);
     }
     $df_def = $this->metadata_set->getDynamicMetadataFieldDefinition($field);
     $field_type = $df_def->getFieldType();
     $required = $df_def->getRequired();
     $df = $this->getDynamicField($field);
     // text can accept anything
     if ($field_type == c\T::TEXT && $v_count == 1) {
         $value = $values[0];
         if ($value == NULL) {
             // turn NULL to empty string
             $value = '';
         }
         if ($required && $value == '') {
             throw new e\RequiredFieldException(S_SPAN . "The {$field_type} requires non-empty value" . E_SPAN);
         }
         $v = new \stdClass();
         $v->value = $value;
         $df->setValue(array($v));
     } else {
         if (($field_type == c\T::RADIO || $field_type == c\T::DROPDOWN) && $v_count == 1) {
             $value = $values[0];
             // read first value
             if ($value == '') {
                 // turn empty string to NULL
                 $value = NULL;
             }
             if ($required && $value == NULL) {
                 // cannot be empty if required
                 throw new e\RequiredFieldException(S_SPAN . "The {$field_type} requires non-empty value." . E_SPAN);
             }
             $possible_values = $df_def->getPossibleValueStrings();
             // read from metadataSet
             if (!in_array($value, $possible_values) && isset($value)) {
                 // undefined value
                 throw new e\NoSuchValueException(S_SPAN . "The value {$value} does not exist." . E_SPAN);
             }
             $v = new \stdClass();
             if ($value != '') {
                 $v->value = $value;
             }
             $df->setValue(array($v));
         } else {
             if (($field_type == c\T::CHECKBOX || $field_type == c\T::MULTISELECT) && $v_count > 0) {
                 if (self::DEBUG) {
                     u\DebugUtility::out('Setting values for checkbox or multiselect');
                 }
                 if ($required && (in_array(NULL, $values) || in_array('', $values))) {
                     throw new e\RequiredFieldException(S_SPAN . "The {$field_type} requires non-empty value." . E_SPAN);
                 }
                 $possible_values = $df_def->getPossibleValueStrings();
                 foreach ($values as $value) {
                     if (self::DEBUG) {
                         u\DebugUtility::out("Value: {$value}");
                     }
                     if (!in_array($value, $possible_values) && isset($value)) {
                         throw new e\NoSuchValueException(S_SPAN . "The value {$value} does not exist." . E_SPAN);
                     }
                 }
                 $v_array = array();
                 foreach ($values as $value) {
                     $v = new \stdClass();
                     $v->value = $value;
                     $v_array[] = $v;
                 }
                 $df->setValue($v_array);
                 if (self::DEBUG && self::DUMP) {
                     u\DebugUtility::dump($df->toStdClass());
                 }
             }
         }
     }
     //if( self::DEBUG && self::DUMP ){ u\DebugUtility::dump( $this ); }
     return $this;
 }
 public function hasPageRegion($region_name)
 {
     if (self::DEBUG) {
         u\DebugUtility::out("Region name fed in: " . $region_name);
     }
     return isset($this->page_region_map[$region_name]);
 }
<?php

require_once 'auth_tutorial7.php';
use cascade_ws_AOHS as aohs;
use cascade_ws_constants as c;
use cascade_ws_asset as a;
use cascade_ws_property as p;
use cascade_ws_utility as u;
use cascade_ws_exception as e;
try {
    u\DebugUtility::dump($service);
    u\DebugUtility::out("Hello");
    echo u\ReflectionUtility::getClassDocumentation("cascade_ws_utility\\DebugUtility", true);
} catch (\Exception $e) {
    echo S_PRE . $e . E_PRE;
} catch (\Error $er) {
    echo S_PRE . $er . E_PRE;
}
 public function removeValue($value)
 {
     // type of text
     if ($this->possible_values == NULL) {
         echo c\M::TEXT_NO_POSSIBLE_VALUE . BR;
         return $this;
     }
     if ($value == '') {
         throw new e\EmptyValueException(S_SPAN . "The value cannot be empty." . E_SPAN);
     }
     if (!in_array($value, $this->values)) {
         throw new e\NoSuchValueException(S_SPAN . "The value {$value} does not exist." . E_SPAN);
     }
     $count = count($this->possible_values);
     for ($i = 0; $i < $count; $i++) {
         if ($this->possible_values[$i]->getValue() == $value) {
             if (self::DEBUG) {
                 u\DebugUtility::out("Removing {$value}");
             }
             $before = array_slice($this->possible_values, 0, $i);
             $values_before = array_slice($this->values, 0, $i);
             if (self::DEBUG && self::DUMP) {
                 u\DebugUtility::dump($values_before);
             }
             $after = array();
             $values_after = array();
             if ($count - $i > 1) {
                 $after = array_slice($this->possible_values, $i + 1);
                 $values_after = array_slice($this->values, $i + 1);
             }
             $this->possible_values = array_merge($before, $after);
             $this->values = array_merge($values_before, $values_after);
             break;
         }
     }
     return $this;
 }
use cascade_ws_exception as e;
try {
    $ms = $cascade->getAsset(a\MetadataSet::TYPE, "06d5db638b7ffe83765c5582062dd782");
    $dmfd = $ms->getDynamicMetadataFieldDefinition("languages");
    u\DebugUtility::dump($dmfd->getPossibleValues());
    $dmfd->appendValue("Chinese");
    $ms->edit();
    $dmfd->swapValues("Chinese", "Japanese");
    $ms->edit();
    if ($dmfd->hasDefaultValue()) {
        u\DebugUtility::dump($dmfd->getDefaultValue()->toStdClass());
        u\DebugUtility::out($dmfd->getDefaultValueString());
    }
    u\DebugUtility::out($dmfd->getFieldType());
    u\DebugUtility::out($dmfd->getLabel());
    u\DebugUtility::out($dmfd->getName());
    u\DebugUtility::dump($dmfd->getPossibleValues());
    u\DebugUtility::dump($dmfd->getPossibleValueStrings());
    u\DebugUtility::dump(u\StringUtility::boolToString($dmfd->getRequired()));
    u\DebugUtility::dump($dmfd->getVisibility());
    u\DebugUtility::dump(u\StringUtility::boolToString($dmfd->hasPossibleValue("Spanish")));
    $dmfd->removeValue("Chinese");
    $ms->edit()->dump();
    $dmfd->setLabel("Languages");
    $ms->edit()->dump();
    $dmfd->setRequired(true);
    $ms->edit()->dump();
    $dmfd->unsetSelectedByDefault("Japanese");
    $ms->edit()->dump();
    // radio
    $dmfd = $ms->getDynamicMetadataFieldDefinition("gender");
 private function appendNodeToField($field_name)
 {
     if (self::DEBUG) {
         u\DebugUtility::out($field_name);
     }
     if (!$this->data_definition->hasIdentifier($field_name)) {
         throw new e\NoSuchFieldException(S_SPAN . "The field name {$field_name} does not exist." . E_SPAN);
     }
     if (!$this->data_definition->isMultiple($field_name)) {
         throw new e\NodeException(S_SPAN . "The field {$field_name} is not multiple." . E_SPAN);
     }
     // get the parent id through the first node
     // alternative: use the field name to work out the parent id
     $first_node = $this->getNode($field_name . a\DataDefinition::DELIMITER . '0');
     $par_id = $first_node->getParentId();
     if ($par_id == '') {
         $child_count = count($this->children);
         //$first_pos   = StructuredDataNodePhantom::getPositionOfFirstNode( $this->children, $field_name );
         $last_pos = StructuredDataNodePhantom::getPositionOfLastNode($this->children, $field_name);
         $cloned_node = $this->children[$last_pos]->cloneNode();
         if ($child_count > $last_pos + 1) {
             $before = array_slice($this->children, 0, $last_pos + 1);
             $after = array_slice($this->children, $last_pos + 1);
             $this->children = array_merge($before, array($cloned_node), $after);
         } else {
             $this->children[] = $cloned_node;
         }
         // add new node to map
         $this->node_map = array_merge($this->node_map, array($cloned_node->getIdentifier() => $cloned_node));
     } else {
         $this->getNode($par_id)->addChildNode($field_name);
     }
     // add new identifier to identifiers
     $temp = $this->node_map;
     asort($temp);
     $this->identifiers = array_keys($temp);
     return $this;
 }
 private function deleteMessagesWithIds($ids)
 {
     if (self::DEBUG) {
         u\DebugUtility::out("Inside deleteMessagesWithIds");
     }
     if (!is_array($ids)) {
         throw new \Exception(S_SPAN . c\M::NOT_ARRAY . E_SPAN);
     }
     if (count($ids) > 0) {
         foreach ($ids as $id) {
             $this->service->deleteMessage($this->service->createIdWithIdType($id, c\T::MESSAGE));
         }
     }
     return $this;
 }
示例#20
0
 public static function assetTreeReportPublishable(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
 {
     if (!isset($params['cache'])) {
         throw new e\ReportException(S_SPAN . c\M::NULL_CACHE . E_SPAN);
     }
     // set up cache
     $cache = $params['cache'];
     // publishable or unpublishable
     $publishable = true;
     // the default
     if (is_array($params) && isset($params['publishable'])) {
         $publishable = $params['publishable'];
     }
     // skip irrelevant children
     $type = $child->getType();
     if ($type != Folder::TYPE && $type != Page::TYPE && $type != File::TYPE) {
         return;
     }
     $path = $child->getPathPath();
     if (self::DEBUG) {
         u\DebugUtility::out("Path: " . $path);
     }
     $asset = $cache->retrieveAsset($child);
     if ($publishable) {
         if ($asset->isPublishable()) {
             //if( self::DEBUG ) { u\DebugUtility::out( "Publishable path: " . $asset->getPath() ); }
             $results[$type][] = $path;
         }
     } else {
         if (!$asset->isPublishable()) {
             //if( self::DEBUG ) { u\DebugUtility::out( "Publishable path: " . $asset->getPath() ); }
             $results[$type][] = $path;
         }
     }
 }
 public function isPublishable()
 {
     $path = $this->getPath();
     if (self::DEBUG) {
         u\DebugUtility::out($path);
     }
     if ($this->getPath() == '/') {
         return $this->getShouldBePublished();
     } else {
         $parent = $this->getAsset($this->getService(), Folder::TYPE, $this->getParentContainerId());
         return $parent->isPublishable() && $this->getShouldBePublished();
     }
 }
示例#22
0
 public function setRegionBlock($config_name, $region_name, Block $block = NULL)
 {
     if (!isset($this->page_configuration_map[$config_name])) {
         throw new e\NoSuchPageConfigurationException(S_SPAN . "Path: " . $this->getPath() . E_SPAN . BR . "The page configuration {$config_name} does not exist.");
     }
     if (self::DEBUG) {
         u\DebugUtility::out("Setting block to region" . BR . "Region name: " . $region_name);
         if (isset($block)) {
             u\DebugUtility::out("Block ID: " . $block->getId());
         } else {
             u\DebugUtility::out("No block passed in.");
         }
     }
     $this->page_configuration_map[$config_name]->setRegionBlock($region_name, $block);
     return $this;
 }
<?php

require_once 'auth_tutorial7.php';
use cascade_ws_constants as c;
use cascade_ws_asset as a;
use cascade_ws_property as p;
use cascade_ws_utility as u;
use cascade_ws_exception as e;
try {
    $cascade->getAsset(a\Page::TYPE, "389b03188b7ffe83164c931405d3704f")->dump();
    u\DebugUtility::out(u\StringUtility::boolToString($cascade->getAsset(a\DataBlock::TYPE, "ffa200f88b7ffe8330d802d73f3adfc3")->getMetadata()->isDynamicMetadataFieldRequired("checkbox")));
    $block_id = "388f033b8b7ffe83164c9314c23a3f8f";
    $block = $cascade->getAsset(a\FeedBlock::TYPE, $block_id);
    $m = $block->getMetadata();
    u\DebugUtility::out(u\StringUtility::boolToString($m->isAuthorFieldRequired()));
    u\DebugUtility::out(u\StringUtility::boolToString($m->isDescriptionFieldRequired()));
    // wired fields
    echo "Author: ", $m->getAuthor(), BR, "Display name: ", $m->getDisplayName(), BR, "End date: ", u\StringUtility::getCoalescedString($m->getEndDate()), BR . HR;
    // dynamic fields
    $ms = $block->getMetadataSet();
    // text
    $field_name = "text";
    echo "Testing {$field_name}", BR;
    if ($m->hasDynamicField($field_name)) {
        $text = $m->getDynamicField($field_name);
        u\DebugUtility::dump($text->getFieldValue()->getValues());
        // passing in a single string as value
        $m->setDynamicFieldValue($field_name, "New string used in text");
    }
    // radio
    /*
use cascade_ws_property as p;
use cascade_ws_utility as u;
use cascade_ws_exception as e;
try {
    $f = $cascade->getAsset(a\Folder::TYPE, "39d53c648b7ffe834c5fe91ec0cb0f27");
    $wd_id = "9fe9a65e8b7ffe83164c9314b8a987d9";
    $wd = $cascade->getAsset(a\WorkflowDefinition::TYPE, $wd_id);
    $ws = $f->getWorkflowSettings();
    $ws->setInheritWorkflows(true)->setRequireWorkflow(false);
    /*   
        // toggle
        if( $ws->hasWorkflowDefinition( $wd_id ) )
            $ws->removeWorkflowDefinition( $wd );
        else
            $ws->addWorkflowDefinition( $wd );
    */
    $f->editWorkflowSettings(true, true);
    u\DebugUtility::dump($ws->toStdClass());
    u\DebugUtility::dump($ws->getWorkflowDefinitions());
    u\DebugUtility::dump($ws->getInheritedWorkflowDefinitions());
    u\DebugUtility::out(u\StringUtility::boolToString($ws->getInheritWorkflows()));
    u\DebugUtility::out(u\StringUtility::boolToString($ws->getRequireWorkflow()));
    $ws = $f->getWorkflowSettings();
    $ws->unsetInheritWorkflows();
    u\DebugUtility::dump($ws->toStdClass());
    $f->editWorkflowSettings(true, true);
} catch (\Exception $e) {
    echo S_PRE . $e . E_PRE;
} catch (\Error $er) {
    echo S_PRE . $er . E_PRE;
}