/**
  * {@inheritdoc}
  */
 protected function isNullValue()
 {
     // Thank you very much, DaPulse. Changing the return type of an API endpoint clearly does not break any existing
     // code. Check to see if an invalid user is returned to be able to return null
     return parent::isNullValue() || is_array($this->jsonResponse) && array_key_exists('value', $this->jsonResponse) && is_array($this->jsonResponse['value']) && array_key_exists('id', $this->jsonResponse['value']) && $this->jsonResponse['value']['id'] === 0;
 }
示例#2
0
文件: Pulse.php 项目: allejo/PhpPulse
 /**
  * Build a pulse's column object if it doesn't exist or return the existing column.
  *
  * @param  string $columnId   The ID of the column to access. This is typically a slugified version of the column
  *                            title
  * @param  string $columnType The type of column being accessed: 'text', 'color', 'person', 'numeric', or 'date'
  *
  * @since  0.1.0
  *
  * @throws ColumnNotFoundException The specified column ID does not exist for this Pulse
  * @throws InvalidColumnException  The specified column is not the same type as specified in `$columnType`
  * @throws InvalidObjectException  The specified column exists but modification of its value is unsupported either
  *                                 by this library or the DaPulse API.
  *
  * @return PulseColumnValue The returned object will be a child of this abstract class.
  */
 private function getColumn($columnId, $columnType)
 {
     if (!isset($this->column_values) || !array_key_exists($columnId, $this->column_values)) {
         $key = ArrayUtilities::array_search_column($this->raw_column_values, 'cid', $columnId);
         $data = array();
         // We can't find the key, this means that we got our information from accessing a Pulse directly instead of
         // getting it through a PulseBoard. This isn't as robust as accessing a PulseBoard but it's more efficient.
         // We make a separate API call to get the value of a column.
         if ($key === false) {
             $url = sprintf("%s/%d/columns/%s/value.json", self::apiEndpoint("boards"), $this->getBoardId(), $columnId);
             $params = array("pulse_id" => $this->getId());
             try {
                 $results = self::sendGet($url, $params);
             } catch (HttpException $e) {
                 throw new ColumnNotFoundException("The '{$columnId}' column could not be found");
             }
             // Store our value inside of jsonResponse so all of the respective objects can treat the data the same
             // as when accessed through a PulseBoard
             $data['jsonResponse']['value'] = $results['value'];
         } else {
             $data = $this->raw_column_values[$key];
             $type = $this->column_structure[$key]->getType();
             if ($type !== $columnType) {
                 throw new InvalidColumnException("The '{$columnId}' column was expected to be '{$columnType}' but was '{$type}' instead.");
             }
         }
         $data['column_id'] = $columnId;
         $data['board_id'] = $this->getBoardId();
         $data['pulse_id'] = $this->getId();
         $this->column_values[$columnId] = PulseColumnValue::_createColumnType($columnType, $data);
     }
     return $this->column_values[$columnId];
 }
示例#3
0
 public function testGetBadColumnType()
 {
     $this->setExpectedException('allejo\\DaPulse\\Exceptions\\InvalidObjectException');
     PulseColumnValue::_createColumnType("non-existent", array());
 }