Beispiel #1
0
 /**
  * path should be build once
  * the object has been
  * initialized with data
  * to build a path we use
  * each dependancy, if has id in data
  * add after path and also set in 
  * object. 
  *
  * result:
  * depend1/depend1id/path
  *
  * @param object: Catapult Model Object
  * @param data: EnsureResource input or Array
  */
 public static function Make(&$object, &$data = null)
 {
     $path = "";
     foreach ($object->depends->terms as $dep) {
         if ($dep->plural) {
             $path .= TitleUtility::toPlural($dep->term) . "/";
         } else {
             $path .= $dep->term . "/";
         }
         /** represent a term in singular form **/
         $term = TitleUtility::toSingular($dep->term) . "Id";
         if (is_array($data) && array_key_exists($term, $data)) {
             $depid = $data[$term];
             $path .= $depid . "/";
             $object->{$dep->term} = $depid;
             unset($data[$term]);
             /** only set when we're given data **/
             $object->hasPath = true;
         }
     }
     $object->path = $path . $object->path;
 }
Beispiel #2
0
 /**
  * get the class for a given path 
  * fallback: singular titlecased
  */
 public function getObjClass($path)
 {
     $cnt = 0;
     foreach (self::$paths as $k => $p) {
         if ($p == $path) {
             return $k;
         }
     }
     return TitleUtility::toTitlecase(TitleUtility::toSingular($path));
 }
Beispiel #3
0
 /**
  * Prototypal update.
  * must have sub id to reference
  * allows mocking
  * of functions like: 
  *
  * Conference->updateMember(array(memberId=1))
  *
  * termId should always be
  * term + Id
  * make sure it is singular.
  *
  */
 public static function update()
 {
     $args = func_get_args();
     $that = self::get_this($args);
     $term = self::get_term($args);
     $data = Ensure::Input($args);
     $termId = TitleUtility::ToSingular($term) . "Id";
     $ret = $this->client->post($url, array($term, $data->get($termId)));
     return $this->{$term}($ret['id']);
 }