예제 #1
0
 /**
  * Get additional content data selected
  *
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get products
                 $item->get_products = static::lazy_load(function () use($item) {
                     return Model_Products::find(array('where' => array('order_id' => $item->id)));
                 }, $item->id, 'products');
                 // Get order payments
                 $item->get_payments = static::lazy_load(function () use($item) {
                     return \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc')));
                 }, $item->id, 'payments');
                 // Get last payment status
                 $item->get_last_payment = static::lazy_load(function () use($item) {
                     $payments = \Payment\Model_Payment::find(array('where' => array('order_id' => $item->id), 'order_by' => array('id' => 'desc')));
                     return isset($payments[0]) ? $payments[0] : array();
                 }, $item->id, 'last_payment', 'object');
                 // Get history
                 $item->get_history = static::lazy_load(function () use($item) {
                     return Model_History::find(array('where' => array('order_id' => $item->id), 'order_by' => array('created_at' => 'desc')));
                 }, $item->id, 'history');
                 // Get artworks
                 $item->get_artwork = static::lazy_load(function () use($item) {
                     return Model_Artwork::find(array('where' => array('order_id' => $item->id)));
                 }, $item->id, 'artwork');
                 // Get artworks status
                 $item->get_artwork_status = static::lazy_load(function () use($item) {
                     $out = array(0, 0);
                     $products = Model_Products::find(array('where' => array('order_id' => $item->id, 'artwork_required' => 1)));
                     if (!$products) {
                         return $out;
                     }
                     $out[0] = count($products);
                     foreach ($products as $product) {
                         if ($product->artwork) {
                             $out[1]++;
                         }
                     }
                     return $out;
                 }, $item->id, 'artwork_status', 'array');
                 // Get order user object
                 $item->get_user = static::lazy_load(function () use($item) {
                     return \Sentry::user((int) $item->user_id);
                 }, $item->id, 'user', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
예제 #2
0
 public function action_index()
 {
     if ($this->type >= 0) {
         switch ($this->type) {
             default:
                 echo json_encode(array('nop' => 'ok'));
                 break;
                 break;
             case 0:
                 //get all
                 $this->get_ip_history('all');
                 break;
             case 1:
             case 2:
                 //get subnodes
                 $this->get_ip_history($this->id);
                 break;
                 //subnets
             //subnets
             case 3:
                 $sub = Model_Subnet::find($this->id);
                 $this->subArray = array();
                 if ($sub) {
                     $from_pos = $sub['range_from'];
                     $to_pos = $sub['range_to'];
                     $ips = Model_History::find()->where('ip_int', '>=', $from_pos)->where('ip_int', '<=', $to_pos)->get();
                     foreach ($ips as $ip) {
                         $device = $ip->dev;
                         // print_r($device);
                         array_push($this->subArray, array('id' => $ip->id, 'ip' => $ip->ip_dotted, 'date' => date('d/m/Y H:i:s', $ip->time), 'device' => array('id' => $ip->device, 'name' => $ip->devname, 'erased' => 0)));
                     }
                 }
                 $out = array('history' => $this->subArray);
                 echo json_encode($out);
                 break;
                 //reserved ip-s
         }
     }
 }