예제 #1
0
 /**
  * Delete constant from constant list
  *
  * @param string $constant
  *
  * @return bool
  */
 public function deleteConstant($constant)
 {
     if (($index = array_search($constant, $this->constants->getArrayCopy())) !== false) {
         $this->constants->offsetUnset($index);
     }
     return $index !== false;
 }
 public function testExchangeArrayTestAssetIterator()
 {
     $ar = $this->getMockForAbstractClass(AbstractCollection::class);
     $ar->expects($this->atLeastOnce())->method('validateValue')->withAnyParameters()->willReturn(null);
     $ar->exchangeArray(new ArrayObjectIterator(['foo' => 'bar']));
     // make sure it does what php array object does:
     $ar2 = new \ArrayObject();
     $ar2->exchangeArray(new ArrayObjectIterator(['foo' => 'bar']));
     $this->assertEquals($ar2->getArrayCopy(), $ar->getArrayCopy());
 }
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function detailAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     $helper = new AttendanceBoardHelper();
     $form = $helper->getForm($this->staffCombo());
     $attendance = $this->attendanceTable()->getAttendance($id);
     if (!$attendance) {
         $attendance = new ArrayObject(array('attendanceId' => $id));
     } else {
         $attendance = new ArrayObject($attendance->getArrayCopy());
     }
     $attendance['hour'] = (int) date('H', time());
     $attendance['minute'] = round((int) date('i', time()) / 5);
     if ($attendance['hour'] > 12 && strlen($attendance['inTime']) > 1) {
         $attendance['type'] = 'O';
     } else {
         $attendance['type'] = 'I';
     }
     $form->bind($attendance);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $form->setData($post_data);
         $form->setInputFilter($helper->getInputFilter());
         if ($form->isValid()) {
             $newData = $this->attendanceTable()->getAttendanceByStaff($attendance['staffId'], $attendance['attendanceDate']);
             if (!$newData) {
                 $newData = new Attendance();
                 $newData->exchangeArray($attendance->getArrayCopy());
             }
             $time = sprintf('%02d:%02d:00', $attendance['hour'], $attendance['minute'] * 5);
             if ($attendance['type'] == 'I') {
                 $newData->setInTime($time);
             } else {
                 $newData->setOutTime($time);
             }
             $this->attendanceTable()->saveAttendance($newData);
             $this->flashMessenger()->addSuccessMessage('Save successful');
             return $this->redirect()->toRoute('hr_attendance');
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
예제 #4
0
 /**
  * Returns all entities.
  * 
  * @return array
  */
 public function getEntities()
 {
     return $this->entities->getArrayCopy();
 }
 /**
  * @param $associations ArrayObject
  * @param $data array
  *
  * @return mixed array
  */
 protected function stripEmptyAssociations(ArrayObject $associations, $data)
 {
     $associationsArray = $associations->getArrayCopy();
     foreach ($associationsArray as $key => $association) {
         if (!(array_key_exists($association, $data) && !empty($data[$association]) && (is_array($data[$association]) || $data[$association] instanceof \Traversable))) {
             unset($associationsArray[$key]);
         }
     }
     return new ArrayObject($associationsArray);
 }
 /**
  * @param ArrayObject $associations
  * @param array $data
  * @return ArrayObject
  */
 protected function stripEmptyAssociations(ArrayObject $associations, $data)
 {
     $associationsArray = $associations->getArrayCopy();
     foreach ($associationsArray as $key => $association) {
         if (!$this->validateAssociationData($association, $data)) {
             unset($associationsArray[$key]);
         }
     }
     return new ArrayObject($associationsArray);
 }
예제 #7
0
 public function testUksort()
 {
     $function = function ($a, $b) {
         $a = preg_replace('@^(a|an|the) @', '', $a);
         $b = preg_replace('@^(a|an|the) @', '', $b);
         return strcasecmp($a, $b);
     };
     $ar = new ArrayObject(array('John' => 1, 'the Earth' => 2, 'an apple' => 3, 'a banana' => 4));
     $sorted = $ar->getArrayCopy();
     uksort($sorted, $function);
     $ar->uksort($function);
     $this->assertSame($sorted, $ar->getArrayCopy());
 }
예제 #8
0
 /**
  * @param string $className
  * @return Datagrid
  */
 public function create($className)
 {
     /** @var \Doctrine\ORM\EntityManager $entityManager */
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $metadata = $entityManager->getClassMetadata($className);
     $reflection = $metadata->getReflectionClass();
     $datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array()));
     $reader = new AnnotationReader();
     foreach ($reader->getClassAnnotations($reflection) as $annotation) {
         $params = compact('datagridSpec', 'annotation');
         $this->getEventManager()->trigger('discoverTitle', $this, $params);
     }
     foreach ($reflection->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'property');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     foreach ($reflection->getMethods() as $method) {
         foreach ($reader->getMethodAnnotations($method) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'method');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     $this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy());
     return $this->datagrids[$className];
 }